Skip to content
Snippets Groups Projects
Verified Commit a2c8988d authored by Dave Long's avatar Dave Long
Browse files

Issue #3420977 by larowlan, smustgrave, Berdir, mstrelan: Convert Mail plugin...

Issue #3420977 by larowlan, smustgrave, Berdir, mstrelan: Convert Mail plugin discovery to attributes
parent 4cbc8e20
No related branches found
No related tags found
24 merge requests!8528Issue #3456871 by Tim Bozeman: Support NULL services,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3133core/modules/system/css/components/hidden.module.css,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!877Issue #2708101: Default value for link text is not saved,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493
Pipeline #95331 passed
Pipeline: drupal

#95332

    <?php
    declare(strict_types=1);
    namespace Drupal\Core\Mail\Attribute;
    use Drupal\Component\Plugin\Attribute\Plugin;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a Mail attribute for plugin discovery.
    *
    * Plugin Namespace: Plugin\Mail
    *
    * For a working example, see \Drupal\Core\Mail\Plugin\Mail\PhpMail
    *
    * @see \Drupal\Core\Mail\MailInterface
    * @see \Drupal\Core\Mail\MailManager
    * @see plugin_api
    */
    #[\Attribute(\Attribute::TARGET_CLASS)]
    class Mail extends Plugin {
    /**
    * Constructs a Mail attribute.
    *
    * @param string $id
    * The plugin ID.
    * @param \Drupal\Core\StringTranslation\TranslatableMarkup $label
    * The label of the plugin.
    * @param \Drupal\Core\StringTranslation\TranslatableMarkup|null $description
    * (optional) A description of the plugin.
    * @param string|null $deriver
    * (optional) The deriver class.
    */
    public function __construct(
    public readonly string $id,
    public readonly TranslatableMarkup $label,
    public readonly ?TranslatableMarkup $description = NULL,
    public readonly ?string $deriver = NULL,
    ) {}
    }
    ......@@ -6,6 +6,7 @@
    use Drupal\Component\Render\PlainTextOutput;
    use Drupal\Component\Utility\Html;
    use Drupal\Core\Logger\LoggerChannelFactoryInterface;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Messenger\MessengerTrait;
    use Drupal\Core\Plugin\DefaultPluginManager;
    use Drupal\Core\Cache\CacheBackendInterface;
    ......@@ -79,7 +80,7 @@ class MailManager extends DefaultPluginManager implements MailManagerInterface {
    * The renderer.
    */
    public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, LoggerChannelFactoryInterface $logger_factory, TranslationInterface $string_translation, RendererInterface $renderer) {
    parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Mail\MailInterface', 'Drupal\Core\Annotation\Mail');
    parent::__construct('Plugin/Mail', $namespaces, $module_handler, 'Drupal\Core\Mail\MailInterface', Mail::class, 'Drupal\Core\Annotation\Mail');
    $this->alterInfo('mail_backend_info');
    $this->setCacheBackend($cache_backend, 'mail_backend_plugins');
    $this->configFactory = $config_factory;
    ......
    ......@@ -2,9 +2,11 @@
    namespace Drupal\Core\Mail\Plugin\Mail;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Mail\MailFormatHelper;
    use Drupal\Core\Mail\MailInterface;
    use Drupal\Core\Site\Settings;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Symfony\Component\Mime\Header\Headers;
    use Symfony\Component\Mime\Header\UnstructuredHeader;
    ......@@ -12,13 +14,12 @@
    /**
    * Defines the default Drupal mail backend, using PHP's native mail() function.
    *
    * @Mail(
    * id = "php_mail",
    * label = @Translation("Default PHP mailer"),
    * description = @Translation("Sends the message as plain text, using PHP's native mail() function.")
    * )
    */
    #[Mail(
    id: 'php_mail',
    label: new TranslatableMarkup('Default PHP Mailer'),
    description: new TranslatableMarkup("Sends the message as plain text, using PHP's native mail() function."),
    )]
    class PhpMail implements MailInterface {
    /**
    ......
    ......@@ -3,9 +3,11 @@
    namespace Drupal\Core\Mail\Plugin\Mail;
    use Drupal\Component\Render\MarkupInterface;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Mail\MailFormatHelper;
    use Drupal\Core\Mail\MailInterface;
    use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    use Drupal\Core\Utility\Error;
    use Psr\Log\LoggerInterface;
    use Symfony\Component\DependencyInjection\ContainerInterface;
    ......@@ -48,13 +50,12 @@
    *
    * @see https://symfony.com/doc/current/mailer.html#using-built-in-transports
    *
    * @Mail(
    * id = "symfony_mailer",
    * label = @Translation("Symfony mailer (Experimental)"),
    * )
    *
    * @internal
    */
    #[Mail(
    id: 'symfony_mailer',
    label: new TranslatableMarkup('Symfony mailer (Experimental)'),
    )]
    class SymfonyMailer implements MailInterface, ContainerFactoryPluginInterface {
    /**
    ......
    ......@@ -2,19 +2,20 @@
    namespace Drupal\Core\Mail\Plugin\Mail;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Mail\MailInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a mail backend that captures sent messages in the state system.
    *
    * This class is for running tests or for development.
    *
    * @Mail(
    * id = "test_mail_collector",
    * label = @Translation("Mail collector"),
    * description = @Translation("Does not send the message, but stores it in Drupal within the state system. Used for testing.")
    * )
    */
    #[Mail(
    id: 'test_mail_collector',
    label: new TranslatableMarkup('Mail collector'),
    description: new TranslatableMarkup('Does not send the message, but stores it in Drupal within the state system. Used for testing.'),
    )]
    class TestMailCollector extends PhpMail implements MailInterface {
    /**
    ......
    ......@@ -2,21 +2,22 @@
    namespace Drupal\mail_html_test\Plugin\Mail;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Mail\MailFormatHelper;
    use Drupal\Core\Mail\Plugin\Mail\TestMailCollector;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a mail backend that captures sent HTML messages in the state system.
    *
    * This class is for running tests or for development and does not convert HTML
    * to plaintext.
    *
    * @Mail(
    * id = "test_html_mail_collector",
    * label = @Translation("HTML mail collector"),
    * description = @Translation("Does not send the message, but stores its HTML in Drupal within the state system. Used for testing.")
    * )
    */
    #[Mail(
    id: 'test_html_mail_collector',
    label: new TranslatableMarkup('HTML mail collector'),
    description: new TranslatableMarkup('Does not send the message, but stores its HTML in Drupal within the state system. Used for testing.'),
    )]
    class TestHtmlMailCollector extends TestMailCollector {
    /**
    ......
    ......@@ -2,8 +2,10 @@
    namespace Drupal\system_mail_failure_test\Plugin\Mail;
    use Drupal\Core\Mail\Attribute\Mail;
    use Drupal\Core\Mail\Plugin\Mail\PhpMail;
    use Drupal\Core\Mail\MailInterface;
    use Drupal\Core\StringTranslation\TranslatableMarkup;
    /**
    * Defines a mail sending implementation that always fails.
    ......@@ -13,13 +15,12 @@
    * @code
    * \Drupal::configFactory()->getEditable('system.mail')->set('interface.default', 'test_php_mail_failure')->save();
    * @endcode
    *
    * @Mail(
    * id = "test_php_mail_failure",
    * label = @Translation("Malfunctioning mail backend"),
    * description = @Translation("An intentionally broken mail backend, used for tests.")
    * )
    */
    #[Mail(
    id: 'test_php_mail_failure',
    label: new TranslatableMarkup('Malfunctioning mail backend'),
    description: new TranslatableMarkup('An intentionally broken mail backend, used for tests.'),
    )]
    class TestPhpMailFailure extends PhpMail implements MailInterface {
    /**
    ......
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment