MailManagerReplacement should override getInstance()

Created on 21 May 2024, about 1 month ago
Updated 22 May 2024, about 1 month ago

Problem/Motivation

Drupal\symfony_mailer\MailManagerReplacement extends the core MailManager implementation but it only overrides the implementation of the mail() function, but not of getInstance() which retrieves the "instance of the mail plugin to use for a given message ID". It does it by reading the system.mail configuration which it not used by Symfony Mailer anymore. And in some cases the configuration might not even exist. This can lead to strange errors.

Therefore, the MailManagerReplacement should override getInstance() and return the correct instance which must be an implementation of Drupal\Core\Mail\MailInterface.

Steps to reproduce

Install and configure Symfony Mailer and Webform (>= 6.2).
Create a webform with an email handler.
Test sending the email, it should be created using the Drupal\symfony_mailer\Plugin\EmailBuilder\LegacyEmailBuilder.
Install the Webprofiler module and enable it's mail toolbat item to track sent emails.

in my case this leads to the following error(s) logged:

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" plugin does not exist. Valid plugin IDs for Drupal\symfony_mailer\MailManagerReplacement are: devel_mail_log, webform_php_mail, symfony_mailer, php_mail, test_mail_collector in Drupal\Core\Plugin\DefaultPluginManager->doGetDefinition() (Zeile 53 in web/core/lib/Drupal/Component/Plugin/Discovery/DiscoveryTrait.php).

Drupal\Core\Entity\EntityStorageException: The "" plugin does not exist. Valid plugin IDs for Drupal\symfony_mailer\MailManagerReplacement are: devel_mail_log, webform_php_mail, symfony_mailer, php_mail, test_mail_collector in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (Zeile 817 in web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

Uncaught PHP Exception Drupal\Core\Entity\EntityStorageException: "The "" plugin does not exist. Valid plugin IDs for Drupal\symfony_mailer\MailManagerReplacement are: devel_mail_log, webform_php_mail, symfony_mailer, php_mail, test_mail_collector" at SqlContentEntityStorage.php line 817

All three errors contain the same error message but don't give any clue where exactly or why it has been caused. I found this cause by extensive debugging only.

πŸ› Bug report
Status

Active

Version

1.4

Component

Code

Created by

πŸ‡¦πŸ‡ΉAustria mvonfrie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024