diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 40bd26de4f05..973d1b97318a 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -775,6 +775,9 @@ public static function addQuickFormElement( if ($search || empty($useRequired)) { $fieldAttributes['allowClear'] = TRUE; } + if ($field->options_per_line) { + $fieldAttributes['options_per_line'] = $field->options_per_line; + } $qf->addRadio($elementName, $label, $options, $fieldAttributes, NULL, $useRequired); } break; diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index ee41275ecc3b..32d8475d84d3 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1498,7 +1498,9 @@ public function &addRadio($name, $title, $values, $attributes = [], $separator = $options[] = $element; } $group = $this->addGroup($options, $name, $title, $separator); - + if (!empty($attributes['options_per_line'])) { + $group->setAttribute('options_per_line', $attributes['options_per_line']); + } $optionEditKey = 'data-option-edit-path'; if (!empty($attributes[$optionEditKey])) { $group->setAttribute($optionEditKey, $attributes[$optionEditKey]); diff --git a/CRM/Core/Form/Renderer.php b/CRM/Core/Form/Renderer.php index 01dc6bb0b866..2857ccf7a45e 100644 --- a/CRM/Core/Form/Renderer.php +++ b/CRM/Core/Form/Renderer.php @@ -84,6 +84,13 @@ public static function &singleton() { public function _elementToArray(&$element, $required, $error) { self::updateAttributes($element, $required, $error); + if ($element->getType() === 'group' && $element->getAttribute('options_per_line')) { + // Our standard template renders the erroneous html as part of it. + // This results in double renders in some cases - see https://lab.civicrm.org/dev/core/-/issues/5571 + // I suspect not rendering the html is probably often better but + // this adds it for our known problem case. + $this->setErrorTemplate('CRM/Form/errorClean.tpl'); + } $el = parent::_elementToArray($element, $required, $error); $el['textLabel'] = $element->_label ?? NULL; @@ -126,7 +133,13 @@ public function _elementToArray(&$element, $required, $error) { else { $typesToShowEditLink = ['select', 'group']; $hasEditPath = NULL !== $element->getAttribute('data-option-edit-path'); - + if ($element->getType() === 'group' && $element->getAttribute('options_per_line')) { + // Our standard template renders the erroneous html as part of it. + // This results in double renders in some cases - see https://lab.civicrm.org/dev/core/-/issues/5571 + // I suspect not rendering the html is probably often better but + // this adds it for our known problem case. + $this->setErrorTemplate('CRM/Form/errorClean.tpl'); + } if (in_array($element->getType(), $typesToShowEditLink) && $hasEditPath) { $this->addOptionsEditLink($el, $element); } @@ -135,7 +148,9 @@ public function _elementToArray(&$element, $required, $error) { $this->appendUnselectButton($el, $element); } } - + // We can't do a get to check but the only time we ever use a different template is within this + // function. + $this->setErrorTemplate('CRM/Form/error.tpl'); return $el; } diff --git a/templates/CRM/Form/errorLabel.tpl b/templates/CRM/Form/errorLabel.tpl new file mode 100644 index 000000000000..6295b3addb3f --- /dev/null +++ b/templates/CRM/Form/errorLabel.tpl @@ -0,0 +1,14 @@ +{* + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC. All rights reserved. | + | | + | This work is published under the GNU AGPLv3 license with some | + | permitted exceptions and without any warranty. For full license | + | and copyright information, see https://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} + +{if $error} + {$error} +{/if} +