From e09fe81dc0dca8745b42c296acc447c9cf2eaf26 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 1 Apr 2014 16:08:05 +0530 Subject: [PATCH] HR-322, extend customFieldOptions hook to support Select options buildup with no associate option group --- CRM/Core/BAO/CustomField.php | 18 +++++++++++++----- CRM/Utils/Hook.php | 3 ++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 2ee32b34b0..8ad18fdff0 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -753,7 +753,7 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { if ($field->html_type == 'TextArea' && $search) { $field->html_type = 'Text'; } - + $placeholder = $search ? ts('- any -') : ($useRequired ? ts('- select -') : ts('- none -')); // FIXME: Why are select state/country separate widget types? @@ -767,7 +767,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { } } // Add data so popup link. Normally this is handled by CRM_Core_Form->addSelect - if (in_array($field->html_type, array('Select', 'Multi-Select')) && !$search && CRM_Core_Permission::check('administer CiviCRM')) { + //HR-322, For html type Select sometime we don't rely on $field->option_group_id but + //use customFieldOptions hook to populate options, so we include that on condition + if (in_array($field->html_type, array('Select', 'Multi-Select')) && $field->option_group_id && !$search && CRM_Core_Permission::check('administer CiviCRM')) { $selectAttributes += array( 'data-api-entity' => 'contact', // FIXME: This works because the getoptions api isn't picky about custom fields, but it's WRONG 'data-api-field' => 'custom_' . $field->id, @@ -882,9 +884,15 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { break; case 'Select': - $selectOption = &CRM_Core_BAO_CustomOption::valuesByID($field->id, - $field->option_group_id - ); + if ($field->option_group_id) { + $selectOption = &CRM_Core_BAO_CustomOption::valuesByID($field->id, + $field->option_group_id + ); + } + else { + CRM_Utils_Hook::customFieldOptions($field->id, $selectOption, FALSE, $selectAttributes); + } + $qf->add('select', $elementName, $label, array('' => $placeholder) + $selectOption, $useRequired && !$search, diff --git a/CRM/Utils/Hook.php b/CRM/Utils/Hook.php index ed534bc027..41755d1017 100644 --- a/CRM/Utils/Hook.php +++ b/CRM/Utils/Hook.php @@ -623,10 +623,11 @@ abstract class CRM_Utils_Hook { * Only add/edit/remove the specific field options you intend to affect. * @param boolean $detailedFormat - if true, * the options are in an ID => array ( 'id' => ID, 'label' => label, 'value' => value ) format + * @param array $selectAttributes contain select attribute(s) if any * * @return mixed */ - static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE) { + static function customFieldOptions($customFieldID, &$options, $detailedFormat = FALSE, $selectAttributes = array()) { return self::singleton()->invoke(3, $customFieldID, $options, $detailedFormat, self::$_nullObject, self::$_nullObject, self::$_nullObject, 'civicrm_customFieldOptions' -- 2.25.1