diff --git a/CRM/Admin/Form/Generic.php b/CRM/Admin/Form/Generic.php index 9d23ce96c9d2..d18e4baacc64 100644 --- a/CRM/Admin/Form/Generic.php +++ b/CRM/Admin/Form/Generic.php @@ -61,18 +61,19 @@ public function setDefaultValues() { $this->setDefaultsForMetadataDefinedFields(); return $this->_defaults; } + /** * Build the form object. */ public function buildQuickForm() { - $filter = array_pop($this->urlPath); + $filter = $this->getSettingPageFilter(); $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. diff --git a/CRM/Admin/Form/SettingTrait.php b/CRM/Admin/Form/SettingTrait.php index bbc755092621..f124ef72e65a 100644 --- a/CRM/Admin/Form/SettingTrait.php +++ b/CRM/Admin/Form/SettingTrait.php @@ -38,6 +38,13 @@ */ trait CRM_Admin_Form_SettingTrait { + /** + * The setting page filter. + * + * @var string + */ + private $_filter; + /** * @var array */ @@ -118,6 +125,44 @@ protected function getSettingMetadataItem($setting, $item) { return CRM_Utils_Array::value($item, $this->getSettingsMetaData()[$setting]); } + /** + * @return string + */ + protected function getSettingPageFilter() { + if (!isset($this->_filter)) { + // Get the last URL component without modifying the urlPath property. + $urlPath = array_values($this->urlPath); + $this->_filter = end($urlPath); + } + return $this->_filter; + } + + /** + * Returns a re-keyed copy of the settings, ordered by weight. + * + * @return array + */ + protected function getSettingsOrderedByWeight() { + $settingMetaData = $this->getSettingsMetaData(); + $filter = $this->getSettingPageFilter(); + + usort($settingMetaData, function ($a, $b) use ($filter) { + // Handle cases in which a comparison is impossible. Such will be considered ties. + if ( + // A comparison can't be made unless both setting weights are declared. + !isset($a['settings_pages'][$filter]['weight'], $b['settings_pages'][$filter]['weight']) + // A pair of settings might actually have the same weight. + || $a['settings_pages'][$filter]['weight'] === $b['settings_pages'][$filter]['weight'] + ) { + return 0; + } + + return $a['settings_pages'][$filter]['weight'] > $b['settings_pages'][$filter]['weight'] ? 1 : -1; + }); + + return $settingMetaData; + } + /** * Add fields in the metadata to the template. */ @@ -207,7 +252,7 @@ protected function addFieldsDefinedInSettingsMetadata() { // setting_description should be deprecated - see Mail.tpl for metadata based tpl. $this->assign('setting_descriptions', $descriptions); $this->assign('settings_fields', $settingMetaData); - $this->assign('fields', $settingMetaData); + $this->assign('fields', $this->getSettingsOrderedByWeight()); } /** diff --git a/CRM/Core/DAO/UFGroup.php b/CRM/Core/DAO/UFGroup.php index af1511333923..27bfa1f2a3fb 100644 --- a/CRM/Core/DAO/UFGroup.php +++ b/CRM/Core/DAO/UFGroup.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/UFGroup.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:e5e629c4f6d56d238b4ac28e822cea8a) + * (GenCodeChecksum:0f78fb49440e1cf5d43fd3db5a43ee7e) */ /** @@ -551,6 +551,9 @@ public static function &fields() { 'entity' => 'UFGroup', 'bao' => 'CRM_Core_BAO_UFGroup', 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], ], 'submit_button_text' => [ 'name' => 'submit_button_text', @@ -564,6 +567,9 @@ public static function &fields() { 'entity' => 'UFGroup', 'bao' => 'CRM_Core_BAO_UFGroup', 'localizable' => 1, + 'html' => [ + 'type' => 'Text', + ], ], 'add_cancel_button' => [ 'name' => 'add_cancel_button', diff --git a/CRM/Report/Form/Activity.php b/CRM/Report/Form/Activity.php index 6be426c8c70b..b85b2b73efb2 100644 --- a/CRM/Report/Form/Activity.php +++ b/CRM/Report/Form/Activity.php @@ -66,9 +66,6 @@ public function __construct() { $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); $caseEnabled = in_array("CiviCase", $config->enableComponents); if ($campaignEnabled) { - $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); - $this->activeCampaigns = $getCampaigns['campaigns']; - asort($this->activeCampaigns); $this->engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); } @@ -345,18 +342,9 @@ public function __construct() { 'operator' => 'like', 'type' => CRM_Utils_Type::T_STRING, ); - if (!empty($this->activeCampaigns)) { - $this->_columns['civicrm_activity']['fields']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'default' => 'false', - ); - $this->_columns['civicrm_activity']['filters']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'type' => CRM_Utils_Type::T_INT, - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->activeCampaigns, - ); - } + // If we have campaigns enabled, add those elements to both the fields, filters. + $this->addCampaignFields('civicrm_activity'); + if (!empty($this->engagementLevels)) { $this->_columns['civicrm_activity']['fields']['engagement_level'] = array( 'title' => ts('Engagement Index'), @@ -1033,7 +1021,7 @@ public function alterDisplay(&$rows) { if (array_key_exists('civicrm_activity_campaign_id', $row)) { if ($value = $row['civicrm_activity_campaign_id']) { - $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->activeCampaigns[$value]; + $rows[$rowNum]['civicrm_activity_campaign_id'] = $this->campaigns[$value]; $entryFound = TRUE; } } diff --git a/CRM/Report/Form/Member/ContributionDetail.php b/CRM/Report/Form/Member/ContributionDetail.php index d5b7bfd5eca3..519c23ef5a50 100644 --- a/CRM/Report/Form/Member/ContributionDetail.php +++ b/CRM/Report/Form/Member/ContributionDetail.php @@ -57,13 +57,6 @@ class CRM_Report_Form_Member_ContributionDetail extends CRM_Report_Form { * Class constructor. */ public function __construct() { - $config = CRM_Core_Config::singleton(); - $campaignEnabled = in_array('CiviCampaign', $config->enableComponents); - if ($campaignEnabled) { - $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); - $this->activeCampaigns = $getCampaigns['campaigns']; - asort($this->activeCampaigns); - } $this->_columns = array( 'civicrm_contact' => array( 'dao' => 'CRM_Contact_DAO_Contact', @@ -376,19 +369,8 @@ public function __construct() { $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; - if ($campaignEnabled && !empty($this->activeCampaigns)) { - $this->_columns['civicrm_contribution']['fields']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'default' => 'false', - ); - $this->_columns['civicrm_contribution']['filters']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->activeCampaigns, - 'type' => CRM_Utils_Type::T_INT, - ); - $this->_columns['civicrm_contribution']['order_bys']['campaign_id'] = array('title' => ts('Campaign')); - } + // If we have campaigns enabled, add those elements to both the fields, filters and sorting + $this->addCampaignFields('civicrm_contribution', FALSE, TRUE); $this->_currencyColumn = 'civicrm_contribution_currency'; parent::__construct(); @@ -780,7 +762,7 @@ public function alterDisplay(&$rows) { // convert campaign_id to campaign title if (array_key_exists('civicrm_contribution_campaign_id', $row)) { if ($value = $row['civicrm_contribution_campaign_id']) { - $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->activeCampaigns[$value]; + $rows[$rowNum]['civicrm_contribution_campaign_id'] = $this->campaigns[$value]; $entryFound = TRUE; } } diff --git a/CRM/Report/Form/Member/Lapse.php b/CRM/Report/Form/Member/Lapse.php index 503288b074b8..4a7f744e7455 100644 --- a/CRM/Report/Form/Member/Lapse.php +++ b/CRM/Report/Form/Member/Lapse.php @@ -58,16 +58,6 @@ class CRM_Report_Form_Member_Lapse extends CRM_Report_Form { * Class constructor. */ public function __construct() { - - // Check if CiviCampaign is a) enabled and b) has active campaigns - $config = CRM_Core_Config::singleton(); - $campaignEnabled = in_array("CiviCampaign", $config->enableComponents); - if ($campaignEnabled) { - $getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, TRUE, FALSE, TRUE); - $this->activeCampaigns = $getCampaigns['campaigns']; - asort($this->activeCampaigns); - } - // UI for selecting columns to appear in the report list // array containing the columns, group_bys and filters build and provided to Form $this->_columns = array( @@ -177,19 +167,8 @@ public function __construct() { ), ); - // If we have a campaign, build out the relevant elements - if ($campaignEnabled && !empty($this->activeCampaigns)) { - $this->_columns['civicrm_membership']['fields']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'default' => 'false', - ); - $this->_columns['civicrm_membership']['filters']['campaign_id'] = array( - 'title' => ts('Campaign'), - 'operatorType' => CRM_Report_Form::OP_MULTISELECT, - 'options' => $this->activeCampaigns, - 'type' => CRM_Utils_Type::T_INT, - ); - } + // If we have campaigns enabled, add those elements to both the fields, filters. + $this->addCampaignFields('civicrm_membership'); $this->_groupFilter = TRUE; $this->_tagFilter = TRUE; @@ -392,7 +371,7 @@ public function alterDisplay(&$rows) { // If using campaigns, convert campaign_id to campaign title if (array_key_exists('civicrm_membership_campaign_id', $row)) { if ($value = $row['civicrm_membership_campaign_id']) { - $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->activeCampaigns[$value]; + $rows[$rowNum]['civicrm_membership_campaign_id'] = $this->campaigns[$value]; } $entryFound = TRUE; } diff --git a/CRM/UF/Form/AdvanceSetting.php b/CRM/UF/Form/AdvanceSetting.php index 4c872910d193..f2945f63dad8 100644 --- a/CRM/UF/Form/AdvanceSetting.php +++ b/CRM/UF/Form/AdvanceSetting.php @@ -38,6 +38,12 @@ class CRM_UF_Form_AdvanceSetting extends CRM_UF_Form_Group { * @param CRM_Core_Form $form */ public static function buildAdvanceSetting(&$form) { + $entityFields = [ + 'cancel_button_text', + 'submit_button_text', + ]; + $form->assign('advancedFieldsConverted', $entityFields); + // should mapping be enabled for this group $form->addElement('checkbox', 'is_map', ts('Enable mapping for this profile?')); @@ -53,8 +59,6 @@ public static function buildAdvanceSetting(&$form) { $form->add('advcheckbox', 'add_cancel_button', ts('Include Cancel Button?')); $form->addElement('text', 'cancel_URL', ts('Cancel Redirect URL'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_URL')); - $form->addElement('text', 'cancel_button_text', ts('Cancel Button Text'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'cancel_button_text')); - $form->addElement('text', 'submit_button_text', ts('Submit Button Text'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFGroup', 'submit_button_text')); // add select for groups $group = array('' => ts('- select -')) + $form->_group; diff --git a/CRM/UF/Form/Group.php b/CRM/UF/Form/Group.php index 475485d293d1..a1c2d80f4735 100644 --- a/CRM/UF/Form/Group.php +++ b/CRM/UF/Form/Group.php @@ -64,7 +64,9 @@ protected function setEntityFields() { 'title' => ['name' => 'title'], 'frontend_title' => ['name' => 'frontend_title'], 'description' => ['name' => 'description', 'help' => ['id' => 'id-description', 'file' => 'CRM/UF/Form/Group.hlp']], - 'uf_group_type' => ['name' => 'uf_group_type', 'not-auto-addable' => TRUE, 'help' => ['id' => 'id-used_for', 'file' => 'CRM/UF/Form/Group.hlp'], 'post_html_text' => ' ' . $this->getOtherModuleString()] + 'uf_group_type' => ['name' => 'uf_group_type', 'not-auto-addable' => TRUE, 'help' => ['id' => 'id-used_for', 'file' => 'CRM/UF/Form/Group.hlp'], 'post_html_text' => ' ' . $this->getOtherModuleString()], + 'cancel_button_text' => ['name' => 'cancel_button_text', 'help' => ['id' => 'id-cancel_button_text', 'file' => 'CRM/UF/Form/Group.hlp'], 'class' => 'cancel_button_section'], + 'submit_button_text' => ['name' => 'submit_button_text', 'help' => ['id' => 'id-submit_button_text', 'file' => 'CRM/UF/Form/Group.hlp'], 'class' => ''], ]; } diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index a31641730a81..19c331f338ed 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -637,7 +637,7 @@ function civicrm_api3_mailing_send_test($params) { $query = CRM_Utils_SQL_Select::from('civicrm_email e') ->select(array('e.id', 'e.contact_id', 'e.email')) ->join('c', 'INNER JOIN civicrm_contact c ON e.contact_id = c.id') - ->where('LOWER(e.email) IN (@emails)', array('@emails' => $testEmailParams['emails'])) + ->where('e.email IN (@emails)', array('@emails' => $testEmailParams['emails'])) ->where('e.on_hold = 0') ->where('c.is_opt_out = 0') ->where('c.do_not_email = 0') diff --git a/templates/CRM/UF/Form/AdvanceSetting.tpl b/templates/CRM/UF/Form/AdvanceSetting.tpl index c2ba1ecf6336..dcef51682491 100644 --- a/templates/CRM/UF/Form/AdvanceSetting.tpl +++ b/templates/CRM/UF/Form/AdvanceSetting.tpl @@ -60,15 +60,12 @@ {$form.cancel_URL.html} {help id='id-cancel_URL' file="CRM/UF/Form/Group.hlp"} - - {$form.cancel_button_text.label} - {$form.cancel_button_text.html} {help id='id-cancel_button_text' file="CRM/UF/Form/Group.hlp"} - - - - {$form.submit_button_text.label} - {$form.submit_button_text.html} {help id='id-submit_button_text' file="CRM/UF/Form/Group.hlp"} - + {foreach from=$advancedFieldsConverted item=fieldName} + {assign var=fieldSpec value=$entityFields.$fieldName} + + {include file="CRM/Core/Form/Field.tpl"} + + {/foreach} diff --git a/templates/CRM/UF/Form/Group.tpl b/templates/CRM/UF/Form/Group.tpl index 698e71e05d03..7e96dd6f640c 100644 --- a/templates/CRM/UF/Form/Group.tpl +++ b/templates/CRM/UF/Form/Group.tpl @@ -47,10 +47,12 @@ {else} {foreach from=$entityFields item=fieldSpec} - {assign var=fieldName value=$fieldSpec.name} - - {include file="CRM/Core/Form/Field.tpl"} - + {if not in_array($fieldSpec.name, $advancedFieldsConverted)} + {assign var=fieldName value=$fieldSpec.name} + + {include file="CRM/Core/Form/Field.tpl"} + + {/if} {/foreach} diff --git a/xml/schema/Core/UFGroup.xml b/xml/schema/Core/UFGroup.xml index 4057e3bd9fdb..cafe160ac631 100644 --- a/xml/schema/Core/UFGroup.xml +++ b/xml/schema/Core/UFGroup.xml @@ -281,6 +281,9 @@ NULLtrue4.7 + + Text + submit_button_text @@ -291,6 +294,9 @@ NULL true 4.7 + + Text + add_cancel_button
{$form.weight.label}{if $config->userSystem->is_drupal EQ '1'} {help id='id-profile_weight' file="CRM/UF/Form/Group.hlp"}{/if}