mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-72289 output: allow customised inplace editable icon for editing.
Add optional argument to allow it to be defined by caller, and set the default icon for `select` type as appropriate.
This commit is contained in:
parent
206023c15f
commit
dcc130c7cf
@ -28,6 +28,7 @@ namespace core\output;
|
||||
use templatable;
|
||||
use renderable;
|
||||
use lang_string;
|
||||
use pix_icon;
|
||||
|
||||
/**
|
||||
* Class allowing to quick edit a title inline
|
||||
@ -89,6 +90,11 @@ class inplace_editable implements templatable, renderable {
|
||||
*/
|
||||
protected $edithint = null;
|
||||
|
||||
/**
|
||||
* @var pix_icon icon to use to toggle editing
|
||||
*/
|
||||
protected $editicon = null;
|
||||
|
||||
/**
|
||||
* @var bool indicates if the current user is allowed to edit this element - set in constructor after permissions are checked
|
||||
*/
|
||||
@ -117,9 +123,10 @@ class inplace_editable implements templatable, renderable {
|
||||
* @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
|
||||
*/
|
||||
public function __construct($component, $itemtype, $itemid, $editable,
|
||||
$displayvalue, $value = null, $edithint = null, $editlabel = null) {
|
||||
$displayvalue, $value = null, $edithint = null, $editlabel = null, ?pix_icon $editicon = null) {
|
||||
$this->component = $component;
|
||||
$this->itemtype = $itemtype;
|
||||
$this->itemid = $itemid;
|
||||
@ -128,6 +135,7 @@ class inplace_editable implements templatable, renderable {
|
||||
$this->value = $value;
|
||||
$this->edithint = $edithint;
|
||||
$this->editlabel = $editlabel;
|
||||
$this->editicon = $editicon;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,6 +198,9 @@ class inplace_editable implements templatable, renderable {
|
||||
if ($this->displayvalue === null) {
|
||||
$this->displayvalue = $options[$this->value];
|
||||
}
|
||||
if ($this->editicon === null) {
|
||||
$this->editicon = new pix_icon('t/expanded', (string) $this->edithint);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -242,6 +253,10 @@ class inplace_editable implements templatable, renderable {
|
||||
);
|
||||
}
|
||||
|
||||
if ($this->editicon === null) {
|
||||
$this->editicon = new pix_icon('t/editstring', (string) $this->edithint);
|
||||
}
|
||||
|
||||
return array(
|
||||
'component' => $this->component,
|
||||
'itemtype' => $this->itemtype,
|
||||
@ -250,6 +265,7 @@ class inplace_editable implements templatable, renderable {
|
||||
'value' => (string)$this->value,
|
||||
'edithint' => (string)$this->edithint,
|
||||
'editlabel' => (string)$this->editlabel,
|
||||
'editicon' => $this->editicon->export_for_pix(),
|
||||
'type' => $this->type,
|
||||
'options' => $this->options,
|
||||
'linkeverything' => $this->get_linkeverything() ? 1 : 0,
|
||||
|
5
lib/external/externallib.php
vendored
5
lib/external/externallib.php
vendored
@ -498,6 +498,11 @@ class core_external extends external_api {
|
||||
'itemid' => new external_value(PARAM_RAW, 'identifier of the updated item', VALUE_OPTIONAL),
|
||||
'edithint' => new external_value(PARAM_NOTAGS, 'hint for editing element', VALUE_OPTIONAL),
|
||||
'editlabel' => new external_value(PARAM_RAW, 'label for editing element', VALUE_OPTIONAL),
|
||||
'editicon' => new external_single_structure([
|
||||
'key' => new external_value(PARAM_RAW, 'Edit icon key', VALUE_OPTIONAL),
|
||||
'component' => new external_value(PARAM_COMPONENT, 'Edit icon component', VALUE_OPTIONAL),
|
||||
'title' => new external_value(PARAM_NOTAGS, 'Edit icon title', VALUE_OPTIONAL),
|
||||
]),
|
||||
'type' => new external_value(PARAM_ALPHA, 'type of the element (text, toggle, select)', VALUE_OPTIONAL),
|
||||
'options' => new external_value(PARAM_RAW, 'options of the element, format depends on type', VALUE_OPTIONAL),
|
||||
'linkeverything' => new external_value(PARAM_INT, 'Should everything be wrapped in the edit link or link displayed separately', VALUE_OPTIONAL),
|
||||
|
@ -736,7 +736,7 @@ class pix_icon implements renderable, templatable {
|
||||
return [
|
||||
'key' => $this->pix,
|
||||
'component' => $this->component,
|
||||
'title' => $title
|
||||
'title' => (string) $title,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,9 @@
|
||||
{{^ linkeverything }}{{{displayvalue}}}{{/ linkeverything }}
|
||||
<a href="#" class="quickeditlink aalink" data-inplaceeditablelink="1" title="{{edithint}}">
|
||||
{{# linkeverything }}{{{displayvalue}}}{{/ linkeverything }}
|
||||
<span class="quickediticon visibleifjs">{{#pix}}t/editstring,core,{{{edithint}}}{{/pix}}</span>
|
||||
<span class="quickediticon visibleifjs">
|
||||
{{#editicon}}{{#pix}}{{key}}, {{component}}, {{title}}{{/pix}}{{/editicon}}
|
||||
</span>
|
||||
</a>
|
||||
</span>
|
||||
{{#js}}
|
||||
|
@ -63,6 +63,8 @@ information provided here is intended especially for developers.
|
||||
* New method \core_user::awaiting_action() has been introduced to check if the user is fully ready to use the site or
|
||||
whether there is an action (such as filling the missing profile field, changing password or agreeing to the site
|
||||
policy) needed.
|
||||
* The inplace_editable element constructor now accepts an optional pix_icon parameter to use as it's editing icon when
|
||||
rendered. The default icon for "select" types has also changed to a dropdown caret ("t/expanded").
|
||||
|
||||
=== 3.11.2 ===
|
||||
* For security reasons, filelib has been updated so all requests now use emulated redirects.
|
||||
|
Loading…
x
Reference in New Issue
Block a user