class ThemeNegotiator in Dashboards with Layout Builder 8
Same name and namespace in other branches
- 2.0.x src/Theme/ThemeNegotiator.php \Drupal\dashboards\Theme\ThemeNegotiator
Dashboard theme negotiator.
Hierarchy
- class \Drupal\dashboards\Theme\ThemeNegotiator implements ThemeNegotiatorInterface
Expanded class hierarchy of ThemeNegotiator
1 string reference to 'ThemeNegotiator'
1 service uses ThemeNegotiator
File
- src/
Theme/ ThemeNegotiator.php, line 14
Namespace
Drupal\dashboards\ThemeView source
class ThemeNegotiator implements ThemeNegotiatorInterface {
/**
* Theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface
*/
protected $themeManager;
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountInterface
*/
protected $user;
/**
* Service constructor.
*
* @param \Drupal\Core\Theme\ThemeManagerInterface $theme_manager
* The theme manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory.
* @param \Drupal\Core\Session\AccountInterface $currentUser
* The current user.
*/
public function __construct(ThemeManagerInterface $theme_manager, ConfigFactoryInterface $configFactory, AccountInterface $currentUser) {
$this->themeManager = $theme_manager;
$this->config = $configFactory;
$this->user = $currentUser;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
if ($dashboard = $route_match
->getParameter('dashboard')) {
if (is_object($dashboard) && $dashboard
->showAlwaysInFrontend()) {
return FALSE;
}
}
if ($this->user
->isAnonymous() || !$this->user
->hasPermission('view the administration theme')) {
return FALSE;
}
if (in_array($route_match
->getRouteName(), [
'entity.dashboard.canonical',
'layout_builder.dashboards.view',
'layout_builder.dashboards_override.view',
])) {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->config
->get('system.theme')
->get('admin');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeNegotiator:: |
protected | property | The config factory. | |
ThemeNegotiator:: |
protected | property | Theme manager. | |
ThemeNegotiator:: |
protected | property | The current user. | |
ThemeNegotiator:: |
public | function |
Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface:: |
|
ThemeNegotiator:: |
public | function |
Determine the active theme for the request. Overrides ThemeNegotiatorInterface:: |
|
ThemeNegotiator:: |
public | function | Service constructor. |