/**
  * {@inheritdoc}
  */
 public function mail($module, $key, $to, $langcode, $params = array(), $reply = NULL, $send = TRUE)
 {
     // Switch the theme to the configured mail theme.
     $mail_theme = $this->getMailTheme();
     $current_active_theme = $this->themeManager->getActiveTheme();
     if ($mail_theme != $current_active_theme->getName()) {
         $this->themeManager->setActiveTheme($this->themeInitialization->initTheme($mail_theme));
         // The theme registry returns the same registry object no matter which
         // theme is currently active. This works around that by having a duplicate
         // service, that is only called when the mail theme is acive.
         // @todo: This will not work if this can not be called. Remove this once
         //   https://www.drupal.org/node/2640962 is committed.
         if ($this->themeManager instanceof ThemeManager) {
             $this->themeManager->setThemeRegistry($this->mailThemeRegistry);
         }
     }
     try {
         $message = parent::mail($module, $key, $to, $langcode, $params, $reply, $send);
     } finally {
         // Revert the active theme, this is done inside a finally block so it is
         // executed even if an exception is thrown during sending a mail.
         if ($mail_theme != $current_active_theme->getName()) {
             $this->themeManager->setActiveTheme($current_active_theme);
             if ($this->themeManager instanceof ThemeManager) {
                 $this->themeManager->setThemeRegistry($this->defaultThemeRegistry);
             }
         }
     }
     return $message;
 }
Exemple #2
0
 /**
  * Initializes the active theme for a given route match.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The current route match.
  */
 protected function initTheme(RouteMatchInterface $route_match = NULL)
 {
     // Determine the active theme for the theme negotiator service. This includes
     // the default theme as well as really specific ones like the ajax base theme.
     if (!$route_match) {
         $route_match = \Drupal::routeMatch();
     }
     if ($route_match instanceof StackedRouteMatchInterface) {
         $route_match = $route_match->getMasterRouteMatch();
     }
     $theme = $this->themeNegotiator->determineActiveTheme($route_match);
     $this->activeTheme = $this->themeInitialization->initTheme($theme);
 }