diff --git a/modules/features/d8_mail/d8_mail.module b/modules/features/d8_mail/d8_mail.module index 06ddd6dd..5f229081 100644 --- a/modules/features/d8_mail/d8_mail.module +++ b/modules/features/d8_mail/d8_mail.module @@ -5,6 +5,7 @@ * Provides a wrapper for the Drupal Symfony Mailer module. */ +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; @@ -35,6 +36,29 @@ function d8_mail_help($route_name, RouteMatchInterface $route_match) { return $output; } +/** + * Implements hook_ENTITY_TYPE_update(). + */ +function d8_mail_mailer_transport_update(EntityInterface $entity) { + /** @var \Drupal\symfony_mailer\MailerTransportInterface $mailer */ + /** @var \Drupal\Core\Plugin\ObjectWithPluginCollectionInterface $mailer */ + $mailer = $entity; + + if ( + $mailer->isDefault() && + !empty($address = $mailer->getPluginCollections()['configuration']['user']) + ) { + /** @var \Drupal\Component\Utility\EmailValidatorInterface $validator */ + $validator = \Drupal::service('email.validator'); + + if ($validator->isValid($address)) { + \Drupal::configFactory()->getEditable('system.site') + ->set('mail', $address) + ->save(); + } + } +} + /** * Implements hook_preprocess_HOOK(). */