From 916b618122053441ae4310150a82f9f25ce1e3ed Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 29 Dec 2015 18:09:24 -0500 Subject: [PATCH] CRM-17757 - Fix metadata for CRM_Core_Form::addField --- CRM/Core/Form.php | 23 ++++++++++++----------- xml/schema/Activity/Activity.xml | 2 +- xml/schema/Batch/Batch.xml | 2 +- xml/schema/Campaign/Campaign.xml | 2 +- xml/schema/Case/CaseContact.xml | 2 +- xml/schema/Contact/Contact.xml | 8 +++----- xml/schema/Contribute/Contribution.xml | 2 +- xml/schema/Event/Event.xml | 4 ++-- xml/schema/Grant/Grant.xml | 2 +- xml/schema/Member/Membership.xml | 2 +- xml/schema/PCP/PCP.xml | 2 +- xml/schema/Pledge/Pledge.xml | 2 +- xml/schema/SMS/History.xml | 2 +- 13 files changed, 27 insertions(+), 28 deletions(-) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 183f4b40c7..ab3e9e89de 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1342,26 +1342,27 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ public function addField($name, $props = array(), $required = FALSE) { // Resolve context. - if (!isset($props['context'])) { + if (empty($props['context'])) { $props['context'] = $this->getDefaultContext(); } + $context = $props['context']; // Resolve entity. - if (!isset($props['entity'])) { + if (empty($props['entity'])) { $props['entity'] = $this->getDefaultEntity(); } // Resolve field. - if (!isset($props['name'])) { + if (empty($props['name'])) { $props['name'] = strrpos($name, '[') ? rtrim(substr($name, 1 + strrpos($name, '[')), ']') : $name; } // Resolve action. - if (!isset($props['action'])) { + if (empty($props['action'])) { $props['action'] = $this->getApiAction(); } // Handle custom fields if (strpos($name, 'custom_') === 0 && is_numeric($name[7])) { $fieldId = (int) substr($name, 7); - return CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $fieldId, $required, $props['context'] == 'search', CRM_Utils_Array::value('label', $props)); + return CRM_Core_BAO_CustomField::addQuickFormElement($this, $name, $fieldId, $required, $context == 'search', CRM_Utils_Array::value('label', $props)); } // Core field - get metadata. @@ -1370,7 +1371,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $label = CRM_Utils_Array::value('label', $props, isset($fieldSpec['title']) ? $fieldSpec['title'] : NULL); $widget = isset($props['type']) ? $props['type'] : $fieldSpec['html']['type']; - if ($widget == 'TextArea' && $props['context'] == 'search') { + if ($widget == 'TextArea' && $context == 'search') { $widget = 'Text'; } @@ -1389,13 +1390,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page { else { $options = isset($fieldSpec['options']) ? $fieldSpec['options'] : NULL; } - if ($props['context'] == 'search') { + if ($context == 'search') { $widget = 'Select'; $props['multiple'] = CRM_Utils_Array::value('multiple', $props, TRUE); } // Add data for popup link. - if ((!empty($props['option_url']) || !array_key_exists('option_url', $props)) && ($props['context'] != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) { + if ((!empty($props['option_url']) || !array_key_exists('option_url', $props)) && ($context != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) { $props['data-option-edit-path'] = !empty($props['option_url']) ? $props['option_url'] : CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); $props['data-api-entity'] = $props['entity']; $props['data-api-field'] = $props['name']; @@ -1441,14 +1442,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page { $props += array( 'required' => $required, 'label' => $label, - 'multiple' => $props['context'] == 'search', + 'multiple' => $context == 'search', ); return $this->addChainSelect($name, $props); case 'Select': $props['class'] = CRM_Utils_Array::value('class', $props, 'big') . ' crm-select2'; if (!array_key_exists('placeholder', $props)) { - $props['placeholder'] = $required ? ts('- select -') : $props['context'] == 'search' ? ts('- any -') : ts('- none -'); + $props['placeholder'] = $required ? ts('- select -') : $context == 'search' ? ts('- any -') : ts('- none -'); } // TODO: Add and/or option for fields that store multiple values return $this->add('select', $name, $label, $options, $required, $props); @@ -1472,7 +1473,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { case 'File': // We should not build upload file in search mode. - if ($props['context'] == 'search') { + if ($context == 'search') { return; } $file = $this->add('file', $name, $label, $props, $required); diff --git a/xml/schema/Activity/Activity.xml b/xml/schema/Activity/Activity.xml index 59348ba6b6..4948f49de8 100644 --- a/xml/schema/Activity/Activity.xml +++ b/xml/schema/Activity/Activity.xml @@ -196,7 +196,7 @@ Phone ID of the number called (optional - used if an existing phone number is selected). 2.0 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Batch/Batch.xml b/xml/schema/Batch/Batch.xml index 9477065c9f..449c6c1bc4 100644 --- a/xml/schema/Batch/Batch.xml +++ b/xml/schema/Batch/Batch.xml @@ -121,7 +121,7 @@ FK to Saved Search ID 4.1 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Campaign/Campaign.xml b/xml/schema/Campaign/Campaign.xml index 01e6767061..da4ec8cbb0 100644 --- a/xml/schema/Campaign/Campaign.xml +++ b/xml/schema/Campaign/Campaign.xml @@ -158,7 +158,7 @@ true 3.3 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Case/CaseContact.xml b/xml/schema/Case/CaseContact.xml index 218dbcce41..43c8310095 100644 --- a/xml/schema/Case/CaseContact.xml +++ b/xml/schema/Case/CaseContact.xml @@ -38,7 +38,7 @@ true Contact ID of contact record given case belongs to. - Autocomplete-Select + EntityRef 2.1 diff --git a/xml/schema/Contact/Contact.xml b/xml/schema/Contact/Contact.xml index 52739de3c3..bcf7c8f385 100644 --- a/xml/schema/Contact/Contact.xml +++ b/xml/schema/Contact/Contact.xml @@ -61,16 +61,14 @@ parent_id IS NOT NULL - Multi-Select + Select + 1 1.5 index_contact_sub_type contact_sub_type - - Multi-Select - 2.1 @@ -805,7 +803,7 @@ true 2.1 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Contribute/Contribution.xml b/xml/schema/Contribute/Contribution.xml index 84c80292a8..db883c14e6 100644 --- a/xml/schema/Contribute/Contribution.xml +++ b/xml/schema/Contribute/Contribution.xml @@ -31,7 +31,7 @@ /^\d+$/ FK to Contact ID - Autocomplete-Select + EntityRef 1.3 diff --git a/xml/schema/Event/Event.xml b/xml/schema/Event/Event.xml index 25bd248e21..decd8a8cb3 100644 --- a/xml/schema/Event/Event.xml +++ b/xml/schema/Event/Event.xml @@ -778,7 +778,7 @@ 3.4 - Autocomplete-Select + EntityRef @@ -816,7 +816,7 @@ NULL Implicit FK to civicrm_event: parent event - Autocomplete-Select + EntityRef 4.1 diff --git a/xml/schema/Grant/Grant.xml b/xml/schema/Grant/Grant.xml index 0cd308dd84..ebb27f30a8 100644 --- a/xml/schema/Grant/Grant.xml +++ b/xml/schema/Grant/Grant.xml @@ -30,7 +30,7 @@ Contact ID of contact record given grant belongs to. 1.8 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Member/Membership.xml b/xml/schema/Member/Membership.xml index 15de8ff827..53336f081e 100644 --- a/xml/schema/Member/Membership.xml +++ b/xml/schema/Member/Membership.xml @@ -35,7 +35,7 @@ FK to Contact ID 1.5 - Autocomplete-Select + EntityRef diff --git a/xml/schema/PCP/PCP.xml b/xml/schema/PCP/PCP.xml index b5fcabf820..46f66b6c30 100644 --- a/xml/schema/PCP/PCP.xml +++ b/xml/schema/PCP/PCP.xml @@ -28,7 +28,7 @@ FK to Contact ID 2.2 - Autocomplete-Select + EntityRef diff --git a/xml/schema/Pledge/Pledge.xml b/xml/schema/Pledge/Pledge.xml index 86ab5b921c..e407d86c70 100644 --- a/xml/schema/Pledge/Pledge.xml +++ b/xml/schema/Pledge/Pledge.xml @@ -29,7 +29,7 @@ Foreign key to civicrm_contact.id . 2.1 - Autocomplete-Select + EntityRef diff --git a/xml/schema/SMS/History.xml b/xml/schema/SMS/History.xml index 550b4b8a2c..0cd60b2ae4 100644 --- a/xml/schema/SMS/History.xml +++ b/xml/schema/SMS/History.xml @@ -36,7 +36,7 @@ FK to Contact who is sending this SMS 1.4 - Autocomplete-Select + EntityRef -- 2.25.1