Skip to content

Commit

Permalink
Merge pull request #10704 from eileenmcnaughton/admin_form
Browse files Browse the repository at this point in the history
CRM-20923 refactor tpl to be based on metadata not hard-coding
  • Loading branch information
monishdeb authored Jul 21, 2017
2 parents 66ff7bd + ded0c21 commit fabcf30
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 47 deletions.
25 changes: 18 additions & 7 deletions CRM/Admin/Form/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ public function setDefaultValues() {
* 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',
Expand All @@ -96,9 +93,8 @@ public function buildQuickForm() {
);

$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(
Expand Down Expand Up @@ -150,7 +146,9 @@ public function buildQuickForm() {

}
}
// setting_description should be deprecated - see Mail.tpl for metadata based tpl.
$this->assign('setting_descriptions', $descriptions);
$this->assign('settings_fields', $settingMetaData);
}

/**
Expand Down Expand Up @@ -291,4 +289,17 @@ public static function getAutocompleteContactSearch() {
) + $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;
}

}
12 changes: 3 additions & 9 deletions CRM/Admin/Form/Setting/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,22 @@
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,
);

/**
* Build the form object.
*/
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();
}

/**
Expand Down
34 changes: 3 additions & 31 deletions templates/CRM/Admin/Form/Setting/Mail.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,8 @@
*}
{capture assign=docLink}{docURL page="CiviMail Mailer Settings" text="CiviMail Mailer Settings and Optimization" resource="wiki"}{/capture}
<div class="crm-block crm-form-block crm-mail-form-block">
<div class="help">
<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'}
</div>
42 changes: 42 additions & 0 deletions templates/CRM/Admin/Form/Setting/SettingForm.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{*
+--------------------------------------------------------------------+
| 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>

0 comments on commit fabcf30

Please sign in to comment.