Skip to content

Commit

Permalink
Fix notices on mailing components screen, convert to metadata based
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 29, 2018
1 parent 9b574de commit cf0789f
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 144 deletions.
19 changes: 3 additions & 16 deletions CRM/Admin/Form/Preferences/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
'contact_smart_group_display' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'advanced_search_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'user_dashboard_options' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'activity_assignee_notification' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'activity_assignee_notification_ics' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'preserve_activity_tab_filter' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'ajaxPopupsEnabled' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'display_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'sort_name_format' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
);
Expand All @@ -57,31 +60,15 @@ public function preProcess() {
'title' => ts('Editing Contacts'),
'weight' => 3,
),
'activity_assignee_notification' => array(
'html_type' => 'checkbox',
'title' => ts('Notify Activity Assignees'),
'weight' => 5,
),
'activity_assignee_notification_ics' => array(
'html_type' => 'checkbox',
'title' => ts('Include ICal Invite to Activity Assignees'),
'weight' => 6,
),
'contact_ajax_check_similar' => array(
'title' => ts('Check for Similar Contacts'),
'weight' => 8,
'html_type' => NULL,
),

'editor_id' => array(
'html_type' => NULL,
'weight' => 12,
),
'ajaxPopupsEnabled' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Popup Forms'),
'weight' => 13,
),
'do_not_notify_assignees_for' => array(
'html_type' => 'select',
'option_values' => $optionValues,
Expand Down
102 changes: 17 additions & 85 deletions CRM/Admin/Form/Preferences/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,102 +29,34 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2018
* $Id: Display.php 36505 2011-10-03 14:19:56Z lobo $
*
*/

/**
* This class generates form components for the component preferences
*
* This class generates form components for the maling component preferences.
*/
class CRM_Admin_Form_Preferences_Mailing extends CRM_Admin_Form_Preferences {
public function preProcess() {
CRM_Utils_System::setTitle(ts('CiviMail Component Settings'));
$this->_varNames = array(
CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array(
'profile_double_optin' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Double Opt-in for Profile Group(s) field'),
'weight' => 1,
'description' => ts('When CiviMail is enabled, users who "subscribe" to a group from a profile Group(s) checkbox will receive a confirmation email. They must respond (opt-in) before they are added to the group.'),
),
'profile_add_to_group_double_optin' => array(
'html_type' => 'checkbox',
'title' => ts('Enable Double Opt-in for Profiles which use the "Add to Group" setting'),
'weight' => 2,
'description' => ts('When CiviMail is enabled and a profile uses the "Add to Group" setting, users who complete the profile form will receive a confirmation email. They must respond (opt-in) before they are added to the group.'),
),
'track_civimail_replies' => array(
'html_type' => 'checkbox',
'title' => ts('Track replies using VERP in Reply-To header'),
'weight' => 3,
'description' => ts('If checked, mailings will default to tracking replies using VERP-ed Reply-To.'),
),
'civimail_workflow' => array(
'html_type' => 'checkbox',
'title' => ts('Enable workflow support for CiviMail'),
'weight' => 4,
'description' => ts('Drupal-only. Rules module must be enabled (beta feature - use with caution).'),
),
'civimail_multiple_bulk_emails' => array(
'html_type' => 'checkbox',
'title' => ts('Enable multiple bulk email address for a contact.'),
'weight' => 5,
'description' => ts('CiviMail will deliver a copy of the email to each bulk email listed for the contact.'),
),
'civimail_server_wide_lock' => array(
'html_type' => 'checkbox',
'title' => ts('Enable global server wide lock for CiviMail'),
'weight' => 6,
'description' => NULL,
),
'include_message_id' => array(
'html_type' => 'checkbox',
'title' => ts('Enable CiviMail to generate Message-ID header'),
'weight' => 7,
'description' => NULL,
),
'write_activity_record' => array(
'html_type' => 'checkbox',
'title' => ts('Enable CiviMail to create activities on delivery'),
'weight' => 8,
'description' => NULL,
),
'disable_mandatory_tokens_check' => array(
'html_type' => 'checkbox',
'title' => ts('Disable check for mandatory tokens'),
'weight' => 9,
'description' => ts('Don\'t check for presence of mandatory tokens (domain address; unsubscribe/opt-out) before sending mailings. WARNING: Mandatory tokens are a safe-guard which facilitate compliance with the US CAN-SPAM Act. They should only be disabled if your organization adopts other mechanisms for compliance or if your organization is not subject to CAN-SPAM.'),
),
'dedupe_email_default' => array(
'html_type' => 'checkbox',
'title' => ts('CiviMail dedupes e-mail addresses by default'),
'weight' => 10,
'description' => NULL,
),
'hash_mailing_url' => array(
'html_type' => 'checkbox',
'title' => ts('Hashed Mailing URL\'s'),
'weight' => 11,
'description' => ts('If enabled, a randomized hash key will be used to reference the mailing URL in the mailing.viewUrl token, instead of the mailing ID'),
),
'auto_recipient_rebuild' => array(
'html_type' => 'checkbox',
'title' => ts('Enable automatic CiviMail recipient count display'),
'weight' => 12,
'description' => ts('Enable this setting to rebuild recipient list automatically during composing mail. Disable will allow you to rebuild recipient manually.'),
),
),
);

parent::preProcess();
}
protected $_settings = [
'profile_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'profile_add_to_group_double_optin' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'track_civimail_replies' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'civimail_workflow' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'civimail_multiple_bulk_emails' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'civimail_server_wide_lock' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'include_message_id' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'write_activity_record' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'disable_mandatory_tokens_check' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'dedupe_email_default' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'hash_mailing_url' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
'auto_recipient_rebuild' => CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME,
];

public function postProcess() {
// check if mailing tab is enabled, if not prompt user to enable the tab if "write_activity_record" is disabled
$params = $this->controller->exportValues($this->_name);

if (empty($params['write_activity_record'])) {
// @todo use the setting onToggle & add an action rather than have specific form handling.
// see logging setting for eg.
$existingViewOptions = Civi::settings()->get('contact_view_options');

$displayValue = CRM_Core_OptionGroup::getValue('contact_view_options', 'CiviMail', 'name');
Expand Down
18 changes: 17 additions & 1 deletion CRM/Admin/Form/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,16 @@ protected function getSettingsMetaData() {
* @return array
*/
protected function getSettingsToSetByMetadata($params) {
return array_intersect_key($params, $this->_settings);
$setValues = array_intersect_key($params, $this->_settings);
// Checkboxes will be unset rather than empty so we need to add them back in.
// Handle quickform hateability just once, right here right now.
$unsetValues = array_diff_key($this->_settings, $params);
foreach ($unsetValues as $key => $unsetValue) {
if ($this->getQuickFormType($this->getSettingMetadata($key)) === 'CheckBox') {
$setValues[$key] = [$key => 0];
}
}
return $setValues;
}

/**
Expand Down Expand Up @@ -230,6 +239,9 @@ protected function setDefaultsForMetadataDefinedFields() {
if ($this->getQuickFormType($spec) === 'CheckBoxes') {
$this->_defaults[$setting] = array_fill_keys($this->_defaults[$setting], 1);
}
if ($this->getQuickFormType($spec) === 'CheckBox') {
$this->_defaults[$setting] = [$setting => $this->_defaults[$setting]];
}
}
}

Expand All @@ -243,6 +255,10 @@ protected function saveMetadataDefinedSettings($params) {
if ($this->getQuickFormType($this->getSettingMetadata($setting)) === 'CheckBoxes') {
$settings[$setting] = array_keys($settingValue);
}
if ($this->getQuickFormType($this->getSettingMetadata($setting)) === 'CheckBox') {
// This will be an array with one value.
$settings[$setting] = (int) reset($settings[$setting]);
}
}
civicrm_api3('setting', 'create', $settings);
}
Expand Down
12 changes: 5 additions & 7 deletions settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/

/**
Expand Down Expand Up @@ -243,7 +241,7 @@
'group' => 'core',
'name' => 'ajaxPopupsEnabled',
'type' => 'Boolean',
'quick_form_type' => 'YesNo',
'html_type' => 'checkbox',
'default' => 1,
'add' => '4.5',
'title' => ts('Enable Popup Forms'),
Expand All @@ -256,8 +254,8 @@
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'activity_assignee_notification',
'type' => 'String',
'html_type' => 'Text',
'type' => 'Boolean',
'html_type' => 'checkbox',
'default' => '1',
'add' => '4.1',
'title' => ts('Notify Activity Assignees'),
Expand All @@ -270,8 +268,8 @@
'group_name' => 'CiviCRM Preferences',
'group' => 'core',
'name' => 'activity_assignee_notification_ics',
'type' => 'String',
'html_type' => 'Text',
'type' => 'Boolean',
'html_type' => 'checkbox',
'default' => '0',
'add' => '4.3',
'title' => ts('Include ICal Invite to Activity Assignees'),
Expand Down
Loading

0 comments on commit cf0789f

Please sign in to comment.