Skip to content
Snippets Groups Projects
Commit 7b70c6fd authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3233579 by AdamPS: Upgrade path from SwiftMailer

parent 23b6c257
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,7 @@ class MailerTransport extends ConfigEntityBase implements MailerTransportInterfa
*/
public function setPluginId($plugin) {
$this->plugin = $plugin;
return $this;
}
/**
......@@ -132,6 +133,7 @@ class MailerTransport extends ConfigEntityBase implements MailerTransportInterfa
*/
public function setAsDefault() {
\Drupal::service('config.factory')->getEditable('symfony_mailer.settings')->set('default_transport', $this->id())->save();
return $this;
}
/**
......
......@@ -59,6 +59,8 @@ interface MailerTransportInterface extends ConfigEntityInterface {
*
* @param string $plugin_id
* The transport plugin ID.
*
* @return $this
*/
public function setPluginId($plugin_id);
......@@ -72,6 +74,8 @@ interface MailerTransportInterface extends ConfigEntityInterface {
/**
* Sets this as the default transport.
*
* @return $this
*/
public function setAsDefault();
......
<?php
namespace Drupal\symfony_mailer\Plugin\EmailBuilder;
use Drupal\symfony_mailer\Entity\MailerTransport;
use Drupal\symfony_mailer\MailerHelperTrait;
use Drupal\symfony_mailer\Processor\EmailProcessorBase;
use Drupal\symfony_mailer\Processor\MailerPolicyImportInterface;
/**
* Defines the Email Builder plug-in for swiftmailer module.
*
* Dummy class for config import only.
*
* @EmailBuilder(
* id = "swiftmailer",
* migrate = @Translation("Swiftmailer transport settings"),
* )
*/
class SwiftmailerEmailBuilder extends EmailProcessorBase implements MailerPolicyImportInterface {
use MailerHelperTrait;
/**
* {@inheritdoc}
*/
public function import() {
$settings = $this->helper()->config()->get('swiftmailer.transport')->get();
if ($settings['transport'] == SWIFTMAILER_TRANSPORT_SMTP) {
$config = [
'user' => $settings['smtp_credentials']['swiftmailer']['username'],
'pass' => $settings['smtp_credentials']['swiftmailer']['password'],
'host' => $settings['smtp_host'],
'port' => $settings['smtp_port'],
];
$transport = MailerTransport::load('swiftmailer') ?? MailerTransport::create(['id' => 'swiftmailer']);
$transport->setPluginId('smtp')
->set('label', 'Imported from swiftmailer')
->set('configuration', $config)
->setAsDefault()
->save();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment