From 5de6f943a753381e4223347c68780b45f9a97e08 Mon Sep 17 00:00:00 2001 From: Allen Shaw Date: Tue, 5 Nov 2024 20:49:42 -0600 Subject: [PATCH] WIP: POC fix for dev/core#5571. --- HTML/QuickForm/Renderer/ArraySmarty.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/HTML/QuickForm/Renderer/ArraySmarty.php b/HTML/QuickForm/Renderer/ArraySmarty.php index a14d14b48..a150a3580 100644 --- a/HTML/QuickForm/Renderer/ArraySmarty.php +++ b/HTML/QuickForm/Renderer/ArraySmarty.php @@ -197,7 +197,7 @@ function _elementToArray(&$element, $required, $error) $this->_renderRequired($ret['label'], $ret['html'], $required, $error); } if ($error && !empty($this->_error)) { - $this->_renderError($ret['label'], $ret['html'], $error); + $this->_renderError($ret['label'], $ret['html'], $error, $element->_type); $ret['error'] = $error; } // create keys for elements grouped by native group or name @@ -310,11 +310,12 @@ function _renderRequired(&$label, &$html, &$required, &$error) * @param string The element label * @param string The element html rendering * @param string The element error + * @param string Type of the relevant quickform element * @see setErrorTemplate() * @access private * @return void */ - function _renderError(&$label, &$html, &$error) + function _renderError(&$label, &$html, &$error, $elementType) { $this->_tpl->assign(array('label' => '', 'html' => '', 'error' => $error)); $error = $this->_tplFetch($this->_error); @@ -323,7 +324,14 @@ function _renderError(&$label, &$html, &$error) if (!empty($label) && strpos($this->_error, $this->_tpl->left_delimiter . '$label') !== false) { $label = $this->_tplFetch($this->_error); } elseif (!empty($html) && strpos($this->_error, $this->_tpl->left_delimiter . '$html') !== false) { - $html = $this->_tplFetch($this->_error); + // Fix dev/core#5571: For 'group'-type elements (checkboxes/radios), merely display $error; + // for other types, re-render the error template completely. + if ($elementType == 'group') { + $html = $error; + } + else { + $html = $this->_tplFetch($this->_error); + } } $this->_tpl->clear_assign(array('label', 'html', 'error')); } // end func _renderError