Skip to content
Snippets Groups Projects

Issue #3520000: You have requested a non-existent service "Symfony\Component\Mailer\Transport"

Merged Issue #3520000: You have requested a non-existent service "Symfony\Component\Mailer\Transport"
Files
4
@@ -5,8 +5,11 @@ declare(strict_types=1);
namespace Drupal\mailer_transport\Plugin\TransportUI;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\mailer_transport\Attribute\TransportUI;
use Drupal\mailer_transport\UnifiedTransportFactoryInterface;
use Drupal\symfony_mailer\AutowireTrait;
/**
* Defines the DSN TransportUI plug-in.
@@ -16,10 +19,29 @@ use Drupal\mailer_transport\Attribute\TransportUI;
label: new TranslatableMarkup("DSN"),
description: new TranslatableMarkup("The DSN transport is a generic fallback and should only be used if there is no specific implementation available."),
)]
class DsnTransportUI extends TransportUIBase {
class DsnTransportUI extends TransportUIBase implements ContainerFactoryPluginInterface {
use AutowireTrait;
const DOCS_URL = 'https://symfony.com/doc/current/mailer.html#transport-setup';
/**
* Constructor.
*
* @param \Drupal\mailer_transport\UnifiedTransportFactoryInterface $factory
* The transport factory.
* @param mixed ...$args
* Parent constructor arguments.
*
* @internal
*/
public function __construct(
protected readonly UnifiedTransportFactoryInterface $factory,
...$args,
) {
parent::__construct(...$args);
}
/**
* {@inheritdoc}
*/
@@ -56,7 +78,7 @@ class DsnTransportUI extends TransportUIBase {
}
try {
\Drupal::service('Symfony\Component\Mailer\Transport')->fromString($dsn);
$this->factory->getTransport($dsn);
}
catch (\Exception $e) {
$form_state->setErrorByName('dsn', $this->t('Invalid DSN: @message', ['@message' => $e->getMessage()]));
Loading