From a4969aeec139e0762a55956695f2747e860df44c Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Fri, 17 Apr 2015 14:47:19 +0200 Subject: [PATCH] Convert dedupeRuleForm to use addField method --- CRM/Admin/Form.php | 7 +++++++ CRM/Contact/Form/DedupeRules.php | 21 +++++++++++++-------- CRM/Core/Form.php | 18 +++++++++++++----- xml/schema/Dedupe/Rule.xml | 6 ++++++ xml/schema/Dedupe/RuleGroup.xml | 9 +++++++++ 5 files changed, 48 insertions(+), 13 deletions(-) diff --git a/CRM/Admin/Form.php b/CRM/Admin/Form.php index 31da21973a..315c7147cd 100644 --- a/CRM/Admin/Form.php +++ b/CRM/Admin/Form.php @@ -59,6 +59,13 @@ class CRM_Admin_Form extends CRM_Core_Form { */ protected $_BAOName; + /** + * Explicitly declare the form context. + */ + public function getDefaultContext() { + return 'create'; + } + /** * Basic setup. */ diff --git a/CRM/Contact/Form/DedupeRules.php b/CRM/Contact/Form/DedupeRules.php index b944442162..66d8a3dc98 100644 --- a/CRM/Contact/Form/DedupeRules.php +++ b/CRM/Contact/Form/DedupeRules.php @@ -44,6 +44,13 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { protected $_fields = array(); protected $_rgid; + /** + * Explicitly declare the entity api name. + */ + public function getDefaultEntity() { + return 'RuleGroup'; + } + /** * Pre processing. * @@ -100,16 +107,14 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { */ public function buildQuickForm() { $foo = CRM_Core_DAO::getAttribute('CRM_Dedupe_DAO_Rule', 'title'); - - $this->add('text', 'title', ts('Rule Name'), array('maxlength' => 255, 'class' => 'huge'), TRUE); + $this->addField('title', array('label' => ts('Rule Name')), TRUE); $this->addRule('title', ts('A duplicate matching rule with this name already exists. Please select another name.'), 'objectExists', array('CRM_Dedupe_DAO_RuleGroup', $this->_rgid, 'title') ); - $this->addRadio('used', ts('Usage'), $this->_options, NULL, NULL, TRUE); - + $this->addField('used', array('label' => ts('Usage'), 'type' => 'Radio'), TRUE); $disabled = array(); - $reserved = $this->add('checkbox', 'is_reserved', ts('Reserved?')); + $reserved = $this->addField('is_reserved', array('label' => ts('Reserved?'))); if (!empty($this->_defaults['is_reserved'])) { $reserved->freeze(); $disabled = array('disabled' => TRUE); @@ -126,11 +131,11 @@ class CRM_Contact_Form_DedupeRules extends CRM_Admin_Form { NULL => ts('- none -'), ) + $this->_fields, FALSE, $disabled ); - $this->add('text', "length_$count", ts('Length'), $attributes); - $this->add('text', "weight_$count", ts('Weight'), $attributes); + $this->addField('rule_length', array('entity' => 'Rule', 'name_id' => "length_$count") + $attributes); + $this->addField('rule_weight', array('entity' => 'Rule', 'name_id' => "weight_$count") + $attributes); } - $this->add('text', 'threshold', ts("Weight Threshold to Consider Contacts 'Matching':"), $attributes); + $this->addField('threshold', array('label' => ts("Weight Threshold to Consider Contacts 'Matching':")) + $attributes); $this->assign('contact_type', $this->_contactType); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index c6079b34c4..3568b2d62f 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1177,8 +1177,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { // Get field metadata. $fieldSpec = civicrm_api3($props['entity'], 'getfield', $props); $fieldSpec = $fieldSpec['values']; - - $label = CRM_Utils_Array::value('label', $props, $fieldSpec['title']); + $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL); + $name = isset($props['name_id']) ? $props['name_id'] : $name; $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type']; if ($widget == 'TextArea' && $props['context'] == 'search') { @@ -1205,7 +1205,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { unset($props['options']); } else { - $options = $fieldSpec['options']; + $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL; } // The placeholder is only used for select-elements. @@ -1254,7 +1254,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page { //case 'Select Date': //TODO: Add date formats //TODO: Add javascript template for dates. - // case 'Radio': + case 'Radio': + $separator = isset($props['separator']) ? $props['separator'] : NULL; + unset($props['seperator']); + $this->addRadio($name, $label, $options, NULL, $separator, $required); + break; + case 'Select': if (empty($props['multiple'])) { $options = array('' => $props['placeholder']) + $options; @@ -1264,7 +1269,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page { break; //case 'AdvMulti-Select': - //case 'CheckBox': + case 'CheckBox': + $this->add('checkbox', $name, $label, NULL, $required); + break; + case 'File': // We should not build upload file in search mode. if (isset($props['context']) && $props['context'] == 'search') { diff --git a/xml/schema/Dedupe/Rule.xml b/xml/schema/Dedupe/Rule.xml index a63d6ca094..627b80ef75 100644 --- a/xml/schema/Dedupe/Rule.xml +++ b/xml/schema/Dedupe/Rule.xml @@ -50,6 +50,9 @@ int unsigned The lenght of the matching substring 1.8 + + Text + rule_weight @@ -57,5 +60,8 @@ true The weight of the rule 1.8 + + Text + diff --git a/xml/schema/Dedupe/RuleGroup.xml b/xml/schema/Dedupe/RuleGroup.xml index eb59b83758..ee5acb0bc6 100644 --- a/xml/schema/Dedupe/RuleGroup.xml +++ b/xml/schema/Dedupe/RuleGroup.xml @@ -38,6 +38,9 @@ true The weight threshold the sum of the rule weights has to cross to consider two contacts the same 1.8 + + Text + level @@ -81,11 +84,17 @@ 255 Label of the rule group 4.1 + + Text + is_reserved boolean Is this a reserved rule - a rule group that has been optimized and cannot be changed by the admin 4.1 + + CheckBox + -- 2.25.1