From 313da3ebf3f33e6cc3485ddd16a01ba8ba49d121 Mon Sep 17 00:00:00 2001 From: Amaia Anabitarte Date: Tue, 18 Jul 2023 17:05:21 +0200 Subject: [PATCH] MDL-78527 pear: Adding attributes parameter to groups --- lib/pear/HTML/QuickForm.php | 7 ++++--- lib/pear/HTML/QuickForm/element.php | 6 ++++-- lib/pear/HTML/QuickForm/group.php | 10 +++++++--- lib/pear/readme_moodle.txt | 1 + 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/pear/HTML/QuickForm.php b/lib/pear/HTML/QuickForm.php index 6cec481f024..0f566f2db55 100644 --- a/lib/pear/HTML/QuickForm.php +++ b/lib/pear/HTML/QuickForm.php @@ -576,7 +576,7 @@ class HTML_QuickForm extends HTML_Common { $includeFile = $GLOBALS['HTML_QUICKFORM_ELEMENT_TYPES'][$type][0]; include_once($includeFile); $elementObject = new $className(); //Moodle: PHP 5.3 compatibility - for ($i = 0; $i < 5; $i++) { + for ($i = 0; $i < 6; $i++) { if (!isset($args[$i])) { $args[$i] = null; } @@ -724,12 +724,13 @@ class HTML_QuickForm extends HTML_Common { * @param string $separator (optional)string to separate elements * @param bool $appendName (optional)specify whether the group name should be * used in the form element name ex: group[element] + * @param mixed $attributes Either a typical HTML attribute string or an associative array * @return object reference to added group of elements * @since 2.8 * @access public * @throws PEAR_Error */ - function &addGroup($elements, $name=null, $groupLabel='', $separator=null, $appendName = true) + function &addGroup($elements, $name = null, $groupLabel = '', $separator = null, $appendName = true, $attributes = null) { static $anonGroups = 1; @@ -737,7 +738,7 @@ class HTML_QuickForm extends HTML_Common { $name = 'qf_group_' . $anonGroups++; $appendName = false; } - $group =& $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName); + $group =& $this->addElement('group', $name, $groupLabel, $elements, $separator, $appendName, $attributes); return $group; } // end func addGroup diff --git a/lib/pear/HTML/QuickForm/element.php b/lib/pear/HTML/QuickForm/element.php index 37e2e1bbff7..45057e83d93 100644 --- a/lib/pear/HTML/QuickForm/element.php +++ b/lib/pear/HTML/QuickForm/element.php @@ -383,10 +383,12 @@ class HTML_QuickForm_element extends HTML_Common { switch ($event) { case 'createElement': - static::__construct($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]); + static::__construct($arg[0], $arg[1], $arg[2], $arg[3], $arg[4], $arg[5]); if ($caller->getAttribute('data-random-ids') && !$this->getAttribute('id')) { $this->_generateId(); - $this->updateAttributes(array('id' => $this->getAttribute('id') . '_' . random_string())); + $attributes = $this->getAttributes(); + $attributes['id'] = $this->getAttribute('id') . '_' . random_string(); + $this->updateAttributes($attributes); } break; case 'addElement': diff --git a/lib/pear/HTML/QuickForm/group.php b/lib/pear/HTML/QuickForm/group.php index b400964082e..1c4a9725d66 100644 --- a/lib/pear/HTML/QuickForm/group.php +++ b/lib/pear/HTML/QuickForm/group.php @@ -88,12 +88,13 @@ class HTML_QuickForm_group extends HTML_QuickForm_element * @param bool $appendName (optional)whether to change elements' names to * the form $groupName[$elementName] or leave * them as is. + * @param mixed $attributes Either a typical HTML attribute string or an associative array * @since 1.0 * @access public * @return void */ - public function __construct($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true) { - parent::__construct($elementName, $elementLabel); + public function __construct($elementName = null, $elementLabel = null, $elements = null, $separator = null, $appendName = true, $attributes = null) { + parent::__construct($elementName, $elementLabel, $attributes); $this->_type = 'group'; if (isset($elements) && is_array($elements)) { $this->setElements($elements); @@ -104,6 +105,9 @@ class HTML_QuickForm_group extends HTML_QuickForm_element if (isset($appendName)) { $this->_appendName = $appendName; } + if (isset($attributes)) { + $this->_attributes = $attributes; + } } //end constructor /** @@ -111,7 +115,7 @@ class HTML_QuickForm_group extends HTML_QuickForm_element * * @deprecated since Moodle 3.1 */ - public function HTML_QuickForm_group($elementName=null, $elementLabel=null, $elements=null, $separator=null, $appendName = true) { + public function HTML_QuickForm_group($elementName = null, $elementLabel = null, $elements = null, $separator = null, $appendName = true, $attributes = null) { debugging('Use of class name as constructor is deprecated', DEBUG_DEVELOPER); self::__construct($elementName, $elementLabel, $elements, $separator, $appendName); } diff --git a/lib/pear/readme_moodle.txt b/lib/pear/readme_moodle.txt index b585c1357e5..827f650e652 100644 --- a/lib/pear/readme_moodle.txt +++ b/lib/pear/readme_moodle.txt @@ -38,6 +38,7 @@ MDL-77164 - PHPdocs corrections MDL-78145 - PHP 8.2 compliance. Added a missing class property that still need to be declared to avoid dynamic properties deprecated error warning. And also remove the $_elementIdx because it is not needed in Moodle code. +MDL-78527 - Adding a sixth parameter to allow groups to use attributes. Pear ====