class LBATAdminNegotiator in Layout builder admin theme 8
Forces the admin theme when using layout builder.
Hierarchy
- class \Drupal\layout_builder_admin_theme\Theme\LBATAdminNegotiator implements ThemeNegotiatorInterface
Expanded class hierarchy of LBATAdminNegotiator
1 string reference to 'LBATAdminNegotiator'
1 service uses LBATAdminNegotiator
File
- src/
Theme/ LBATAdminNegotiator.php, line 14
Namespace
Drupal\layout_builder_admin_theme\ThemeView source
class LBATAdminNegotiator implements ThemeNegotiatorInterface {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Layout Builder Admin Theme - Admin Negotiator constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function applies(RouteMatchInterface $route_match) {
// Check if enabled in config.
$is_enabled = $this->configFactory
->get('layout_builder_admin_theme.config')
->get('lbat_enable_admin_theme');
if (!$is_enabled) {
return FALSE;
}
// Get and check the route.
$route = $route_match
->getRouteObject();
if (empty($route)) {
return FALSE;
}
// Get and check the form.
$form = $route
->getDefault('_entity_form') ?? $route
->getDefault('_form');
if (empty($form)) {
return FALSE;
}
$form_class = ltrim($form, '\\');
// If this is the Layout Builder revert changes form, apply the admin theme.
if ($form_class === RevertOverridesForm::class) {
return TRUE;
}
// If this is the Layout Builder discard changes form, apply the admin
// theme.
if ($form_class === DiscardLayoutChangesForm::class) {
return TRUE;
}
// If form ends with ".layout_builder" apply the admin theme.
$form_types = explode('.', $form);
$form_type = end($form_types);
if (!empty($form_type) && $form_type === 'layout_builder') {
return TRUE;
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(RouteMatchInterface $route_match) {
return $this->configFactory
->get('system.theme')
->get('admin');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
LBATAdminNegotiator:: |
protected | property | The configuration factory. | |
LBATAdminNegotiator:: |
public | function |
Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface:: |
|
LBATAdminNegotiator:: |
public | function |
Determine the active theme for the request. Overrides ThemeNegotiatorInterface:: |
|
LBATAdminNegotiator:: |
public | function | Layout Builder Admin Theme - Admin Negotiator constructor. |