From d1a98215a48d241c430f23caef17f23ba4169614 Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Sat, 11 Apr 2015 11:10:13 +0200 Subject: [PATCH] Remove add to addElement changes --- CRM/Core/Form.php | 28 ++++------------------------ 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index c23792c982..673401dc67 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1243,14 +1243,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page { case 'Text': case 'Link': //TODO: Autodetect ranges - $element = $this->addElement('text', $name, $label, $props); - if ($required) { - $this->addRequiredRule($element); - } + $this->add('text', $name, $label, $props, $required); break; case 'hidden': - $this->addElement('hidden', $name, $label, $props); + $this->add('hidden', $name, $label, $props, $required); break; //case 'TextArea': @@ -1262,10 +1259,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if (empty($props['multiple'])) { $options = array('' => $props['placeholder']) + $options; } - $this->addElement('select', $name, $label, $options, $props); - if ($required) { - $this->addRequiredRule($element); - } + $this->add('select', $name, $label, $options, $required, $props); // TODO: Add and/or option for fields that store multiple values break; @@ -1276,18 +1270,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if (isset($props['context']) && $props['context'] == 'search') { return; } - $this->addElement('file', $name, $label, $props); + $this->add('file', $name, $label, $props, $required); $this->addUploadElement($name); - if ($required) { - $this->addRequiredRule($element, 'uploadedfile'); - } break; //case 'RichTextEditor': //TODO: Add javascript template for wysiwyg. case 'Autocomplete-Select': case 'EntityRef': - //TODO: Refactor to avoid add-method. $this->addEntityRef($name, $label, $props, $required); break; @@ -1302,16 +1292,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } - /** - * Add a required rule to a form element. - */ - public function addRequiredRule($element, $rule = 'required') { - $error = $this->addRule($element->getName(), ts('%1 is a required field.', array(1 => $element->getLabel())), $rule); - if (HTML_QuickForm::isError($error)) { - CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element)); - } - } - /** * Add a widget for selecting/editing/creating/copying a profile form * -- 2.25.1