diff --git a/admin_pages/messages/Messages_Admin_Page.core.php b/admin_pages/messages/Messages_Admin_Page.core.php index 8c03283c028..04cb7d3de52 100644 --- a/admin_pages/messages/Messages_Admin_Page.core.php +++ b/admin_pages/messages/Messages_Admin_Page.core.php @@ -1428,7 +1428,8 @@ protected function _edit_message_template() // let's get EEH_MSG_Template so we can get template form fields $template_field_structure = EEH_MSG_Template::get_fields( $message_template_group->messenger(), - $message_template_group->message_type() + $message_template_group->message_type(), + $context ); if (! $template_field_structure) { @@ -1484,9 +1485,7 @@ protected function _edit_message_template() . $reference_field . '][content][' . $extra_field . ']'; - $css_class = isset($extra_array['css_class']) - ? $extra_array['css_class'] - : ''; + $css_class = $extra_array['css_class'] ?? ''; $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) && in_array($extra_field, $v_fields, true) @@ -1554,10 +1553,8 @@ protected function _edit_message_template() $template_form_fields[ $field_id ] = $field_setup_array; $template_form_fields[ $field_id ]['name'] = 'MTP_template_fields[' . $template_field . '][content]'; - $message_template = - isset($message_templates[ $context ][ $template_field ]) - ? $message_templates[ $context ][ $template_field ] - : null; + $message_template = $message_templates[ $context ][ $template_field ] + ?? null; $template_form_fields[ $field_id ]['value'] = ! empty($message_templates) && is_array($message_templates[ $context ]) && $message_template instanceof EE_Message_Template @@ -1571,9 +1568,7 @@ protected function _edit_message_template() $template_form_fields[ $field_id ]['db-col'] = 'MTP_content'; - $css_class = isset($field_setup_array['css_class']) - ? $field_setup_array['css_class'] - : ''; + $css_class = $field_setup_array['css_class'] ?? ''; $template_form_fields[ $field_id ]['css_class'] = ! empty($v_fields) && in_array($template_field, $v_fields, true) && isset($validators[ $template_field ]['msg']) diff --git a/caffeinated/EE_Caf_Messages.class.php b/caffeinated/EE_Caf_Messages.class.php index 011710e784c..29ea9a484ce 100644 --- a/caffeinated/EE_Caf_Messages.class.php +++ b/caffeinated/EE_Caf_Messages.class.php @@ -184,7 +184,7 @@ public function email_messenger_template_fields($template_fields, EE_Email_messe 'input' => 'textarea', 'label' => '[QUESTION_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -202,7 +202,7 @@ public function html_messenger_template_fields($template_fields, EE_Html_messeng 'input' => 'textarea', 'label' => '[QUESTION_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -220,7 +220,7 @@ public function pdf_messenger_template_fields($template_fields, EE_Pdf_messenger 'input' => 'textarea', 'label' => '[QUESTION_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', diff --git a/core/helpers/EEH_MSG_Template.helper.php b/core/helpers/EEH_MSG_Template.helper.php index cc8f9c8b7bf..560d7a53d4e 100644 --- a/core/helpers/EEH_MSG_Template.helper.php +++ b/core/helpers/EEH_MSG_Template.helper.php @@ -1226,29 +1226,37 @@ public static function message_type_has_active_templates_for_messenger( /** * get_fields - * This takes a given messenger and message type and returns all the template fields indexed by context (and with field type). + * This takes a given messenger and message type + * and returns all the template fields indexed by context with field type. * * @param string $messenger_name name of EE_messenger * @param string $message_type_name name of EE_message_type + * @param string $current_context current context [optional] * @return array * @throws EE_Error * @throws ReflectionException */ - public static function get_fields($messenger_name, $message_type_name) - { - $template_fields = array(); + public static function get_fields( + string $messenger_name, + string $message_type_name, + string $current_context = '' + ): array { + $template_fields = []; /** @type EE_Message_Resource_Manager $Message_Resource_Manager */ $Message_Resource_Manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); - $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); - $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); + $messenger = $Message_Resource_Manager->valid_messenger($messenger_name); + $message_type = $Message_Resource_Manager->valid_message_type($message_type_name); if (! EEH_MSG_Template::message_type_has_active_templates_for_messenger($messenger, $message_type)) { - return array(); + return []; } $excluded_fields_for_messenger = $message_type->excludedFieldsForMessenger($messenger_name); // okay now let's assemble an array with the messenger template fields added to the message_type contexts. foreach ($message_type->get_contexts() as $context => $details) { + if ($current_context && $current_context !== $context) { + continue; + } foreach ($messenger->get_template_fields() as $field => $value) { if (in_array($field, $excluded_fields_for_messenger, true)) { continue; @@ -1263,7 +1271,7 @@ public static function get_fields($messenger_name, $message_type_name) __FUNCTION__, __LINE__ ); - return array(); + return []; } return $template_fields; } diff --git a/core/libraries/messages/EE_messenger.lib.php b/core/libraries/messages/EE_messenger.lib.php index aa607dc4155..2fff50fb02e 100644 --- a/core/libraries/messages/EE_messenger.lib.php +++ b/core/libraries/messages/EE_messenger.lib.php @@ -652,16 +652,20 @@ class="button button--secondary button--tiny edit-mtpg-button" /** - * get_template_fields + * returns $this->_template_fields, + * filtered first by child class specific filter named something like + * FHEE__EE_Email_messenger__get_template_fields, + * followed by global FHEE__EE_messenger__get_template_fields filter * - * @access public - * @return array $this->_template_fields + * @return array */ - public function get_template_fields() + public function get_template_fields(): array { - $template_fields = apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this); - $template_fields = apply_filters('FHEE__EE_messenger__get_template_fields', $template_fields, $this); - return $template_fields; + return (array) apply_filters( + 'FHEE__EE_messenger__get_template_fields', + apply_filters('FHEE__' . get_class($this) . '__get_template_fields', $this->_template_fields, $this), + $this + ); } diff --git a/core/libraries/messages/messenger/EE_Email_messenger.class.php b/core/libraries/messages/messenger/EE_Email_messenger.class.php index ab03ff7b405..b44798248ef 100644 --- a/core/libraries/messages/messenger/EE_Email_messenger.class.php +++ b/core/libraries/messages/messenger/EE_Email_messenger.class.php @@ -331,7 +331,7 @@ protected function _set_template_fields() 'input' => 'wp_editor', 'label' => '[EVENT_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'rows' => '15', @@ -341,7 +341,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[ATTENDEE_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -352,7 +352,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[TICKET_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -363,7 +363,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[DATETIME_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', diff --git a/core/libraries/messages/messenger/EE_Html_messenger.class.php b/core/libraries/messages/messenger/EE_Html_messenger.class.php index 30a0c6b2205..0e2325fcf4d 100644 --- a/core/libraries/messages/messenger/EE_Html_messenger.class.php +++ b/core/libraries/messages/messenger/EE_Html_messenger.class.php @@ -295,7 +295,7 @@ protected function _set_template_fields() 'input' => 'wp_editor', 'label' => '[EVENT_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'rows' => '15', @@ -305,7 +305,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[TICKET_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -355,7 +355,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[DATETIME_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -366,7 +366,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[ATTENDEE_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -399,7 +399,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[PAYMENT_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', diff --git a/core/libraries/messages/messenger/EE_Pdf_messenger.class.php b/core/libraries/messages/messenger/EE_Pdf_messenger.class.php index 028bc9d3deb..c3bbb86b7a9 100644 --- a/core/libraries/messages/messenger/EE_Pdf_messenger.class.php +++ b/core/libraries/messages/messenger/EE_Pdf_messenger.class.php @@ -173,7 +173,7 @@ protected function _set_template_fields() 'input' => 'wp_editor', 'label' => '[EVENT_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'rows' => '15', @@ -183,7 +183,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[ATTENDEE_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -194,7 +194,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[TICKET_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text', @@ -205,7 +205,7 @@ protected function _set_template_fields() 'input' => 'textarea', 'label' => '[DATETIME_LIST]', 'type' => 'string', - 'required' => true, + 'required' => false, 'validation' => true, 'format' => '%s', 'css_class' => 'large-text',