MDL-78527 forms: New parentclass attribute to wrapper element only

This commit is contained in:
Amaia Anabitarte 2023-07-14 16:17:07 +02:00
parent b4c6ed3650
commit 0122c2c3e7
5 changed files with 22 additions and 5 deletions

View file

@ -59,9 +59,18 @@ class MoodleQuickForm_group extends HTML_QuickForm_group implements templatable
* @param array $elements (optional) array of HTML_QuickForm_element elements to group
* @param string $separator (optional) string to seperate elements.
* @param string $appendName (optional) string to appened to grouped elements.
* @param mixed $attributes (optional) Either a typical HTML attribute string
* or an associative array
*/
public function __construct($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true) {
parent::__construct($elementName, $elementLabel, $elements, $separator, $appendName);
public function __construct(
$elementName = null,
$elementLabel = null,
$elements = null,
$separator = null,
$appendName = true,
$attributes = null
) {
parent::__construct($elementName, $elementLabel, $elements, $separator, $appendName, $attributes);
}
/**

View file

@ -66,6 +66,7 @@ trait templatable_form_element {
$context[strtolower($propname)] = isset($this->$classpropname) ? $this->$classpropname : false;
}
$extraclasses = $this->getAttribute('class');
$parentonlyclasses = $this->getAttribute('parentclass');
// Special wierd named property.
$context['frozen'] = !empty($this->_flagFrozen);
@ -74,11 +75,12 @@ trait templatable_form_element {
// Other attributes.
$otherattributes = [];
foreach ($this->getAttributes() as $attr => $value) {
if (!in_array($attr, $standardattributes) && $attr != 'class' && !is_object($value)) {
if (!in_array($attr, $standardattributes) && $attr != 'class' && $attr != 'parentclass' && !is_object($value)) {
$otherattributes[] = $attr . '="' . s($value) . '"';
}
}
$context['extraclasses'] = $extraclasses;
$context['parentclasses'] = $parentonlyclasses;
$context['type'] = $this->getType();
$context['attributes'] = implode(' ', $otherattributes);
$context['emptylabel'] = ($this->getLabel() === '');

View file

@ -42,7 +42,7 @@
}
}
}}
<div id="{{element.wrapperid}}" class="form-group row {{#error}}has-danger{{/error}} fitem {{#element.emptylabel}}femptylabel{{/element.emptylabel}} {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}}" {{#element.groupname}}data-groupname="{{.}}"{{/element.groupname}}>
<div id="{{element.wrapperid}}" class="form-group row {{#error}}has-danger{{/error}} fitem {{#element.emptylabel}}femptylabel{{/element.emptylabel}} {{#advanced}}advanced{{/advanced}} {{{element.extraclasses}}} {{{element.parentclasses}}}" {{#element.groupname}}data-groupname="{{.}}"{{/element.groupname}}>
<div class="col-md-3 col-form-label d-flex pb-0 pr-md-0">
{{# label}}{{$ label }}
{{^element.staticlabel}}

View file

@ -1,6 +1,10 @@
This files describes API changes in core_form libraries and APIs,
information provided here is intended especially for developers.
=== 4.3 ===
* Added a new parameter to allow Groups to add attributes.
=== 4.2 ===
* The moodle-form-passwordunmask module has been removed. It was deprecated in Moodle 3.2.

View file

@ -3370,7 +3370,9 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
$groupid = 'fgroup_' . $group->getAttribute('id');
// Update the ID.
$group->updateAttributes(array('id' => $groupid));
$attributes = $group->getAttributes();
$attributes['id'] = $groupid;
$group->updateAttributes($attributes);
$advanced = isset($this->_advancedElements[$group->getName()]);
$html = $OUTPUT->mform_element($group, $required, $advanced, $error, false);