From 599ae208da4b97a332bb1caef9d11271c81d6b8b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 22 Dec 2015 22:27:17 -0500 Subject: [PATCH] CRM_Core_Form::addField fixes --- CRM/Contact/Form/Contact.php | 5 ++--- CRM/Core/Form.php | 22 ++++++++-------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/CRM/Contact/Form/Contact.php b/CRM/Contact/Form/Contact.php index 1d2dba8fb6..4bde8dc3b8 100644 --- a/CRM/Contact/Form/Contact.php +++ b/CRM/Contact/Form/Contact.php @@ -779,9 +779,8 @@ class CRM_Contact_Form_Contact extends CRM_Core_Form { 'options' => $subtypes, 'class' => $buildCustomData, 'multiple' => 'multiple', - 'options-url' => FALSE, - ) - ); + 'option_url' => NULL, + )); } // build edit blocks ( custom data, demographics, communication preference, notes, tags and groups ) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 04b2cdd84b..a9713154ce 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1210,7 +1210,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if ($action & (CRM_Core_Action::UPDATE + CRM_Core_Action::ADD)) { return 'create'; } - if ($action & (CRM_Core_Action::BROWSE)) { + if ($action & (CRM_Core_Action::BROWSE + CRM_Core_Action::BASIC + CRM_Core_Action::ADVANCED + CRM_Core_Action::PREVIEW)) { return 'get'; } // If you get this exception try adding more cases above. @@ -1294,7 +1294,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } $label = isset($props['label']) ? $props['label'] : $fieldSpec['title']; if (CRM_Utils_Array::value('context', $props) != 'search') { - $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : $props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); + $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); } } $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2"; @@ -1380,19 +1380,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if ($props['context'] == 'search' || ($widget !== 'AdvMulti-Select' && strpos($widget, 'Select') !== FALSE)) { $widget = 'Select'; } - // Set default options-url value. - if ((!isset($props['options-url']))) { - $props['options-url'] = TRUE; - } // Add data for popup link. - if ((isset($props['options-url']) && $props['options-url']) && ($props['context'] != 'search' && $widget == 'Select' && CRM_Core_Permission::check('administer CiviCRM'))) { - $props['data-option-edit-path'] = array_key_exists('option_url', $props) ? $props['option_url'] : $props['data-option-edit-path'] = CRM_Core_PseudoConstant::getOptionEditUrl($fieldSpec); + if ((!empty($props['option_url']) || !array_key_exists('option_url', $props)) && ($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']; - if (isset($props['options-url'])) { - unset($props['options-url']); - } } } //Use select2 library for following widgets. @@ -1405,7 +1398,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { 'Multi-Select Country', ))); if ($isSelect2) { - $props['class'] = (isset($props['class']) ? $props['class'] . ' ' : '') . "crm-select2"; + $props['class'] = (!empty($props['class']) ? $props['class'] . ' ' : '') . "crm-select2"; if ($props['context'] == 'search' || strpos($widget, 'Multi') !== FALSE) { $props['class'] .= ' huge'; $props['multiple'] = 'multiple'; @@ -1416,7 +1409,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page { } } $props += CRM_Utils_Array::value('html', $fieldSpec, array()); - CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type'); + CRM_Utils_Array::remove($props, 'entity', 'name', 'context', 'label', 'action', 'type', 'option_url'); + // TODO: refactor switch statement, to separate methods. switch ($widget) { case 'Text': @@ -1432,7 +1426,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { //Set default columns and rows for textarea. $props['rows'] = isset($props['rows']) ? $props['rows'] : 4; $props['cols'] = isset($props['cols']) ? $props['cols'] : 60; - return $this->addElement('textarea', $name, $label, $props, $required); + return $this->add('textarea', $name, $label, $props, $required); case 'Select Date': //TODO: add range support -- 2.25.1