Commit 82f3aedc authored by Seamus Lee's avatar Seamus Lee

CRM-19346 Add in form rule to ensure that option values can't use the same value

parent 30ce03ec
......@@ -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)
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment