Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Adding Option Value for Locked Groups #11962

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CRM/Admin/Page/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class CRM_Admin_Page_Options extends CRM_Core_Page_Basic {
public function preProcess() {
if (!self::$_gName && !empty($this->urlPath[3])) {
self::$_gName = $this->urlPath[3];
self::$_isLocked = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', self::$_gName, 'is_locked', 'name');
}
// If an id arg is passed instead of a group name in the path
elseif (!self::$_gName && !empty($_GET['gid'])) {
Expand Down
35 changes: 35 additions & 0 deletions CRM/Custom/Page/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ public function run() {
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(
Expand Down Expand Up @@ -281,4 +286,34 @@ public function run() {
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'
);
}

}
4 changes: 3 additions & 1 deletion templates/CRM/Custom/Page/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@

<div class="action-link">
{crmButton q="reset=1&action=map&fid=$fid&gid=$gid" class="action-item open-inline-noreturn" icon="sort-alpha-asc"}{ts}Alphabetize Options{/ts}{/crmButton}
{crmButton q="reset=1&action=add&fid=$fid&gid=$gid" class="action-item" icon="plus-circle"}{ts}Add Option{/ts}{/crmButton}
{if !$isOptionGroupLocked}
{crmButton q="reset=1&action=add&fid=$fid&gid=$gid" class="action-item" icon="plus-circle"}{ts}Add Option{/ts}{/crmButton}
{/if}
{crmButton p="civicrm/admin/custom/group/field" q="reset=1&action=browse&gid=$gid" class="action-item cancel" icon="times"}{ts}Done{/ts}{/crmButton}
</div>
</div>
Expand Down