Don't duplicate code to add a radio element to quickform
authorMatthew Wire <mjw@mjwconsult.co.uk>
Thu, 6 Feb 2020 22:40:32 +0000 (22:40 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Thu, 7 May 2020 09:21:04 +0000 (10:21 +0100)
CRM/Core/BAO/CustomField.php

index 128c2a8841502016b78e3c3081b29664f95d6a25..e2573e0abed0a018da832e2d66639effe823a76c 100644 (file)
@@ -780,25 +780,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField {
           $qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
         }
         else {
-          $choice = [];
           parse_str($field->attributes, $radioAttributes);
           $radioAttributes = array_merge($radioAttributes, $customFieldAttributes);
-
-          foreach ($options as $v => $l) {
-            $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $radioAttributes);
-          }
-          $element = $qf->addGroup($choice, $elementName, $label);
-          $optionEditKey = 'data-option-edit-path';
-          if (isset($selectAttributes[$optionEditKey])) {
-            $element->setAttribute($optionEditKey, $selectAttributes[$optionEditKey]);
-          }
-
-          if ($useRequired && !$search) {
-            $qf->addRule($elementName, ts('%1 is a required field.', [1 => $label]), 'required');
-          }
-          else {
-            $element->setAttribute('allowClear', TRUE);
-          }
+          $qf->addRadio($elementName, $label, $options, $radioAttributes, NULL, $useRequired);
         }
         break;