Commit b23b1ea7 authored by Adam Shepherd's avatar Adam Shepherd Committed by Adam Shepherd
Browse files

Issue #3315698 by AdamPS: Improve back-compatibility, call hook_mail_alter()

parent 5dc1f5d2
Loading
Loading
Loading
Loading
+0 −34
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Documentation of Symfony Mailer back-compatibility hooks.
 */

/**
 * Alters back-compatibility creation of an email.
 *
 * The parameters supplied are from the old mail manager interface. The altered
 * values will be passed to the email factory.
 *
 * @param array $message
 *   A message array, as described in hook_mail_alter().
 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
 *   (optional) Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
 *
 * @see \Drupal\Core\Mail\MailManagerInterface::mail()
 * @see \Drupal\symfony_mailer\EmailFactory
 */
function hook_mailer_bc_alter(array &$message, ?ConfigEntityInterface $entity) {
}

/**
 * Alters back-compatibility creation of an email from a specific module.
 *
 * @param array $message
 *   A message array, as described in hook_mail_alter().
 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface|null $entity
 *   (optional) Entity. @see \Drupal\symfony_mailer\EmailInterface::getEntity()
 */
function hook_mailer_bc_MODULE_alter(array &$message, ?ConfigEntityInterface $entity) {
}
+2 −2
Original line number Diff line number Diff line
name: Symfony Mailer Back-compatibility
name: Symfony Mailer Override
type: module
description: 'Back-compatibility mapper for Symfony Mailer. Entirely replaces the default mail system, so that all Drupal emails will be sent via Symfony Mailer.'
description: 'Overrides email building for key core and contrib modules, improving features and integration with Symfony Mailer.'
core_version_requirement: ^9.1
package: Mail
dependencies:
+0 −22
Original line number Diff line number Diff line
<?php

/**
 * @file
 * Install, functions for the Symfony Mailer Back-compatibility module.
 */

/**
 * Implements hook_requirements().
 */
function symfony_mailer_bc_requirements($phase) {
  $requirements = [];
  if ($phase === 'install') {
    if (\Drupal::moduleHandler()->moduleExists('mailsystem')) {
      $requirements['symfony_mailer_bc'] = [
        'description' => t('Symfony Mailer Back-compatibility module cannot be installed because the Mail System module is installed and incompatible.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}
+0 −23
Original line number Diff line number Diff line
@@ -6,7 +6,6 @@
 */

use Drupal\Core\Form\FormStateInterface;
use Drupal\symfony_mailer\Annotation\EmailBuilder;

/**
 * Implements hook_theme().
@@ -22,28 +21,6 @@ function symfony_mailer_bc_theme($existing, $type, $theme, $path) {
  return $hooks;
}

/**
 * Implements hook_mailer_builder_info_alter().
 */
function symfony_mailer_bc_mailer_builder_info_alter(array &$email_builders) {
  // Add EmailBuilder definitions for any implementations of hook_mail() that
  // don't already have one, using LegacyEmailBuilder.
  $module_handler = \Drupal::moduleHandler();
  $mail_hooks = $module_handler->getImplementations('mail');
  $missing = array_diff($mail_hooks, array_keys($email_builders));

  foreach ($missing as $type) {
    $params = [
      'id' => $type,
      'label' => $module_handler->getName($type),
      'class' => "Drupal\symfony_mailer_bc\Plugin\EmailBuilder\LegacyEmailBuilder",
      'provider' => $type,
    ];

    $email_builders[$type] = (new EmailBuilder($params))->get();
  }
}

/**
 * Implements hook_module_implements_alter().
 */
+2 −1
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ trait BaseEmailTrait {
   */
  public function setAddress(string $name, $addresses) {
    assert(isset($this->addresses[$name]));
    if ($name == 'To') {
    // See Mailer::doSend() for explanation of __disable_customize__.
    if (($name == 'To') && !$this->getParam('__disable_customize__')) {
      $this->valid(self::PHASE_BUILD);
    }
    $this->addresses[$name] = Address::convert($addresses);
Loading