Commit f167c7a9 authored by eileen's avatar eileen

Replace event form with a generic replacement form

parent a33f28e0
......@@ -32,14 +32,81 @@
*/
/**
* This class generates the form for event preferences.
* Generic metadata based settings form.
*
* The form filter will determine the settings displayed.
*/
class CRM_Admin_Form_Preferences_Event extends CRM_Admin_Form_Preferences {
class CRM_Admin_Form_Generic extends CRM_Core_Form {
use CRM_Admin_Form_SettingTrait;
protected $_settings = [
'enable_cart' => CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
'show_events' => CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
];
protected $_settings = [];
protected $includesReadOnlyFields = FALSE;
public $_defaults = [];
/**
* Get the tpl file name.
*
* @return string
*/
public function getTemplateFileName() {
return 'CRM/Form/basicForm.tpl';
}
/**
* Set default values for the form.
*
* Default values are retrieved from the database.
*/
public function setDefaultValues() {
$this->setDefaultsForMetadataDefinedFields();
return $this->_defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$filter = array_pop($this->urlPath);
$settings = civicrm_api3('Setting', 'getfields', [])['values'];
foreach ($settings as $key => $setting) {
if (isset($setting['settings_pages'][$filter])) {
$this->_settings[$key] = $setting;
}
}
// @todo sort settings by weight.
$this->addFieldsDefinedInSettingsMetadata();
// @todo look at sharing the code below in the settings trait.
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));
}
// @todo - do we still like this redirect?
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'),
),
)
);
}
/**
* Process the form submission.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
try {
$this->saveMetadataDefinedSettings($params);
}
catch (CiviCRM_API3_Exception $e) {
CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error');
}
}
}
......@@ -563,7 +563,7 @@
<item>
<path>civicrm/admin/setting/preferences/event</path>
<title>CiviEvent Component Settings</title>
<page_callback>CRM_Admin_Form_Preferences_Event</page_callback>
<page_callback>CRM_Admin_Form_Generic</page_callback>
</item>
<item>
<path>civicrm/admin/setting/preferences/mailing</path>
......
......@@ -138,7 +138,7 @@
<item>
<path>civicrm/admin/setting/preferences/event</path>
<title>CiviEvent Component Settings</title>
<page_callback>CRM_Admin_Form_Preferences_Event</page_callback>
<page_callback>CRM_Admin_Form_Generic</page_callback>
<desc>Configure global CiviEvent behaviors.</desc>
<access_arguments>access CiviEvent,administer CiviCRM</access_arguments>
<adminGroup>CiviEvent</adminGroup>
......
......@@ -38,6 +38,7 @@ return array(
'enable_cart' => array(
'name' => 'enable_cart',
'group_name' => 'Event Preferences',
'settings_pages' => ['event' => ['weight' => 10]],
'group' => 'event',
'type' => 'Boolean',
'quick_form_type' => 'CheckBox',
......@@ -54,6 +55,7 @@ return array(
'name' => 'show_events',
'group_name' => 'Event Preferences',
'group' => 'event',
'settings_pages' => ['event' => ['weight' => 20]],
'type' => 'Integer',
'quick_form_type' => 'Select',
'default' => 10,
......
{*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{include file="CRM/Form/basicForm.tpl"}
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