From c352113cb92649fcf6674c4f4b9f46cfcef582c4 Mon Sep 17 00:00:00 2001 From: Michael Devery Date: Mon, 9 Apr 2018 12:33:50 +0100 Subject: [PATCH] dev/core#55: Hide "Add Option" for locked custom field option groups --- CRM/Custom/Page/Option.php | 35 ++++++++++++++++++++++++++++ templates/CRM/Custom/Page/Option.tpl | 4 +++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CRM/Custom/Page/Option.php b/CRM/Custom/Page/Option.php index 6e4b6e8ec0..8766e2cb04 100644 --- a/CRM/Custom/Page/Option.php +++ b/CRM/Custom/Page/Option.php @@ -232,6 +232,11 @@ WHERE option_group_id = %1"; CRM_Core_Error::fatal("You cannot add or edit muliple choice options in a reserved custom field-set."); } + $optionGroupId = $this->getOptionGroupId($this->_fid); + $isOptionGroupLocked = $optionGroupId ? $this->isOptionGroupLocked($optionGroupId) : FALSE; + $this->assign('optionGroupId', $optionGroupId); + $this->assign('isOptionGroupLocked', $isOptionGroupLocked); + //as url contain $gid so append breadcrumb dynamically. $breadcrumb = array( array( @@ -281,4 +286,34 @@ WHERE option_group_id = %1"; return parent::run(); } + /** + * Gets the "is_locked" status for the provided option group + * + * @param int $optionGroupId + * + * @return bool + */ + private function isOptionGroupLocked($optionGroupId) { + return (bool) CRM_Core_DAO::getFieldValue( + CRM_Core_DAO_OptionGroup::class, + $optionGroupId, + 'is_locked' + ); + } + + /** + * Gets the associated "option_group_id" for a custom field + * + * @param int $customFieldId + * + * @return int + */ + private function getOptionGroupId($customFieldId) { + return (int) CRM_Core_DAO::getFieldValue( + CRM_Core_DAO_CustomField::class, + $customFieldId, + 'option_group_id' + ); + } + } diff --git a/templates/CRM/Custom/Page/Option.tpl b/templates/CRM/Custom/Page/Option.tpl index 2322e6a3d8..fa99b71fe0 100644 --- a/templates/CRM/Custom/Page/Option.tpl +++ b/templates/CRM/Custom/Page/Option.tpl @@ -160,7 +160,9 @@ -- 2.25.1