public function LBATAdminNegotiator::applies in Layout builder admin theme 8
Whether this theme negotiator should be used to set the theme.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match object.
Return value
bool TRUE if this negotiator should be used or FALSE to let other negotiators decide.
Overrides ThemeNegotiatorInterface::applies
File
- src/
Theme/ LBATAdminNegotiator.php, line 36
Class
- LBATAdminNegotiator
- Forces the admin theme when using layout builder.
Namespace
Drupal\layout_builder_admin_theme\ThemeCode
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;
}