Loading domain_theme_switch.services.yml +5 −2 Original line number Diff line number Diff line services: domain_theme_switch.domain_theme_lookup: class: Drupal\domain_theme_switch\DomainThemeLookup arguments: ['@config.factory'] theme.negotiator.domain_theme_switch: class: Drupal\domain_theme_switch\Theme\ThemeSwitchNegotiator arguments: ['@router.admin_context','@current_user','@domain.negotiator','@config.factory'] arguments: ['@router.admin_context','@current_user','@domain.negotiator','@domain_theme_switch.domain_theme_lookup'] tags: - { name: theme_negotiator, priority: 10 } src/DomainThemeLookup.php 0 → 100644 +43 −0 Original line number Diff line number Diff line <?php namespace Drupal\domain_theme_switch; use Drupal\Core\Config\ConfigFactoryInterface; /** * Class DomainThemeLookup. */ class DomainThemeLookup implements DomainThemeLookupInterface { /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** * DomainThemeLookup constructor. * * @param ConfigFactoryInterface $config_factory * The config factory. */ public function __construct(ConfigFactoryInterface $config_factory) { $this->configFactory = $config_factory->get('domain_theme_switch.settings'); } /** * {@inheritdoc} */ public function getDefaultTheme($domain_id) { return $this->configFactory->get($domain_id . '_site'); } /** * {@inheritdoc} */ public function getAdminTheme($domain_id) { return $this->configFactory->get($domain_id . '_admin'); } } src/DomainThemeLookupInterface.php 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php namespace Drupal\domain_theme_switch; /** * Defines the interface for domain_theme_lookup. */ interface DomainThemeLookupInterface { /** * Gets the default theme for the domain. * * @param string $domain_id * The domain ID. * * @return string * The default theme. */ public function getDefaultTheme($domain_id); /** * Gets the admin theme for the domain. * * @param string $domain_id * The domain ID. * * @return string * The admin theme. */ public function getAdminTheme($domain_id); } src/Theme/ThemeSwitchNegotiator.php +12 −16 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ use Drupal\Core\Theme\ThemeNegotiatorInterface; use Drupal\Core\Routing\AdminContext; use Drupal\Core\Session\AccountInterface; use Drupal\domain\DomainNegotiatorInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\domain_theme_switch\DomainThemeLookup; /** * Implements ThemeNegotiatorInterface. Loading @@ -15,18 +15,16 @@ use Drupal\Core\Config\ConfigFactoryInterface; class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { /** * Protected theme variable to set the default theme againt the domain. * The name of the default theme for the current domain. * * @var string * Return theme name for the curret domain. */ protected $defaultTheme = NULL; /** * Protected theme variable to set default theme against domain admin pages. * The name of the admin theme for the current domain. * * @var string * Return theme name for the current domain. */ protected $adminTheme = NULL; Loading @@ -53,11 +51,11 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { protected $negotiator; /** * The config factory. * The domain theme lookup service. * * @var \Drupal\Core\Config\ConfigFactoryInterface * @var \Drupal\domain_theme_switch\DomainThemeLookup */ protected $configFactory; protected $domainThemeLookup; /** * Constructs a new EntityConverter. Loading @@ -68,17 +66,17 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { * The current user. * @param \Drupal\domain\DomainNegotiatorInterface $negotiator * The domain negotiator. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. * @param \Drupal\domain_theme_switch\DomainThemeLookup * The domain theme lookup service. */ public function __construct(AdminContext $admin_context, AccountInterface $current_user, DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory) { DomainThemeLookup $domain_theme_lookup) { $this->adminContext = $admin_context; $this->currentUser = $current_user; $this->negotiator = $negotiator; $this->configFactory = $config_factory; $this->domainThemeLookup = $domain_theme_lookup; } /** Loading @@ -97,15 +95,13 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { return FALSE; } $config = $this->configFactory->get('domain_theme_switch.settings'); // Admin pages uses same theme by default. $this->defaultTheme = $this->adminTheme = $config->get($domain->id() . '_site'); $this->defaultTheme = $this->adminTheme = $this->domainThemeLookup->getDefaultTheme($domain->id()); // Allow overriding admin theme for users having 'Use domain admin theme' // permission. if ($this->currentUser->hasPermission('domain administration theme')) { $this->adminTheme = $config->get($domain->id() . '_admin'); $this->adminTheme = $this->domainThemeLookup->getAdminTheme($domain->id()); } return TRUE; Loading Loading
domain_theme_switch.services.yml +5 −2 Original line number Diff line number Diff line services: domain_theme_switch.domain_theme_lookup: class: Drupal\domain_theme_switch\DomainThemeLookup arguments: ['@config.factory'] theme.negotiator.domain_theme_switch: class: Drupal\domain_theme_switch\Theme\ThemeSwitchNegotiator arguments: ['@router.admin_context','@current_user','@domain.negotiator','@config.factory'] arguments: ['@router.admin_context','@current_user','@domain.negotiator','@domain_theme_switch.domain_theme_lookup'] tags: - { name: theme_negotiator, priority: 10 }
src/DomainThemeLookup.php 0 → 100644 +43 −0 Original line number Diff line number Diff line <?php namespace Drupal\domain_theme_switch; use Drupal\Core\Config\ConfigFactoryInterface; /** * Class DomainThemeLookup. */ class DomainThemeLookup implements DomainThemeLookupInterface { /** * The config factory. * * @var \Drupal\Core\Config\ConfigFactoryInterface */ protected $configFactory; /** * DomainThemeLookup constructor. * * @param ConfigFactoryInterface $config_factory * The config factory. */ public function __construct(ConfigFactoryInterface $config_factory) { $this->configFactory = $config_factory->get('domain_theme_switch.settings'); } /** * {@inheritdoc} */ public function getDefaultTheme($domain_id) { return $this->configFactory->get($domain_id . '_site'); } /** * {@inheritdoc} */ public function getAdminTheme($domain_id) { return $this->configFactory->get($domain_id . '_admin'); } }
src/DomainThemeLookupInterface.php 0 → 100644 +32 −0 Original line number Diff line number Diff line <?php namespace Drupal\domain_theme_switch; /** * Defines the interface for domain_theme_lookup. */ interface DomainThemeLookupInterface { /** * Gets the default theme for the domain. * * @param string $domain_id * The domain ID. * * @return string * The default theme. */ public function getDefaultTheme($domain_id); /** * Gets the admin theme for the domain. * * @param string $domain_id * The domain ID. * * @return string * The admin theme. */ public function getAdminTheme($domain_id); }
src/Theme/ThemeSwitchNegotiator.php +12 −16 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ use Drupal\Core\Theme\ThemeNegotiatorInterface; use Drupal\Core\Routing\AdminContext; use Drupal\Core\Session\AccountInterface; use Drupal\domain\DomainNegotiatorInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\domain_theme_switch\DomainThemeLookup; /** * Implements ThemeNegotiatorInterface. Loading @@ -15,18 +15,16 @@ use Drupal\Core\Config\ConfigFactoryInterface; class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { /** * Protected theme variable to set the default theme againt the domain. * The name of the default theme for the current domain. * * @var string * Return theme name for the curret domain. */ protected $defaultTheme = NULL; /** * Protected theme variable to set default theme against domain admin pages. * The name of the admin theme for the current domain. * * @var string * Return theme name for the current domain. */ protected $adminTheme = NULL; Loading @@ -53,11 +51,11 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { protected $negotiator; /** * The config factory. * The domain theme lookup service. * * @var \Drupal\Core\Config\ConfigFactoryInterface * @var \Drupal\domain_theme_switch\DomainThemeLookup */ protected $configFactory; protected $domainThemeLookup; /** * Constructs a new EntityConverter. Loading @@ -68,17 +66,17 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { * The current user. * @param \Drupal\domain\DomainNegotiatorInterface $negotiator * The domain negotiator. * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The config factory. * @param \Drupal\domain_theme_switch\DomainThemeLookup * The domain theme lookup service. */ public function __construct(AdminContext $admin_context, AccountInterface $current_user, DomainNegotiatorInterface $negotiator, ConfigFactoryInterface $config_factory) { DomainThemeLookup $domain_theme_lookup) { $this->adminContext = $admin_context; $this->currentUser = $current_user; $this->negotiator = $negotiator; $this->configFactory = $config_factory; $this->domainThemeLookup = $domain_theme_lookup; } /** Loading @@ -97,15 +95,13 @@ class ThemeSwitchNegotiator implements ThemeNegotiatorInterface { return FALSE; } $config = $this->configFactory->get('domain_theme_switch.settings'); // Admin pages uses same theme by default. $this->defaultTheme = $this->adminTheme = $config->get($domain->id() . '_site'); $this->defaultTheme = $this->adminTheme = $this->domainThemeLookup->getDefaultTheme($domain->id()); // Allow overriding admin theme for users having 'Use domain admin theme' // permission. if ($this->currentUser->hasPermission('domain administration theme')) { $this->adminTheme = $config->get($domain->id() . '_admin'); $this->adminTheme = $this->domainThemeLookup->getAdminTheme($domain->id()); } return TRUE; Loading