From 82f3aedc43466da228e26f59c2e143a2c0899599 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 9 Oct 2017 19:39:58 +1100 Subject: [PATCH] CRM-19346 Add in form rule to ensure that option values can't use the same value --- CRM/Admin/Form/Options.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index e247f55194..44f036b7dd 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -50,6 +50,12 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { */ protected $_gLabel; + /** + * Is this Option Group Domain Specific + * @var bool + */ + protected $_domainSpecific = FALSE; + /** * Pre-process */ @@ -164,7 +170,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'), TRUE ); - + $domainSpecificOptionGroups = array('from_email_address'); + $this->_domainSpecific = in_array($this->_gName, $domainSpecificOptionGroups) ? TRUE : FALSE; if ($this->_gName != 'activity_type') { $this->add('text', 'value', @@ -172,6 +179,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'), TRUE ); + $this->addRule('value', + ts('This Value already exists in the database for this option group. Please select a different Value.'), + 'optionExists', + array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'value', $this->_domainSpecific) + ); } else { $this->add('text', 'icon', ts('Icon'), array('class' => 'crm-icon-picker', 'title' => ts('Choose Icon'), 'allowClear' => TRUE)); @@ -187,12 +199,10 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { 'addressee', )) && !$isReserved ) { - $domainSpecificOptionGroups = array('from_email_address'); - $domainSpecific = in_array($this->_gName, $domainSpecificOptionGroups) ? TRUE : FALSE; $this->addRule('label', - ts('This Label already exists in the database for this option group. Please select a different Value.'), + ts('This Label already exists in the database for this option group. Please select a different Label.'), 'optionExists', - array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $domainSpecific) + array('CRM_Core_DAO_OptionValue', $this->_id, $this->_gid, 'label', $this->_domainSpecific) ); } -- 2.25.1