Loading config/schema/symfony_mailer.schema.yml +8 −0 Changes for config/schema/symfony_mailer.schema.yml: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,14 @@ symfony_mailer.email_adjuster_plugin.email_subject: type: label label: 'Email subject' symfony_mailer.email_adjuster_plugin.email_theme: type: mapping label: 'Theme' mapping: theme: type: label label: 'Email theme' symfony_mailer.email_adjuster_plugin.mailer_default_headers: type: mapping label: 'Default headers' Loading modules/symfony_mailer_bc/config/install/symfony_mailer.mailer_policy._.yml +2 −0 Changes for modules/symfony_mailer_bc/config/install/symfony_mailer.mailer_policy._.yml: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,3 +7,5 @@ configuration: mailer_url_to_absolute: {} mailer_html_to_text: {} mailer_inline_css: {} email_theme: theme: _active_fallback src/Email.php +31 −1 Changes for src/Email.php: 31 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Component\Render\PlainTextOutput; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\symfony_mailer\Processor\EmailProcessorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -30,6 +31,11 @@ class Email implements InternalEmailInterface { */ protected EntityTypeManagerInterface $entityTypeManager; /** * The theme manager. */ protected ThemeManagerInterface $themeManager; protected string $type; protected string $subType; protected string $entity_id; Loading @@ -40,6 +46,7 @@ class Email implements InternalEmailInterface { protected string $langcode; protected array $params = []; protected array $variables = []; protected string $theme = ''; protected array $libraries = []; /** Loading @@ -56,6 +63,8 @@ class Email implements InternalEmailInterface { * The renderer. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. * @param string $type * Type. @see \Drupal\symfony_mailer\BaseEmailInterface::getType() * @param string $sub_type Loading @@ -63,10 +72,11 @@ class Email implements InternalEmailInterface { * @param ?\Drupal\Core\Config\Entity\ConfigEntityInterface $entity * Entity. @see \Drupal\symfony_mailer\BaseEmailInterface::getEntity() */ public function __construct(MailerInterface $mailer, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager, string $type, string $sub_type, ?ConfigEntityInterface $entity) { public function __construct(MailerInterface $mailer, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager, ThemeManagerInterface $theme_manager, string $type, string $sub_type, ?ConfigEntityInterface $entity) { $this->mailer = $mailer; $this->renderer = $renderer; $this->entityTypeManager = $entity_type_manager; $this->themeManager = $theme_manager; $this->type = $type; $this->subType = $sub_type; $this->entity = $entity; Loading Loading @@ -95,6 +105,7 @@ class Email implements InternalEmailInterface { $container->get('symfony_mailer'), $container->get('renderer'), $container->get('entity_type.manager'), $container->get('theme.manager'), $type, $sub_type, $entity Loading Loading @@ -267,6 +278,25 @@ class Email implements InternalEmailInterface { return $this->variables; } /** * {@inheritdoc} */ public function setTheme(string $theme_name) { $this->valid('preBuild'); $this->theme = $theme_name; return $this; } /** * {@inheritdoc} */ public function getTheme() { if (!$this->theme) { $this->theme = $this->themeManager->getActiveTheme()->getName(); } return $this->theme; } /** * {@inheritdoc} */ Loading src/EmailInterface.php +20 −0 Changes for src/EmailInterface.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,26 @@ interface EmailInterface extends BaseEmailInterface { */ public function getSuggestions(string $initial, string $join); /** * Sets the email theme. * * Valid: before building. * * @param string $theme_name * The theme name to use for email. * * @return $this */ public function setTheme(string $theme_name); /** * Gets the email theme name. * * @return string * The email theme name. */ public function getTheme(); /** * Adds an asset library to use as mail CSS. * Loading src/Mailer.php +54 −7 Changes for src/Mailer.php: 54 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Theme\ThemeInitializationInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationManager; use Drupal\Core\Url; Loading Loading @@ -73,6 +75,20 @@ class Mailer implements MailerInterface { */ protected $account; /** * The theme manager. * * @var \Drupal\Core\Theme\ThemeManagerInterface */ protected $themeManager; /** * The theme initialization. * * @var \Drupal\Core\Theme\ThemeInitializationInterface */ protected $themeInitialization; /** * Constructs the Mailer object. * Loading @@ -90,8 +106,12 @@ class Mailer implements MailerInterface { * The logger channel factory. * @param \Drupal\Core\Session\AccountInterface $account * The current user. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. * @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization * The theme initialization. */ public function __construct(EventDispatcherInterface $dispatcher, RendererInterface $renderer, ModuleHandlerInterface $module_handler, LanguageDefault $language_default, LanguageManagerInterface $language_manager, LoggerChannelFactoryInterface $logger_factory, AccountInterface $account) { public function __construct(EventDispatcherInterface $dispatcher, RendererInterface $renderer, ModuleHandlerInterface $module_handler, LanguageDefault $language_default, LanguageManagerInterface $language_manager, LoggerChannelFactoryInterface $logger_factory, AccountInterface $account, ThemeManagerInterface $theme_manager, ThemeInitializationInterface $theme_initialization) { $this->dispatcher = $dispatcher; $this->renderer = $renderer; $this->moduleHandler = $module_handler; Loading @@ -99,6 +119,8 @@ class Mailer implements MailerInterface { $this->languageManager = $language_manager; $this->loggerFactory = $logger_factory; $this->account = $account; $this->themeManager = $theme_manager; $this->themeInitialization = $theme_initialization; } /** Loading Loading @@ -127,15 +149,26 @@ class Mailer implements MailerInterface { * @internal */ public function doSend(InternalEmailInterface $email) { // Call hooks. $this->invokeAll('init', $email); // Call hooks/processors. $email->process('preBuild'); $this->invokeAll('pre_build', $email); $theme_name = $email->getTheme(); $active_theme_name = $this->themeManager->getActiveTheme()->getName(); $must_switch_theme = $theme_name !== $active_theme_name; if ($must_switch_theme) { $this->changeTheme($theme_name); } $langcode = $email->getLangcode(); $currentLangcode = $this->languageManager->getCurrentLanguage()->getId(); $mustSwitch = isset($langcode) && $langcode !== $currentLangcode; $current_langcode = $this->languageManager->getCurrentLanguage()->getId(); $must_switch_language = isset($langcode) && $langcode !== $current_langcode; if ($mustSwitch) { if ($must_switch_language) { $this->changeActiveLanguage($langcode); } Loading Loading @@ -188,8 +221,12 @@ class Mailer implements MailerInterface { $result = FALSE; } if ($mustSwitch) { $this->changeActiveLanguage($currentLangcode); if ($must_switch_language) { $this->changeActiveLanguage($current_langcode); } if ($must_switch_theme) { $this->changeTheme($active_theme_name); } return $result; Loading @@ -201,7 +238,7 @@ class Mailer implements MailerInterface { * @param string $langcode * The langcode. */ protected function changeActiveLanguage($langcode) { protected function changeActiveLanguage(string $langcode) { // Language switching adapted from commerce module. // @see \Drupal\commerce\MailHandler::sendMail if (!$this->languageManager->isMultilingual()) { Loading Loading @@ -232,6 +269,16 @@ class Mailer implements MailerInterface { } } /** * Changes the active theme for email. * * @param string $theme_name * The theme name. */ protected function changeTheme(string $theme_name) { $this->themeManager->setActiveTheme($this->themeInitialization->initTheme($theme_name)); } /** * Invoke hooks. * Loading Loading
config/schema/symfony_mailer.schema.yml +8 −0 Changes for config/schema/symfony_mailer.schema.yml: 8 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,14 @@ symfony_mailer.email_adjuster_plugin.email_subject: type: label label: 'Email subject' symfony_mailer.email_adjuster_plugin.email_theme: type: mapping label: 'Theme' mapping: theme: type: label label: 'Email theme' symfony_mailer.email_adjuster_plugin.mailer_default_headers: type: mapping label: 'Default headers' Loading
modules/symfony_mailer_bc/config/install/symfony_mailer.mailer_policy._.yml +2 −0 Changes for modules/symfony_mailer_bc/config/install/symfony_mailer.mailer_policy._.yml: 2 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -7,3 +7,5 @@ configuration: mailer_url_to_absolute: {} mailer_html_to_text: {} mailer_inline_css: {} email_theme: theme: _active_fallback
src/Email.php +31 −1 Changes for src/Email.php: 31 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ use Drupal\Component\Render\PlainTextOutput; use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Render\RendererInterface; use Drupal\symfony_mailer\Processor\EmailProcessorInterface; use Symfony\Component\DependencyInjection\ContainerInterface; Loading @@ -30,6 +31,11 @@ class Email implements InternalEmailInterface { */ protected EntityTypeManagerInterface $entityTypeManager; /** * The theme manager. */ protected ThemeManagerInterface $themeManager; protected string $type; protected string $subType; protected string $entity_id; Loading @@ -40,6 +46,7 @@ class Email implements InternalEmailInterface { protected string $langcode; protected array $params = []; protected array $variables = []; protected string $theme = ''; protected array $libraries = []; /** Loading @@ -56,6 +63,8 @@ class Email implements InternalEmailInterface { * The renderer. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. * @param string $type * Type. @see \Drupal\symfony_mailer\BaseEmailInterface::getType() * @param string $sub_type Loading @@ -63,10 +72,11 @@ class Email implements InternalEmailInterface { * @param ?\Drupal\Core\Config\Entity\ConfigEntityInterface $entity * Entity. @see \Drupal\symfony_mailer\BaseEmailInterface::getEntity() */ public function __construct(MailerInterface $mailer, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager, string $type, string $sub_type, ?ConfigEntityInterface $entity) { public function __construct(MailerInterface $mailer, RendererInterface $renderer, EntityTypeManagerInterface $entity_type_manager, ThemeManagerInterface $theme_manager, string $type, string $sub_type, ?ConfigEntityInterface $entity) { $this->mailer = $mailer; $this->renderer = $renderer; $this->entityTypeManager = $entity_type_manager; $this->themeManager = $theme_manager; $this->type = $type; $this->subType = $sub_type; $this->entity = $entity; Loading Loading @@ -95,6 +105,7 @@ class Email implements InternalEmailInterface { $container->get('symfony_mailer'), $container->get('renderer'), $container->get('entity_type.manager'), $container->get('theme.manager'), $type, $sub_type, $entity Loading Loading @@ -267,6 +278,25 @@ class Email implements InternalEmailInterface { return $this->variables; } /** * {@inheritdoc} */ public function setTheme(string $theme_name) { $this->valid('preBuild'); $this->theme = $theme_name; return $this; } /** * {@inheritdoc} */ public function getTheme() { if (!$this->theme) { $this->theme = $this->themeManager->getActiveTheme()->getName(); } return $this->theme; } /** * {@inheritdoc} */ Loading
src/EmailInterface.php +20 −0 Changes for src/EmailInterface.php: 20 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -237,6 +237,26 @@ interface EmailInterface extends BaseEmailInterface { */ public function getSuggestions(string $initial, string $join); /** * Sets the email theme. * * Valid: before building. * * @param string $theme_name * The theme name to use for email. * * @return $this */ public function setTheme(string $theme_name); /** * Gets the email theme name. * * @return string * The email theme name. */ public function getTheme(); /** * Adds an asset library to use as mail CSS. * Loading
src/Mailer.php +54 −7 Changes for src/Mailer.php: 54 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,8 @@ use Drupal\Core\Logger\LoggerChannelFactoryInterface; use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RendererInterface; use Drupal\Core\Session\AccountInterface; use Drupal\Core\Theme\ThemeManagerInterface; use Drupal\Core\Theme\ThemeInitializationInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslationManager; use Drupal\Core\Url; Loading Loading @@ -73,6 +75,20 @@ class Mailer implements MailerInterface { */ protected $account; /** * The theme manager. * * @var \Drupal\Core\Theme\ThemeManagerInterface */ protected $themeManager; /** * The theme initialization. * * @var \Drupal\Core\Theme\ThemeInitializationInterface */ protected $themeInitialization; /** * Constructs the Mailer object. * Loading @@ -90,8 +106,12 @@ class Mailer implements MailerInterface { * The logger channel factory. * @param \Drupal\Core\Session\AccountInterface $account * The current user. * @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager * The theme manager. * @param \Drupal\Core\Theme\ThemeInitializationInterface $theme_initialization * The theme initialization. */ public function __construct(EventDispatcherInterface $dispatcher, RendererInterface $renderer, ModuleHandlerInterface $module_handler, LanguageDefault $language_default, LanguageManagerInterface $language_manager, LoggerChannelFactoryInterface $logger_factory, AccountInterface $account) { public function __construct(EventDispatcherInterface $dispatcher, RendererInterface $renderer, ModuleHandlerInterface $module_handler, LanguageDefault $language_default, LanguageManagerInterface $language_manager, LoggerChannelFactoryInterface $logger_factory, AccountInterface $account, ThemeManagerInterface $theme_manager, ThemeInitializationInterface $theme_initialization) { $this->dispatcher = $dispatcher; $this->renderer = $renderer; $this->moduleHandler = $module_handler; Loading @@ -99,6 +119,8 @@ class Mailer implements MailerInterface { $this->languageManager = $language_manager; $this->loggerFactory = $logger_factory; $this->account = $account; $this->themeManager = $theme_manager; $this->themeInitialization = $theme_initialization; } /** Loading Loading @@ -127,15 +149,26 @@ class Mailer implements MailerInterface { * @internal */ public function doSend(InternalEmailInterface $email) { // Call hooks. $this->invokeAll('init', $email); // Call hooks/processors. $email->process('preBuild'); $this->invokeAll('pre_build', $email); $theme_name = $email->getTheme(); $active_theme_name = $this->themeManager->getActiveTheme()->getName(); $must_switch_theme = $theme_name !== $active_theme_name; if ($must_switch_theme) { $this->changeTheme($theme_name); } $langcode = $email->getLangcode(); $currentLangcode = $this->languageManager->getCurrentLanguage()->getId(); $mustSwitch = isset($langcode) && $langcode !== $currentLangcode; $current_langcode = $this->languageManager->getCurrentLanguage()->getId(); $must_switch_language = isset($langcode) && $langcode !== $current_langcode; if ($mustSwitch) { if ($must_switch_language) { $this->changeActiveLanguage($langcode); } Loading Loading @@ -188,8 +221,12 @@ class Mailer implements MailerInterface { $result = FALSE; } if ($mustSwitch) { $this->changeActiveLanguage($currentLangcode); if ($must_switch_language) { $this->changeActiveLanguage($current_langcode); } if ($must_switch_theme) { $this->changeTheme($active_theme_name); } return $result; Loading @@ -201,7 +238,7 @@ class Mailer implements MailerInterface { * @param string $langcode * The langcode. */ protected function changeActiveLanguage($langcode) { protected function changeActiveLanguage(string $langcode) { // Language switching adapted from commerce module. // @see \Drupal\commerce\MailHandler::sendMail if (!$this->languageManager->isMultilingual()) { Loading Loading @@ -232,6 +269,16 @@ class Mailer implements MailerInterface { } } /** * Changes the active theme for email. * * @param string $theme_name * The theme name. */ protected function changeTheme(string $theme_name) { $this->themeManager->setActiveTheme($this->themeInitialization->initTheme($theme_name)); } /** * Invoke hooks. * Loading