Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403]

Contains class \core\output\inplace_editable

Copyright: 2016 Marina Glancy
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 284 lines (10 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

inplace_editable:: (7 methods):
  __construct()
  set_type_toggle()
  set_type_select()
  set_type_autocomplete()
  get_linkeverything()
  export_for_template()
  render()


Class: inplace_editable  - X-Ref

Class allowing to quick edit a title inline

This class is used for displaying an element that can be in-place edited by the user. To display call:
echo $OUTPUT->render($element);
or
echo $OUTPUT->render_from_template('core/inplace_editable', $element->export_for_template($OUTPUT));

Template core/inplace_editable will automatically load javascript module with the same name
core/inplace_editable. Javascript module registers a click-listener on edit link and
then replaces the displayed value with an input field. On "Enter" it sends a request
to web service core_update_inplace_editable, which invokes the callback from the component.
Any exception thrown by the web service (or callback) is displayed as an error popup.

Callback {$component}_inplace_editable($itemtype, $itemid, $newvalue) must be present in the lib.php file of
the component or plugin. It must return instance of this class.

__construct($component, $itemtype, $itemid, $editable,$displayvalue, $value = null, $edithint = null, $editlabel = null, ?pix_icon $editicon = null)   X-Ref
Constructor.

param: string $component name of the component or plugin responsible for the updating of the value (must declare callback)
param: string $itemtype type of the item inside the component - each component/plugin may implement multiple inplace-editable elements
param: int $itemid identifier of the item that can be edited in-place
param: bool $editable whether this value is editable (check capabilities and editing mode), if false, only "displayvalue"
param: string $displayvalue what needs to be displayed to the user, it must be cleaned, with applied filters (call
param: string $value what needs to be edited - usually raw value from the database, it may contain multilang tags
param: lang_string|string $edithint hint (title) that will be displayed under the edit link
param: lang_string|string $editlabel label for the input element in the editing mode (for screenreaders)
param: pix_icon|null $editicon icon to use to toggle editing

set_type_toggle($options = null)   X-Ref
Sets the element type to be a toggle

For toggle element $editlabel is not used.
$displayvalue must be specified, it can have text or icons but can not contain html links.

Toggle element can have two or more options.

param: array $options toggle options as simple, non-associative array; defaults to array(0,1)
return: self

set_type_select($options)   X-Ref
Sets the element type to be a dropdown

For select element specifying $displayvalue is optional, if null it will
be assumed that $displayvalue = $options[$value].
However displayvalue can still be specified if it needs icons and/or
html links.

If only one option specified, the element will not be editable.

param: array $options associative array with dropdown options
return: self

set_type_autocomplete($options, $attributes)   X-Ref
Sets the element type to be an autocomplete field

param: array $options associative array with dropdown options
param: array $attributes associative array with attributes for autoselect field. See AMD module core/form-autocomplete.
return: self

get_linkeverything()   X-Ref
Whether the link should contain all of the content or not.


export_for_template(\renderer_base $output)   X-Ref
Export this data so it can be used as the context for a mustache template (core/inplace_editable).

param: \renderer_base $output typically, the renderer that's calling this function
return: array data context for a mustache template

render(\renderer_base $output)   X-Ref
Renders this element

param: \renderer_base $output typically, the renderer that's calling this function
return: string