General developer forum

Inplace Editing

Picture of Pedro Remedios
Inplace Editing


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) {
if ($itemtype === 'name') {
global $DB;
$telemedia_record = $DB->get_record('telemedia', array("id"=>$itemid), '*', MUST_EXIST);
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.


Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Inplace Editing
Core developersDocumentation writersParticularly helpful MoodlersPlugin 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.

Average of ratings: -
Picture of Marina Glancy
Re: Inplace Editing

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: -
Picture of Marina Glancy
Re: Inplace Editing

... 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.

Average of ratings: -