From 064d86856721361c1436245ba9811f37e6082af6 Mon Sep 17 00:00:00 2001 From: "Matthew Wire (MJW Consulting)" Date: Fri, 24 Aug 2018 15:38:37 +0100 Subject: [PATCH] Follow on to #12718 - Display all non-reserved option groups on update, making sure the existing one is selected. --- CRM/Custom/Form/Field.php | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/CRM/Custom/Form/Field.php b/CRM/Custom/Form/Field.php index 0a83a5b37e..4391c22ee3 100644 --- a/CRM/Custom/Form/Field.php +++ b/CRM/Custom/Form/Field.php @@ -315,26 +315,22 @@ class CRM_Custom_Form_Field extends CRM_Core_Form { $this->add('checkbox', 'in_selector', ts('Display in Table?')); } - if ($this->_action == CRM_Core_Action::UPDATE) { - $this->freeze('data_type'); - } + $optionGroupParams = [ + 'is_reserved' => 0, + 'is_active' => 1, + 'options' => ['limit' => 0, 'sort' => "title ASC"], + 'return' => ['title'], + ]; if ($this->_action == CRM_Core_Action::UPDATE) { - $optionGroupParams = [ - 'id' => $this->_values['option_group_id'], - 'return' => ['title'], - ]; - } - else { - $optionGroupParams = [ - 'is_reserved' => 0, - 'is_active' => 1, - 'options' => ['limit' => 0, 'sort' => "title ASC"], - 'return' => ['title'], - ]; + $this->freeze('data_type'); + // Before dev/core#155 we didn't set the is_reserved flag properly, which should be handled by the upgrade script... + // but it is still possible that existing installs may have optiongroups linked to custom fields that are marked reserved. + $optionGroupParams['id'] = $this->_values['option_group_id']; + $optionGroupParams['options']['or'] = [["is_reserved", "id"]]; } - // Get all custom (is_reserved=0) option groups + // Retrieve optiongroups for selection list $optionGroupMetadata = civicrm_api3('OptionGroup', 'get', $optionGroupParams); // OptionGroup selection -- 2.25.1