Overview
When you are managing and displaying the NextGenEditor widgets, you can use events in your own plugins to modify the output rendering, to allow saving and removing, or to do extra operations.
You can use these events in any plugin, although the content plugin is more suitable for rendering events and system plugin more suitable for saving events.
onRenderPart(&$part, &$params)
Description
This event is called when a widget is rendered. You can change the widget contents and settings before rendering.
Parameters
&$part A reference to a Part object containing all content and settings of the widget
&$params An array of content params of the widget. May vary depending of the context
Return Value
None. Result will be omitted.
Usage
Create or use an existing content plugin. Add this fonction inside the plugin class.
public function onRenderPart(&$part, &$params) { $contentObject = json_decode($part->content); $contentObject->header->label .= ' ' . date("h:i:sa"); $part->content = json_encode($contentObject); }
All contents of the widget are accessible in the $part->content property.This property is a json string.
All options settings of the widget are accessible in the $part->params property.This property is a json string.
Tip : to find the name of the property, go in the configuration screen of the widget. With the browser inspector, watch the html source of the field the name of the input. For example the widget title has the name header[label]. The saved property is header->label
onDisplayPart(&$content, $part, $params)
Description
This event is called when a widget is rendered. You can change the rendered content before displaying. You can add html content before and after the widget. You can modify the widget html before displaying.
Parameters
&$content A reference to the html content that will be displayed $part A reference to a Part object containing all content and settings of the widget $params An array of content params of the widget. May vary depending of the context
Return Value
None. Result will be omitted.
Usage
Create or use an existing content plugin. Add this fonction inside the plugin class
public function onDisplayPart(&$content, $part, $params) { $content = 'My content before' . $content . 'My content after'; }
onPartBeforeSave(&$data)
Description
This event is called when a widget is saved in database after being created or updated. You can change the data that will be saved. You can enable or disable the widget saving.
Parameters
&$data : A reference to the incoming data to be saved.
Return Value
True to allow saving the Widget, False to disallow saving the widget.
Usage
Create or use an existing system plugin. Add this fonction inside the plugin class
public function onPartBeforeSave(&data) { //Example, do never modify the widget id 100 if ($data['pk'] == 100) return false; else return true; }
onPartAfterSave($pk, $data)
Description
This is an event that is called after a widget has been saved in the database. You can do here some extra operations.
Parameters
$pk The id of the saved widget
$data An array of the incoming data that have been used to save the widget.
Return Value
None. Result will be omitted.
Usage
Create or use an existing system plugin. Add this fonction inside the plugin class
public function onPartAfterSave($pk, $data) { //Example, write all saved data in a log file file_put_contents ( 'mylogfile.txt', $data); }
onPartBeforeDelete($pk)
Description
This is an event that is called when a widget will be removed in the database. You can allow or not this operation.
Parameters
$pk The id of the widget to be deleted
Return Value
True to allow deleting, False to disallow deleting.
Usage
Create or use an existing system plugin. Add this fonction inside the plugin class
public function onPartBeforeDelete(&pk) { //Example, do never delete the widget id 100 if ($pk == 100) return false; else return true; }