_action & CRM_Core_Action::DELETE) { return; } CRM_Utils_System::setTitle(ts('Dropdown Options')); $this->applyFilter('__ALL__', 'trim'); $this->add('text', 'name', ts('Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'name'), TRUE ); $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', ['CRM_Core_DAO_OptionGroup', $this->_id] ); $this->add('text', 'title', ts('Group Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'title') ); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionGroup', 'description') ); $this->addSelect('data_type', ['options' => CRM_Utils_Type::dataTypes()], empty($this->_values['is_reserved'])); $element = $this->add('checkbox', 'is_active', ts('Enabled?')); if ($this->_action & CRM_Core_Action::UPDATE) { if (in_array($this->_values['name'], [ 'encounter_medium', 'case_type', 'case_status', ])) { static $caseCount = NULL; if (!isset($caseCount)) { $caseCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE); } if ($caseCount > 0) { $element->freeze(); } } $this->add('checkbox', 'is_reserved', ts('Reserved?')); $this->freeze('is_reserved'); if (!empty($this->_values['is_reserved'])) { $this->freeze(['name', 'is_active', 'data_type']); } } $this->assign('id', $this->_id); } /** * Process the form submission. */ public function postProcess() { CRM_Utils_System::flushCache(); if ($this->_action & CRM_Core_Action::DELETE) { CRM_Core_BAO_OptionGroup::del($this->_id); CRM_Core_Session::setStatus(ts('Selected option group has been deleted.'), ts('Record Deleted'), 'success'); } else { // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::ADD) { // If we are adding option group via UI it should not be marked reserved. if (!isset($params['is_reserved'])) { $params['is_reserved'] = 0; } } elseif ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $optionGroup = CRM_Core_BAO_OptionGroup::add($params); CRM_Core_Session::setStatus(ts('The Option Group \'%1\' has been saved.', [1 => $optionGroup->name]), ts('Saved'), 'success'); } } }