Loading config/install/forward.settings.yml +4 −0 Changes for config/install/forward.settings.yml: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ forward_link_style: 0 forward_link_noindex: true forward_link_nofollow: false forward_form_instructions: 'Thank you for your interest in spreading the word about <em>[forward:entity-title]</em> on [site:name].' forward_form_allow_plain_text: false forward_form_display_page: false forward_form_display_subject: false forward_form_display_body: false Loading @@ -23,8 +24,11 @@ forward_personal_message_tags: 'p,br,em,strong,cite,code,ul,ol,li,dl,dt,dd' forward_email_logo: '' forward_email_subject: '[forward:sender-name] has forwarded a page to you from [site:name]' forward_email_message: '[forward:sender-name] thought you would like to see this page from the [site:name] web site.' forward_email_footer: '' forward_bypass_access_control: 0 forward_filter_format: '' forward_filter_format_html: '' forward_filter_format_plain_text: '' forward_flood_control_limit: 10 forward_flood_control_error: "You can't send more than @number messages per hour. Please try again later." forward_max_recipients: 1 Loading config/schema/forward.schema.yml +11 −2 Changes for config/schema/forward.schema.yml: 11 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -63,6 +63,9 @@ forward.settings: forward_form_instructions: type: label label: 'Instructions' forward_form_allow_plain_text: type: boolean label: 'Allow plain text' forward_form_display_page: type: boolean label: 'Display page' Loading Loading @@ -96,12 +99,18 @@ forward.settings: forward_email_message: type: label label: 'Email message header' forward_email_footer: type: label label: 'Email message footer' forward_bypass_access_control: type: integer label: 'Bypass access control' forward_filter_format: forward_filter_format_html: type: string label: 'HTML filter format' forward_filter_format_plain_text: type: string label: 'Filter format' label: 'Plain text filter format' forward_flood_control_limit: type: integer label: 'Flood control limit' Loading forward.install +29 −0 Changes for forward.install: 29 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -175,3 +175,32 @@ function forward_update_8001() { ->set('forward_max_recipients_error', "You can't send email to more than @number recipient(s) at a time.") ->save(); } /** * Add the default configuration value for 'forward_form_allow_plain_text'. */ function forward_update_8200() { \Drupal::configFactory()->getEditable('forward.settings') ->set('forward_form_allow_plain_text', FALSE) ->save(TRUE); } /** * Split 'forward_filter_format' setting into HTML vs. plain text filters. */ function forward_update_8201() { $forward_settings = \Drupal::configFactory()->getEditable('forward.settings'); $format = $forward_settings->get('forward_filter_format'); $forward_settings->set('forward_filter_format_html', $format); $forward_settings->set('forward_filter_format_plain_text', ''); $forward_settings->save(TRUE); } /** * Add the default configuration value for 'forward_email_footer'. */ function forward_update_8202() { \Drupal::configFactory()->getEditable('forward.settings') ->set('forward_email_footer', '') ->save(TRUE); } forward.module +22 −6 Changes for forward.module: 22 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -104,17 +104,30 @@ function forward_theme($existing, $type, $theme, $path) { 'forward' => [ 'variables' => [ 'email' => NULL, 'recipient' => NULL, 'header' => NULL, 'footer' => NULL, 'message' => NULL, 'settings' => NULL, 'entity' => NULL, 'content' => NULL, 'view_mode' => NULL, 'email_format' => NULL, ], ], ]; } /** * Implements hook_theme_suggestions_HOOK(). */ function forward_theme_suggestions_forward(array $variables) { $suggestions = []; $suggestions[] = 'forward__' . $variables['email_format']; $suggestions[] = 'forward__' . $variables['email_format'] . '__' . $variables['view_mode']; return $suggestions; } /** * Implements template_preprocess_module(). */ Loading Loading @@ -185,7 +198,7 @@ function forward_form_alter(&$form, FormStateInterface $form_state, $form_id) { '#type' => 'checkbox', '#title' => t('Show forwarding link/form'), '#return_value' => 1, '#default_value' => $settings['forward_node_' . $node_type], '#default_value' => isset($settings['forward_node_' . $node_type]) ? $settings['forward_node_' . $node_type] : 0, '#description' => t('Further configuration is available on the <a href="@settings-url">Forward settings page</a>.', ['@settings-url' => $url->toString()]), ]; $form['actions']['submit']['#submit'][] = 'forward_node_type_edit_form_submit'; Loading @@ -196,11 +209,14 @@ function forward_form_alter(&$form, FormStateInterface $form_state, $form_id) { * Implements submit handler for hook_form_alter(). */ function forward_node_type_edit_form_submit($form, FormStateInterface $form_state) { \Drupal::getContainer() ->get('config.factory') ->getEditable('forward.settings') ->set('forward_node_' . $form['#node_type'], $form_state->getValue('forward_node')) ->save(); $value = $form_state->getValue('forward_node'); $settings = \Drupal::getContainer()->get('config.factory')->getEditable('forward.settings'); if (!empty($value)) { $settings->set('forward_node_' . $form['#node_type'], $value)->save(); } else { $settings->clear('forward_node_' . $form['#node_type']); } } /** Loading src/Form/ForwardForm.php +35 −11 Changes for src/Form/ForwardForm.php: 35 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -433,6 +433,18 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { '#required' => ($settings['forward_personal_message'] == 2), ]; } if ($settings['forward_form_allow_plain_text']) { $form['message']['email_format'] = [ '#type' => 'select', '#title' => $this->t('E-mail format'), '#default_value' => 'html', '#options' => [ 'html' => $this->t('HTML'), 'plain_text' => $this->t('Plain text'), ], '#required' => TRUE, ]; } // Submit button. if ($settings['forward_interface_type'] == 'form') { Loading Loading @@ -503,6 +515,12 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $entity = $form_state->get('#entity'); $recipients = $this->splitEmailAddresses($form_state->getValue('recipient')); // Decide if we're sending HTML or plain text. Default to HTML. $email_format = 'html'; if ($form_state->getValue('email_format') == 'plain_text') { $email_format = 'plain_text'; } // Use the entity language to drive translation. $langcode = $entity->language()->getId(); Loading @@ -524,19 +542,13 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $elements = []; if ($entity->access('view')) { $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId()); $view_mode = 'forward'; if ($this->isValidDisplay($entity, $view_mode)) { $elements = $view_builder->view($entity, $view_mode, $langcode); } if (empty($elements)) { $view_mode = 'teaser'; foreach (['forward', 'teaser', 'full'] as $view_mode) { if ($this->isValidDisplay($entity, $view_mode)) { $elements = $view_builder->view($entity, $view_mode, $langcode); } if (!empty($elements)) { break; } if (empty($elements)) { $view_mode = 'full'; $elements = $view_builder->view($entity, $view_mode, $langcode); } } // Prevent recursion. Loading @@ -546,6 +558,9 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { // Build the header line. $header = ['#markup' => $this->tokenService->replace($this->settings['forward_email_message'], $token, ['langcode' => $langcode])]; // Build the footer line. $footer = ['#markup' => $this->tokenService->replace($this->settings['forward_email_footer'], $token, ['langcode' => $langcode])]; // Build the personal message if present. $message = ''; if ($this->settings['forward_personal_message']) { Loading @@ -566,12 +581,15 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $render_array = [ '#theme' => 'forward', '#email' => $form_state->getValue('email'), '#recipient' => $recipient, '#header' => $header, '#message' => $message, '#settings' => $this->settings, '#entity' => $entity, '#content' => $content, '#view_mode' => $view_mode, '#email_format' => $email_format, '#footer' => $footer, ]; // Allow modules to alter the render array for the message. Loading @@ -581,11 +599,12 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $params['body'] = $this->renderer->render($render_array); // Apply filters such as Pathologic for link correction. if ($this->settings['forward_filter_format']) { $format_setting = "forward_filter_format_$email_format"; if ($this->settings[$format_setting]) { // This filter was setup by the Forward administrator for this purpose only, // whose permission to run the filter was checked at that time. // Therefore, no need to check filter access again here. $params['body'] = check_markup($params['body'], $this->settings['forward_filter_format'], $langcode); $params['body'] = check_markup($params['body'], $this->settings[$format_setting], $langcode); } // Allow modules to alter the final message body. Loading Loading @@ -614,6 +633,11 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { } $params['headers']['Reply-To'] = trim(Unicode::mimeHeaderEncode($form_state->getValue('name')) . ' <' . $form_state->getValue('email') . '>'); // Handle plain text vs. HTML setting. if ($email_format == 'plain_text') { $params['plain_text'] = TRUE; } // Prepare for Event dispatch. $account = $this->entityTypeManager->getStorage('user') ->load($this->currentUser()->id()); Loading Loading
config/install/forward.settings.yml +4 −0 Changes for config/install/forward.settings.yml: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ forward_link_style: 0 forward_link_noindex: true forward_link_nofollow: false forward_form_instructions: 'Thank you for your interest in spreading the word about <em>[forward:entity-title]</em> on [site:name].' forward_form_allow_plain_text: false forward_form_display_page: false forward_form_display_subject: false forward_form_display_body: false Loading @@ -23,8 +24,11 @@ forward_personal_message_tags: 'p,br,em,strong,cite,code,ul,ol,li,dl,dt,dd' forward_email_logo: '' forward_email_subject: '[forward:sender-name] has forwarded a page to you from [site:name]' forward_email_message: '[forward:sender-name] thought you would like to see this page from the [site:name] web site.' forward_email_footer: '' forward_bypass_access_control: 0 forward_filter_format: '' forward_filter_format_html: '' forward_filter_format_plain_text: '' forward_flood_control_limit: 10 forward_flood_control_error: "You can't send more than @number messages per hour. Please try again later." forward_max_recipients: 1 Loading
config/schema/forward.schema.yml +11 −2 Changes for config/schema/forward.schema.yml: 11 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -63,6 +63,9 @@ forward.settings: forward_form_instructions: type: label label: 'Instructions' forward_form_allow_plain_text: type: boolean label: 'Allow plain text' forward_form_display_page: type: boolean label: 'Display page' Loading Loading @@ -96,12 +99,18 @@ forward.settings: forward_email_message: type: label label: 'Email message header' forward_email_footer: type: label label: 'Email message footer' forward_bypass_access_control: type: integer label: 'Bypass access control' forward_filter_format: forward_filter_format_html: type: string label: 'HTML filter format' forward_filter_format_plain_text: type: string label: 'Filter format' label: 'Plain text filter format' forward_flood_control_limit: type: integer label: 'Flood control limit' Loading
forward.install +29 −0 Changes for forward.install: 29 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -175,3 +175,32 @@ function forward_update_8001() { ->set('forward_max_recipients_error', "You can't send email to more than @number recipient(s) at a time.") ->save(); } /** * Add the default configuration value for 'forward_form_allow_plain_text'. */ function forward_update_8200() { \Drupal::configFactory()->getEditable('forward.settings') ->set('forward_form_allow_plain_text', FALSE) ->save(TRUE); } /** * Split 'forward_filter_format' setting into HTML vs. plain text filters. */ function forward_update_8201() { $forward_settings = \Drupal::configFactory()->getEditable('forward.settings'); $format = $forward_settings->get('forward_filter_format'); $forward_settings->set('forward_filter_format_html', $format); $forward_settings->set('forward_filter_format_plain_text', ''); $forward_settings->save(TRUE); } /** * Add the default configuration value for 'forward_email_footer'. */ function forward_update_8202() { \Drupal::configFactory()->getEditable('forward.settings') ->set('forward_email_footer', '') ->save(TRUE); }
forward.module +22 −6 Changes for forward.module: 22 added lines, 6 removed lines. Original line number Diff line number Diff line Loading @@ -104,17 +104,30 @@ function forward_theme($existing, $type, $theme, $path) { 'forward' => [ 'variables' => [ 'email' => NULL, 'recipient' => NULL, 'header' => NULL, 'footer' => NULL, 'message' => NULL, 'settings' => NULL, 'entity' => NULL, 'content' => NULL, 'view_mode' => NULL, 'email_format' => NULL, ], ], ]; } /** * Implements hook_theme_suggestions_HOOK(). */ function forward_theme_suggestions_forward(array $variables) { $suggestions = []; $suggestions[] = 'forward__' . $variables['email_format']; $suggestions[] = 'forward__' . $variables['email_format'] . '__' . $variables['view_mode']; return $suggestions; } /** * Implements template_preprocess_module(). */ Loading Loading @@ -185,7 +198,7 @@ function forward_form_alter(&$form, FormStateInterface $form_state, $form_id) { '#type' => 'checkbox', '#title' => t('Show forwarding link/form'), '#return_value' => 1, '#default_value' => $settings['forward_node_' . $node_type], '#default_value' => isset($settings['forward_node_' . $node_type]) ? $settings['forward_node_' . $node_type] : 0, '#description' => t('Further configuration is available on the <a href="@settings-url">Forward settings page</a>.', ['@settings-url' => $url->toString()]), ]; $form['actions']['submit']['#submit'][] = 'forward_node_type_edit_form_submit'; Loading @@ -196,11 +209,14 @@ function forward_form_alter(&$form, FormStateInterface $form_state, $form_id) { * Implements submit handler for hook_form_alter(). */ function forward_node_type_edit_form_submit($form, FormStateInterface $form_state) { \Drupal::getContainer() ->get('config.factory') ->getEditable('forward.settings') ->set('forward_node_' . $form['#node_type'], $form_state->getValue('forward_node')) ->save(); $value = $form_state->getValue('forward_node'); $settings = \Drupal::getContainer()->get('config.factory')->getEditable('forward.settings'); if (!empty($value)) { $settings->set('forward_node_' . $form['#node_type'], $value)->save(); } else { $settings->clear('forward_node_' . $form['#node_type']); } } /** Loading
src/Form/ForwardForm.php +35 −11 Changes for src/Form/ForwardForm.php: 35 added lines, 11 removed lines. Original line number Diff line number Diff line Loading @@ -433,6 +433,18 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { '#required' => ($settings['forward_personal_message'] == 2), ]; } if ($settings['forward_form_allow_plain_text']) { $form['message']['email_format'] = [ '#type' => 'select', '#title' => $this->t('E-mail format'), '#default_value' => 'html', '#options' => [ 'html' => $this->t('HTML'), 'plain_text' => $this->t('Plain text'), ], '#required' => TRUE, ]; } // Submit button. if ($settings['forward_interface_type'] == 'form') { Loading Loading @@ -503,6 +515,12 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $entity = $form_state->get('#entity'); $recipients = $this->splitEmailAddresses($form_state->getValue('recipient')); // Decide if we're sending HTML or plain text. Default to HTML. $email_format = 'html'; if ($form_state->getValue('email_format') == 'plain_text') { $email_format = 'plain_text'; } // Use the entity language to drive translation. $langcode = $entity->language()->getId(); Loading @@ -524,19 +542,13 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $elements = []; if ($entity->access('view')) { $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId()); $view_mode = 'forward'; if ($this->isValidDisplay($entity, $view_mode)) { $elements = $view_builder->view($entity, $view_mode, $langcode); } if (empty($elements)) { $view_mode = 'teaser'; foreach (['forward', 'teaser', 'full'] as $view_mode) { if ($this->isValidDisplay($entity, $view_mode)) { $elements = $view_builder->view($entity, $view_mode, $langcode); } if (!empty($elements)) { break; } if (empty($elements)) { $view_mode = 'full'; $elements = $view_builder->view($entity, $view_mode, $langcode); } } // Prevent recursion. Loading @@ -546,6 +558,9 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { // Build the header line. $header = ['#markup' => $this->tokenService->replace($this->settings['forward_email_message'], $token, ['langcode' => $langcode])]; // Build the footer line. $footer = ['#markup' => $this->tokenService->replace($this->settings['forward_email_footer'], $token, ['langcode' => $langcode])]; // Build the personal message if present. $message = ''; if ($this->settings['forward_personal_message']) { Loading @@ -566,12 +581,15 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $render_array = [ '#theme' => 'forward', '#email' => $form_state->getValue('email'), '#recipient' => $recipient, '#header' => $header, '#message' => $message, '#settings' => $this->settings, '#entity' => $entity, '#content' => $content, '#view_mode' => $view_mode, '#email_format' => $email_format, '#footer' => $footer, ]; // Allow modules to alter the render array for the message. Loading @@ -581,11 +599,12 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { $params['body'] = $this->renderer->render($render_array); // Apply filters such as Pathologic for link correction. if ($this->settings['forward_filter_format']) { $format_setting = "forward_filter_format_$email_format"; if ($this->settings[$format_setting]) { // This filter was setup by the Forward administrator for this purpose only, // whose permission to run the filter was checked at that time. // Therefore, no need to check filter access again here. $params['body'] = check_markup($params['body'], $this->settings['forward_filter_format'], $langcode); $params['body'] = check_markup($params['body'], $this->settings[$format_setting], $langcode); } // Allow modules to alter the final message body. Loading Loading @@ -614,6 +633,11 @@ class ForwardForm extends FormBase implements BaseFormIdInterface { } $params['headers']['Reply-To'] = trim(Unicode::mimeHeaderEncode($form_state->getValue('name')) . ' <' . $form_state->getValue('email') . '>'); // Handle plain text vs. HTML setting. if ($email_format == 'plain_text') { $params['plain_text'] = TRUE; } // Prepare for Event dispatch. $account = $this->entityTypeManager->getStorage('user') ->load($this->currentUser()->id()); Loading