Skip to content

Commit

Permalink
MDL-75910 core_form: Allow editor field to set a hidden label
Browse files Browse the repository at this point in the history
When an editor is used in a form as part of a group, it is missing its
label element.

This happens because there is no inline template for the editor, and
therefore it reverts to using the old `toHtml` function. The legacy
function does not cater to the editor being in a group, and therefore
does not add the hidden label.

In addition, the hiddenLabel attribute was missing from the editor
element. This is a semi-standard element but must be added to each
supporting element.

Both the missing inline template for the editor, and the hidden label
attribute must be present:
- If the hidden label attribute is not present, then the standard inline
  template will add a visible label within the group.
- If the inline editor template is missing, then the label is not shown
  at all.
  • Loading branch information
lameze authored and andrewnicols committed Oct 6, 2022
1 parent 24f97ed commit f1be9b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/form/editor.php
Expand Up @@ -64,6 +64,9 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element implements templatab
/** @var array values for editor */
protected $_values = array('text'=>null, 'format'=>null, 'itemid'=>null);

/** @var bool if true label will be hidden */
protected $_hiddenLabel = false;

/**
* Constructor
*
Expand Down Expand Up @@ -496,4 +499,14 @@ function getFrozenHtml() {

return '';
}

/**
* Sets label to be hidden.
*
* @param bool $hiddenLabel Whether the label should be hidden or not.
* @return void
*/
function setHiddenLabel($hiddenLabel) {
$this->_hiddenLabel = $hiddenLabel;
}
}
5 changes: 5 additions & 0 deletions lib/form/templates/element-editor-inline.mustache
@@ -0,0 +1,5 @@
{{< core_form/element-template-inline }}
{{$element}}
{{{element.html}}}
{{/element}}
{{/ core_form/element-template-inline }}

0 comments on commit f1be9b6

Please sign in to comment.