Commit 8d84c417 authored by Jay Friendly's avatar Jay Friendly Committed by Adam Shepherd
Browse files

Issue #3274069 by AdamPS, Jaypan: Add interfaces

parent 77f7f48e
Loading
Loading
Loading
Loading
+1 −1
Changes for modules/symfony_mailer_bc/src/MailManagerReplacement.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ use Drupal\symfony_mailer\Processor\EmailBuilderManagerInterface;
/**
 * Provides a Symfony Mailer replacement for MailManager.
 */
class MailManagerReplacement extends MailManager {
class MailManagerReplacement extends MailManager implements MailManagerReplacementInterface {

  /**
   * List of headers for conversion to array.
+10 −0
Changes for modules/symfony_mailer_bc/src/MailManagerReplacementInterface.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\symfony_mailer_bc;

use Drupal\Core\Mail\MailManagerInterface;

/**
 * Provides a Symfony Mailer replacement for MailManager.
 */
interface MailManagerReplacementInterface extends MailManagerInterface {}
+4 −4
Changes for src/EmailFactory.php: 4 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@ namespace Drupal\symfony_mailer;

use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\symfony_mailer\Processor\EmailAdjusterManager;
use Drupal\symfony_mailer\Processor\EmailAdjusterManagerInterface;
use Drupal\symfony_mailer\Processor\EmailBuilderManagerInterface;

/**
@@ -22,7 +22,7 @@ class EmailFactory implements EmailFactoryInterface {
  /**
   * The email adjuster manager.
   *
   * @var \Drupal\symfony_mailer\Processor\EmailAdjusterManager
   * @var \Drupal\symfony_mailer\Processor\EmailAdjusterManagerInterface
   */
  protected $emailAdjusterManager;

@@ -38,12 +38,12 @@ class EmailFactory implements EmailFactoryInterface {
   *
   * @param \Drupal\symfony_mailer\Processor\EmailBuilderManagerInterface $email_builder_manager
   *   The email builder manager.
   * @param \Drupal\symfony_mailer\Processor\EmailAdjusterManager $email_adjuster_manager
   * @param \Drupal\symfony_mailer\Processor\EmailAdjusterManagerInterface $email_adjuster_manager
   *   The email adjuster manager.
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   *   The module handler to invoke the alter hook with.
   */
  public function __construct(EmailBuilderManagerInterface $email_builder_manager, EmailAdjusterManager $email_adjuster_manager, ModuleHandlerInterface $module_handler) {
  public function __construct(EmailBuilderManagerInterface $email_builder_manager, EmailAdjusterManagerInterface $email_adjuster_manager, ModuleHandlerInterface $module_handler) {
    $this->emailBuilderManager = $email_builder_manager;
    $this->emailAdjusterManager = $email_adjuster_manager;
    $this->moduleHandler = $module_handler;
+14 −59
Changes for src/Entity/MailerPolicy.php: 14 added lines, 59 removed lines.
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ use Drupal\symfony_mailer\Processor\EmailAdjusterInterface;
 *   }
 * )
 */
class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectionInterface {
class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectionInterface, MailerPolicyInterface {

  use StringTranslationTrait;

@@ -60,7 +60,7 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  /**
   * The email adjuster manager.
   *
   * @var \Drupal\symfony_mailer\Processor\EmailAdjusterManager
   * @var \Drupal\symfony_mailer\Processor\EmailAdjusterManagerInterface
   */
  protected $emailAdjusterManager;

@@ -157,50 +157,35 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Gets the email type this policy applies to.
   *
   * @return string
   *   Email type, or NULL if the policy applies to all types.
   * {@inheritdoc}
   */
  public function getType() {
    return $this->type;
  }

  /**
   * Gets the email sub-type this policy applies to.
   *
   * @return string
   *   Email sub-type, or NULL if the policy applies to all sub-types.
   * {@inheritdoc}
   */
  public function getSubType() {
    return $this->subType;
  }

  /**
   * Gets the config entity this policy applies to.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
   *   Entity, or NULL if the policy applies to all entities.
   * {@inheritdoc}
   */
  public function getEntity() {
    return $this->entity;
  }

  /**
   * Gets a human-readable label for the email type this policy applies to.
   *
   * @return string
   *   Email type label.
   * {@inheritdoc}
   */
  public function getTypeLabel() {
    return $this->builderDefinition['label'];
  }

  /**
   * Gets a human-readable label for the the email sub-type.
   *
   * @return string
   *   Email sub-type label.
   * {@inheritdoc}
   */
  public function getSubTypeLabel() {
    if ($this->subType) {
@@ -213,11 +198,7 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Gets a human-readable label for the config entity this policy applies to.
   *
   * @return string
   *   Email config entity label, or NULL if the builder doesn't support
   *   entities.
   * {@inheritdoc}
   */
  public function getEntityLabel() {
    if (empty($this->builderDefinition['has_entity'])) {
@@ -242,13 +223,7 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Sets the email adjuster configuration for this policy record.
   *
   * @param array $configuration
   *   An associative array of adjuster configuration, keyed by the plug-in ID
   *   with value as an array of configured settings.
   *
   * @return $this
   * {@inheritdoc}
   */
  public function setConfiguration(array $configuration) {
    $this->configuration = $configuration;
@@ -259,21 +234,14 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Gets the email adjuster configuration for this policy record.
   *
   * @return array
   *   An associative array of adjuster configuration, keyed by the plug-in ID
   *   with value as an array of configured settings.
   * {@inheritdoc}
   */
  public function getConfiguration() {
    return $this->configuration;
  }

  /**
   * Returns the ordered collection of configured adjuster plugin instances.
   *
   * @return \Drupal\symfony_mailer\Processor\AdjusterPluginCollection
   *   The adjuster collection.
   * {@inheritdoc}
   */
  public function adjusters() {
    if (!isset($this->pluginCollection)) {
@@ -283,24 +251,14 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Returns all available adjuster plugin definitions.
   *
   * @return array
   *   An associative array of plugin definitions, keyed by the plug-in ID.
   * {@inheritdoc}
   */
  public function adjusterDefinitions() {
    return $this->emailAdjusterManager->getDefinitions();
  }

  /**
   * Gets a short human-readable summary of the configured policy.
   *
   * @param bool $expanded
   *   (Optional) If FALSE return just the labels. If TRUE include a short
   *   summary of each element.
   *
   * @return string
   *   Summary text.
   * {@inheritdoc}
   */
  public function getSummary($expanded = FALSE) {
    $summary = [];
@@ -323,10 +281,7 @@ class MailerPolicy extends ConfigEntityBase implements EntityWithPluginCollectio
  }

  /**
   * Returns the common adjusters for this policy.
   *
   * @return array
   *   An array of common adjuster IDs.
   * {@inheritdoc}
   */
  public function getCommonAdjusters() {
    return $this->builderDefinition ? $this->builderDefinition['common_adjusters'] : [];
+160 −0
Changes for src/Entity/MailerPolicyInterface.php: 160 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\symfony_mailer\Entity;

use Drupal\Core\Config\Entity\ConfigEntityInterface;

/**
 * Defines a Mailer Policy configuration entity class.
 */
interface MailerPolicyInterface extends ConfigEntityInterface {

  /**
   * Gets the email type this policy applies to.
   *
   * @return string
   *   Email type, or NULL if the policy applies to all types.
   */
  public function getType();

  /**
   * Gets the email sub-type this policy applies to.
   *
   * @return string
   *   Email sub-type, or NULL if the policy applies to all sub-types.
   */
  public function getSubType();

  /**
   * Gets the config entity this policy applies to.
   *
   * @return \Drupal\Core\Config\Entity\ConfigEntityInterface
   *   Entity, or NULL if the policy applies to all entities.
   */
  public function getEntity();

  /**
   * Gets a human-readable label for the email type this policy applies to.
   *
   * @return string
   *   Email type label.
   */
  public function getTypeLabel();

  /**
   * Gets a human-readable label for the the email sub-type.
   *
   * @return string
   *   Email sub-type label.
   */
  public function getSubTypeLabel();

  /**
   * Gets a human-readable label for the config entity this policy applies to.
   *
   * @return string
   *   Email config entity label, or NULL if the builder doesn't support
   *   entities.
   */
  public function getEntityLabel();

  /**
   * {@inheritdoc}
   */
  public function label();

  /**
   * Sets the email adjuster configuration for this policy record.
   *
   * @param array $configuration
   *   An associative array of adjuster configuration, keyed by the plug-in ID
   *   with value as an array of configured settings.
   *
   * @return $this
   */
  public function setConfiguration(array $configuration);

  /**
   * Gets the email adjuster configuration for this policy record.
   *
   * @return array
   *   An associative array of adjuster configuration, keyed by the plug-in ID
   *   with value as an array of configured settings.
   */
  public function getConfiguration();

  /**
   * Returns the ordered collection of configured adjuster plugin instances.
   *
   * @return \Drupal\symfony_mailer\Processor\AdjusterPluginCollection
   *   The adjuster collection.
   */
  public function adjusters();

  /**
   * Returns all available adjuster plugin definitions.
   *
   * @return array
   *   An associative array of plugin definitions, keyed by the plug-in ID.
   */
  public function adjusterDefinitions();

  /**
   * Gets a short human-readable summary of the configured policy.
   *
   * @param bool $expanded
   *   (Optional) If FALSE return just the labels. If TRUE include a short
   *   summary of each element.
   *
   * @return string
   *   Summary text.
   */
  public function getSummary($expanded = FALSE);

  /**
   * Returns the common adjusters for this policy.
   *
   * @return array
   *   An array of common adjuster IDs.
   */
  public function getCommonAdjusters();

  /**
   * Helper callback to sort entities.
   */
  public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b);

  /**
   * Loads a Mailer Policy, or creates a new one.
   *
   * @param string $id
   *   The id of the policy to load or create.
   *
   * @return static
   *   The policy object.
   */
  public static function loadOrCreate(string $id);

  /**
   * Loads config for a Mailer Policy including inherited policy.
   *
   * @param string $id
   *   The id of the policy.
   *
   * @return array
   *   The configuration array.
   */
  public static function loadInheritedConfig(string $id);

  /**
   * Imports a Mailer Policy from configuration.
   *
   * @param string $id
   *   The id of the policy to import.
   * @param array $configuration
   *   An associative array of adjuster configuration, keyed by the plug-in ID
   *   with value as an array of configured settings.
   */
  public static function import($id, array $configuration);

}
Loading