Skip to content

Commit

Permalink
Issue #262: Set the E-mail notification sender address based on the u…
Browse files Browse the repository at this point in the history
…sername of the default transporter
  • Loading branch information
lexhouk committed Sep 3, 2023
1 parent 75addb7 commit b328642
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions modules/features/d8_mail/d8_mail.module
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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().
*/
Expand Down

0 comments on commit b328642

Please sign in to comment.