Inplace Editing

Inplace Editing

by Pedro Remedios -
Number of replies: 3

Hi,

I'm having trouble following the explanation about implementing inplace editing in my plugin.

- What does it mean by itemtype?

- When I try to test the code I have it gives me an "undefined" popup with no message. Debugging information activated also doesn't show anything.

- I tried naming the function mod_telemedia_inplace_editable and telemedia_inplace_editable and no of them seem to be getting called.

This is the code I have:

function telemedia_inplace_editable($itemtype, $itemid, $newvalue) {
var_dump($itemtype);
if ($itemtype === 'name') {
global $DB;
$telemedia_record = $DB->get_record('telemedia', array("id"=>$itemid), '*', MUST_EXIST);
\external_api::validate_context(context_system::instance());
require_capability('mod/telemedia::update', context_system::instance());
$newvalue = clean_param($newvalue, PARAM_NOTAGS);
$telemedia_record->name = $newvalue;
$DB->update_record('telemedia', $telemedia_record);
return new \core\output\inplace_editable('telemedia', 'name', $telemedia_record->id, true,
$telemedia_record->name, $telemedia_record->name, 'New name', 'New value for ' . $telemedia_record->name);
}
return true;
}

Any hints/help are appreciated.

Pedro

Average of ratings: -
In reply to Pedro Remedios

Re: Inplace Editing

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

The point about itemtype is that your plugin might have different things that can be edited in-place. For example, your things might have a name and a description. So, when a particular value is edited, you need to know which property has been changed. That is what itemtype does.

So, you can use whatever itemtypes you like, just pick a sensible string.

In reply to Pedro Remedios

Re: Inplace Editing

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

In addition to what Tim said,

this code gives you undefined popup because you have var_dump() in the begninning. Caller expects JSON-encoded output and fails to parse the response.

This callback is executed as part of AJAX request. If you want to add debugging to AJAX requests, just throw exceptions. For example

throw new Exception('Itemtype = '.print_r($itemtype,true));
Average of ratings: Useful (1)
In reply to Marina Glancy

Re: Inplace Editing

by Marina Glancy -
Picture of Core developers Picture of Moodle HQ Picture of Moodle Workplace team Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

... It also helps if I look at the date of the post and don't reply two weeks later. Hope you have sorted it all out already.