From 089360bb15ddc680ca6275d1eb2b5aabaa352a05 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 20 Jul 2017 13:02:15 +1200 Subject: [PATCH] CRM-20923 refactor tpl to be based on metadata not hard-coding Change-Id: Iee2a7aa9fa93c5d20b95f3dbc45ec2f3cf7a216b --- CRM/Admin/Form/Setting.php | 25 ++++++++---- CRM/Admin/Form/Setting/Mail.php | 12 ++---- templates/CRM/Admin/Form/Setting/Mail.tpl | 31 +------------- .../CRM/Admin/Form/Setting/SettingForm.tpl | 40 +++++++++++++++++++ 4 files changed, 62 insertions(+), 46 deletions(-) create mode 100644 templates/CRM/Admin/Form/Setting/SettingForm.tpl diff --git a/CRM/Admin/Form/Setting.php b/CRM/Admin/Form/Setting.php index 671c8fe7ed..103b436803 100644 --- a/CRM/Admin/Form/Setting.php +++ b/CRM/Admin/Form/Setting.php @@ -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; + } + } diff --git a/CRM/Admin/Form/Setting/Mail.php b/CRM/Admin/Form/Setting/Mail.php index 960ce2abae..83679cabe9 100644 --- a/CRM/Admin/Form/Setting/Mail.php +++ b/CRM/Admin/Form/Setting/Mail.php @@ -37,12 +37,12 @@ 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(); } /** diff --git a/templates/CRM/Admin/Form/Setting/Mail.tpl b/templates/CRM/Admin/Form/Setting/Mail.tpl index 964dd095a4..1cbd03fd82 100644 --- a/templates/CRM/Admin/Form/Setting/Mail.tpl +++ b/templates/CRM/Admin/Form/Setting/Mail.tpl @@ -28,33 +28,4 @@
{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}
-
{include file="CRM/common/formButtons.tpl" location="top"}
- - - - - - - - - - - - - - - - - - - -
{$form.mailerBatchLimit.label}{$form.mailerBatchLimit.html}
- {ts}Throttle email delivery by setting the maximum number of emails sent during each CiviMail run (0 = unlimited).{/ts}
{$form.mailThrottleTime.label}{$form.mailThrottleTime.html}
- {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}
{$form.mailerJobSize.label}{$form.mailerJobSize.html}
- {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}
{$form.mailerJobsMax.label}{$form.mailerJobsMax.html}
- {ts}The maximum number of mailer delivery jobs executing simultaneously (0 = allow as many processes to execute as started by cron){/ts}
{$form.verpSeparator.label}{$form.verpSeparator.html}
- {ts}Separator character used when CiviMail generates VERP (variable envelope return path) Mail-From addresses.{/ts}
{$form.replyTo.label}{$form.replyTo.html}
- {ts}Allow CiviMail users to send mailings with a custom Reply-To header.{/ts}
-
{include file="CRM/common/formButtons.tpl" location="bottom"}
-
- +{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 index 0000000000..6cd4465698 --- /dev/null +++ b/templates/CRM/Admin/Form/Setting/SettingForm.tpl @@ -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 | ++--------------------------------------------------------------------+ +*} +{ +
{include file="CRM/common/formButtons.tpl" location="top"}
+ + {foreach from=$settings_fields key="setting_name" item="setting_detail"} + + + + {/foreach} +
{$form.$setting_name.label}{$form.$setting_name.html}
+ {ts}{$setting_detail.description}{/ts}{if $setting_detail.help_text} + {assign var='tplhelp_id' value = $setting_name|cat:'-id'|replace:'_':'-'} + {help id="$tplhelp_id"}{/if}
+
{include file="CRM/common/formButtons.tpl" location="bottom"}
+
+ \ No newline at end of file -- 2.25.1