_defaults) { $this->_defaults = array(); $formArray = array('Component', 'Localization'); $formMode = FALSE; if (in_array($this->_name, $formArray)) { $formMode = TRUE; } $this->setDefaultsForMetadataDefinedFields(); // @todo these should be retrievable from the above function. $this->_defaults['enableSSL'] = Civi::settings()->get('enableSSL'); $this->_defaults['verifySSL'] = Civi::settings()->get('verifySSL'); $this->_defaults['environment'] = CRM_Core_Config::environment(); $this->_defaults['enableComponents'] = Civi::settings()->get('enable_components'); } return $this->_defaults; } /** * Build the form object. */ public function buildQuickForm() { CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); $this->addButtons(array( array( 'type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE, ), array( 'type' => 'cancel', 'name' => ts('Cancel'), ), ) ); $this->addFieldsDefinedInSettingsMetadata(); if ($this->includesReadOnlyFields) { CRM_Core_Session::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', array('expires' => 0)); } } /** * Process the form submission. */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); self::commonProcess($params); } /** * Common Process. * * @todo Document what I do. * * @param array $params * @throws \CRM_Core_Exception */ public function commonProcess(&$params) { // save components to be enabled if (array_key_exists('enableComponents', $params)) { civicrm_api3('setting', 'create', array( 'enable_components' => $params['enableComponents'], )); unset($params['enableComponents']); } foreach (array('verifySSL', 'enableSSL') as $name) { if (isset($params[$name])) { Civi::settings()->set($name, $params[$name]); unset($params[$name]); } } try { $settings = $this->getSettingsToSetByMetadata($params); $this->saveMetadataDefinedSettings($params); } catch (CiviCRM_API3_Exception $e) { CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error'); } $this->filterParamsSetByMetadata($params); $params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params); if (!empty($params)) { throw new CRM_Core_Exception('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')'); } CRM_Core_Config::clearDBCache(); Civi::cache('session')->clear(); // This doesn't make a lot of sense to me, but it maintains pre-existing behavior. CRM_Utils_System::flushCache(); CRM_Core_Resources::singleton()->resetCacheCode(); CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success"); } public function rebuildMenu() { // ensure config is set with new values $config = CRM_Core_Config::singleton(TRUE, TRUE); // rebuild menu items CRM_Core_Menu::store(); // also delete the IDS file so we can write a new correct one on next load $configFile = $config->uploadDir . 'Config.IDS.ini'; @unlink($configFile); } }