Commit 77f7f48e authored by Henrik Danielsson's avatar Henrik Danielsson Committed by Adam Shepherd
Browse files

Issue #3310956 by TwoD, AdamPS: Add processor interfaces for discoverability

parent a3a939b0
Loading
Loading
Loading
Loading
+5 −0
Changes for src/EmailFactory.php: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -94,6 +94,7 @@ class EmailFactory implements EmailFactoryInterface {
    // Load builders with matching ID.
    foreach ($email->getSuggestions('', '.') as $plugin_id) {
      if ($this->emailBuilderManager->hasDefinition($plugin_id)) {
        /** @var \Drupal\symfony_mailer\Processor\EmailBuilderInterface $builder */
        $builder = $this->emailBuilderManager->createInstance($plugin_id);
        if (empty($created)) {
          $builder->createParams($email, ...$params);
@@ -127,6 +128,10 @@ class EmailFactory implements EmailFactoryInterface {
   *
   * @param \Drupal\symfony_mailer\EmailInterface $email
   *   The email.
   *
   * @see hook_mailer_PHASE()
   * @see hook_mailer_TYPE_PHASE()
   * @see hook_mailer_TYPE__SUBTYPE_PHASE()
   */
  public function invokeHooks(EmailInterface $email) {
    $name = EmailInterface::PHASE_NAMES[$email->getPhase()];
+8 −0
Changes for src/EmailInterface.php: 8 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ interface EmailInterface extends BaseEmailInterface {
   * Must not trigger any rendering because cannot yet rely on the correct
   * language, theme, and account. For example, must not cast a translatable
   * string into a plain string, or replace tokens.
   *
   * @see \Drupal\symfony_mailer\Processor\EmailProcessorInterface::build()
   */
  const PHASE_BUILD = 1;

@@ -35,6 +37,8 @@ interface EmailInterface extends BaseEmailInterface {
   *
   * Not normally needed. Only if there is a rendering step that needs to be
   * done before the main rendering call.
   *
   * @see \Drupal\symfony_mailer\Processor\EmailProcessorInterface::preRender()
   */
  const PHASE_PRE_RENDER = 2;

@@ -42,11 +46,15 @@ interface EmailInterface extends BaseEmailInterface {
   * Post-render phase: adjusting of rendered output.
   *
   * Act on the rendered HTML, or any header.
   *
   * @see \Drupal\symfony_mailer\Processor\EmailProcessorInterface::postRender()
   */
  const PHASE_POST_RENDER = 3;

  /**
   * Post-send phase: no further alterations allowed.
   *
   * @see \Drupal\symfony_mailer\Processor\EmailProcessorInterface::postSend()
   */
  const PHASE_POST_SEND = 4;

+4 −0
Changes for src/Mailer.php: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -161,6 +161,7 @@ class Mailer implements MailerInterface {
   */
  public function doSend(InternalEmailInterface $email) {
    // Process the build phase.
    // @see \Drupal\symfony_mailer\EmailInterface::PHASE_BUILD
    $email->process();

    // Do switching.
@@ -202,12 +203,14 @@ class Mailer implements MailerInterface {

    try {
      // Process the pre-render phase.
      // @see \Drupal\symfony_mailer\EmailInterface::PHASE_PRE_RENDER
      $email->process();

      // Render.
      $email->render();

      // Process the post-render phase.
      // @see \Drupal\symfony_mailer\EmailInterface::PHASE_POST_RENDER
      $email->process();
    }
    finally {
@@ -265,6 +268,7 @@ class Mailer implements MailerInterface {
    }

    // Process the post-send phase.
    // @see \Drupal\symfony_mailer\EmailInterface::PHASE_POST_SEND
    $email->process();

    return $result;
+1 −1
Changes for src/Processor/EmailAdjusterBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use Drupal\Core\Form\FormStateInterface;
/**
 * Defines the base class for EmailAdjuster plug-ins.
 */
class EmailAdjusterBase extends EmailProcessorBase implements EmailAdjusterInterface {
abstract class EmailAdjusterBase extends EmailProcessorBase implements EmailAdjusterInterface {

  /**
   * The default weight for an email adjuster.
+1 −1
Changes for src/Processor/EmailBuilderBase.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ use Drupal\symfony_mailer\EmailInterface;
/**
 * Defines the base class for EmailBuilder plug-ins.
 */
class EmailBuilderBase extends EmailProcessorBase implements EmailBuilderInterface {
abstract class EmailBuilderBase extends EmailProcessorBase implements EmailBuilderInterface {

  /**
   * The default weight for an email builder.
Loading