CRM-20923 refactor tpl to be based on metadata not hard-coding
authoreileen <emcnaughton@wikimedia.org>
Thu, 20 Jul 2017 01:02:15 +0000 (13:02 +1200)
committereileen <emcnaughton@wikimedia.org>
Thu, 20 Jul 2017 23:23:17 +0000 (11:23 +1200)
Change-Id: Iee2a7aa9fa93c5d20b95f3dbc45ec2f3cf7a216b

CRM/Admin/Form/Setting.php
CRM/Admin/Form/Setting/Mail.php
templates/CRM/Admin/Form/Setting/Mail.tpl
templates/CRM/Admin/Form/Setting/SettingForm.tpl [new file with mode: 0644]

index 671c8fe7ed3fb7cccadaf4b84370871568c78e6f..103b43680368741c068fb0d9292c5e362d9f4bf5 100644 (file)
@@ -78,10 +78,7 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
    * Build the form object.
    */
   public function buildQuickForm() {
-    $session = CRM_Core_Session::singleton();
-    $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
-    $args = func_get_args();
-    $check = reset($args);
+    CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
     $this->addButtons(array(
         array(
           'type' => 'next',
@@ -96,9 +93,8 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
     );
 
     $descriptions = array();
-    foreach ($this->_settings as $setting => $group) {
-      $settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
-      $props = $settingMetaData['values'][$setting];
+    $settingMetaData = $this->getSettingsMetaData();
+    foreach ($settingMetaData as $setting => $props) {
       if (isset($props['quick_form_type'])) {
         if (isset($props['pseudoconstant'])) {
           $options = civicrm_api3('Setting', 'getoptions', array(
@@ -150,7 +146,9 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
       }
     }
+    // setting_description should be deprecated - see Mail.tpl for metadata based tpl.
     $this->assign('setting_descriptions', $descriptions);
+    $this->assign('settings_fields', $settingMetaData);
   }
 
   /**
@@ -291,4 +289,17 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
     ) + $autoSearchFields;
   }
 
+  /**
+   * Get the metadata relating to the settings on the form, ordered by the keys in $this->_settings.
+   *
+   * @return array
+   */
+  protected function getSettingsMetaData() {
+    $allSettingMetaData = civicrm_api3('setting', 'getfields', array());
+    $settingMetaData = array_intersect_key($allSettingMetaData['values'], $this->_settings);
+    // This array_merge re-orders to the key order of $this->_settings.
+    $settingMetaData = array_merge($this->_settings, $settingMetaData);
+    return $settingMetaData;
+  }
+
 }
index 960ce2abae1efcc5259ff39157199239a3ba46a0..83679cabe9b760ae3718497747dd41fda4339699 100644 (file)
 class CRM_Admin_Form_Setting_Mail extends CRM_Admin_Form_Setting {
 
   protected $_settings = array(
-    'replyTo' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
     'mailerBatchLimit' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
+    'mailThrottleTime' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
     'mailerJobSize' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
     'mailerJobsMax' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
-    'mailThrottleTime' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
     'verpSeparator' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
+    'replyTo' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
   );
 
   /**
@@ -50,15 +50,9 @@ class CRM_Admin_Form_Setting_Mail extends CRM_Admin_Form_Setting {
    */
   public function buildQuickForm() {
     CRM_Utils_System::setTitle(ts('Settings - CiviMail'));
-    $check = TRUE;
-
-    // redirect to Administer Section After hitting either Save or Cancel button.
-    $session = CRM_Core_Session::singleton();
-    $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
-
     $this->addFormRule(array('CRM_Admin_Form_Setting_Mail', 'formRule'));
 
-    parent::buildQuickForm($check);
+    parent::buildQuickForm();
   }
 
   /**
index 964dd095a46fb733a360eb564a1a53c72279c003..1cbd03fd82e81103963c1ad1bc0822a1b1cfe4c1 100644 (file)
 <div class="help">
     {ts 1=$docLink}These settings are used to configure mailer properties for the optional CiviMail component and may allow you to significantly optimize performance. Please read the %1 documentation, and make sure you understand it before modifying default values. (These settings are NOT used for the built-in 'Email - send now' feature).{/ts}
 </div>
-<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
-      <table class="form-layout-compressed">
-        <tr class="crm-mail-form-block-mailerBatchLimit">
-            <td class="label">{$form.mailerBatchLimit.label}</td><td>{$form.mailerBatchLimit.html}<br />
-            <span class="description">{ts}Throttle email delivery by setting the maximum number of emails sent during each CiviMail run (0 = unlimited).{/ts}</span></td>
-        </tr>
-        <tr class="crm-mail-form-block-mailThrottleTime">
-          <td class="label">{$form.mailThrottleTime.label}</td><td>{$form.mailThrottleTime.html} <br />
-          <span class="description">{ts}The time to sleep in between each e-mail in micro seconds. Setting this above 0 allows you to control the rate at which e-mail messages are sent to the mail server, avoiding filling up the mail queue very quickly. Set to 0 to disable.{/ts}</span></td>
-        </tr>
-        <tr class="crm-mail-form-block-mailerJobSize">
-            <td class="label">{$form.mailerJobSize.label}</td><td>{$form.mailerJobSize.html}<br />
-            <span class="description">{ts}If you want to utilize multi-threading enter the size you want your sub jobs to be split into. Recommended values are between 1,000 and 10,000. Use a lower value if your server has multiple cron jobs running simultaneously, but do not use values smaller than 1,000. Enter "0" to disable multi-threading and process mail as one single job - batch limits still apply.{/ts}</span></td>
-        </tr>
-        <tr class="crm-mail-form-block-mailerJobsMax">
-            <td class="label">{$form.mailerJobsMax.label}</td><td>{$form.mailerJobsMax.html}<br />
-            <span class="description">{ts}The maximum number of mailer delivery jobs executing simultaneously (0 = allow as many processes to execute as started by cron){/ts}</span></td>
-        </tr>
-        <tr class="crm-mail-form-block-verpSeparator">
-            <td class="label">{$form.verpSeparator.label}</td><td>{$form.verpSeparator.html}<br />
-            <span class="description">{ts}Separator character used when CiviMail generates VERP (variable envelope return path) Mail-From addresses.{/ts}</span></td>
-        </tr>
-        <tr class="crm-mail-form-block-replyTo">
-            <td class="label">{$form.replyTo.label}</td><td>{$form.replyTo.html}<br />
-            <span class="description">{ts}Allow CiviMail users to send mailings with a custom Reply-To header.{/ts}</span></td>
-        </tr>
-      </table>
-<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
-<div class="spacer"></div>
-</div>
+{include file='CRM/Admin/Form/Setting/SettingForm.tpl'}
diff --git a/templates/CRM/Admin/Form/Setting/SettingForm.tpl b/templates/CRM/Admin/Form/Setting/SettingForm.tpl
new file mode 100644 (file)
index 0000000..6cd4465
--- /dev/null
@@ -0,0 +1,40 @@
+{*
++--------------------------------------------------------------------+
+| CiviCRM version 4.7                                                |
++--------------------------------------------------------------------+
+| Copyright CiviCRM LLC (c) 2004-2017                                |
++--------------------------------------------------------------------+
+| 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        |
++--------------------------------------------------------------------+
+*}
+{
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
+  <table class="form-layout-compressed">
+    {foreach from=$settings_fields key="setting_name" item="setting_detail"}
+      <tr class="crm-mail-form-block-{$setting_name}">
+        <td class="label">{$form.$setting_name.label}</td><td>{$form.$setting_name.html}<br />
+          <span class="description">{ts}{$setting_detail.description}{/ts}</span>{if $setting_detail.help_text}
+            {assign var='tplhelp_id' value = $setting_name|cat:'-id'|replace:'_':'-'}
+            {help id="$tplhelp_id"}{/if}</td>
+      </tr>
+    {/foreach}
+  </table>
+  <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+  <div class="spacer"></div>
+</div>
\ No newline at end of file