Commit 2a0ee195 authored by Adam Shepherd's avatar Adam Shepherd
Browse files

Issue #3263679 by AdamPS: Theme policy option "Active with fallback" is confusing/wrong

parent a7b0e6bc
Loading
Loading
Loading
Loading
+5 −18
Original line number Diff line number Diff line
@@ -9,7 +9,6 @@ use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Theme\ThemeManagerInterface;
use Drupal\Core\Extension\ThemeHandlerInterface;
use Drupal\Core\Asset\LibraryDiscoveryInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
@@ -46,14 +45,6 @@ class ThemeEmailAdjuster extends EmailAdjusterBase implements ContainerFactoryPl
   */
  protected $themeHandler;

  /**
   * The library discovery service.
   *
   * @var \Drupal\Core\Asset\LibraryDiscoveryInterface
   */
  protected $libraryDiscovery;


  /**
   * Constructs a new ThemeEmailAdjuster object.
   *
@@ -69,15 +60,12 @@ class ThemeEmailAdjuster extends EmailAdjusterBase implements ContainerFactoryPl
   *   The theme manager.
   * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
   *   The theme handler.
   * @param \Drupal\Core\Asset\LibraryDiscoveryInterface $library_discovery
   *   The library discovery service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ThemeManagerInterface $theme_manager, ThemeHandlerInterface $theme_handler, LibraryDiscoveryInterface $library_discovery) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config_factory, ThemeManagerInterface $theme_manager, ThemeHandlerInterface $theme_handler) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);
    $this->configFactory = $config_factory;
    $this->themeManager = $theme_manager;
    $this->themeHandler = $theme_handler;
    $this->libraryDiscovery = $library_discovery;
  }

  /**
@@ -145,18 +133,17 @@ class ThemeEmailAdjuster extends EmailAdjusterBase implements ContainerFactoryPl
   */
  protected function getEmailTheme() {
    $theme = $this->configuration['theme'];
    $theme_config = $this->configFactory->get('system.theme');

    switch ($theme) {
      case '_default':
        $theme = $this->configFactory->get('system.theme')->get('default');
        $theme = $theme_config->get('default');
        break;

      case '_active_fallback':
        $theme = $this->themeManager->getActiveTheme()->getName();
        if (!$this->libraryDiscovery->getLibraryByName($theme, 'email')) {
          $default_theme = $this->configFactory->get('system.theme')->get('default');
          $theme = $this->libraryDiscovery->getLibraryByName($default_theme, 'email') ?
            $default_theme : $theme;
        if ($theme == $theme_config->get('admin')) {
          $theme = $theme_config->get('default');
        }
        break;
    }