Replace event form with a generic replacement form
authoreileen <emcnaughton@wikimedia.org>
Thu, 1 Nov 2018 21:55:17 +0000 (10:55 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 5 Nov 2018 19:03:55 +0000 (08:03 +1300)
CRM/Admin/Form/Generic.php [new file with mode: 0644]
CRM/Admin/Form/Preferences/Event.php [deleted file]
CRM/Core/xml/Menu/Admin.xml
CRM/Event/xml/Menu/Event.xml
settings/Event.setting.php
templates/CRM/Admin/Form/Preferences/Event.tpl [deleted file]

diff --git a/CRM/Admin/Form/Generic.php b/CRM/Admin/Form/Generic.php
new file mode 100644 (file)
index 0000000..c61e223
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2018
+ */
+
+/**
+ * Generic metadata based settings form.
+ *
+ * The form filter will determine the settings displayed.
+ */
+class CRM_Admin_Form_Generic extends CRM_Core_Form {
+  use CRM_Admin_Form_SettingTrait;
+
+  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');
+    }
+  }
+
+}
diff --git a/CRM/Admin/Form/Preferences/Event.php b/CRM/Admin/Form/Preferences/Event.php
deleted file mode 100644 (file)
index b6d6d2c..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | 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        |
- +--------------------------------------------------------------------+
- */
-
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
- */
-
-/**
- * This class generates the form for event preferences.
- *
- */
-class CRM_Admin_Form_Preferences_Event extends CRM_Admin_Form_Preferences {
-
-  protected $_settings = [
-    'enable_cart' => CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
-    'show_events' => CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME,
-  ];
-
-}
index 38377d0850c24df6a550cfc3ea3642402657bbd3..918d372cae3e350bd9f3aa68837ad5c34b1e62c0 100644 (file)
   <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>
index f9d1d464eff67c5941ca7e8d6a9b5129b6211e86..7cc9a3ba68945be7bce018f766f053d3f70178c6 100644 (file)
   <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>
index e9ce8749f46e942d6232f741fc7e094b6f766272..29413fdfb19335a8b30880b0e1479ec337729e01 100644 (file)
@@ -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,
diff --git a/templates/CRM/Admin/Form/Preferences/Event.tpl b/templates/CRM/Admin/Form/Preferences/Event.tpl
deleted file mode 100644 (file)
index 9baa42d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-{*
- +--------------------------------------------------------------------+
- | 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"}