You are here

class LBATAdminNegotiator in Layout builder admin theme 8

Forces the admin theme when using layout builder.

Hierarchy

Expanded class hierarchy of LBATAdminNegotiator

1 string reference to 'LBATAdminNegotiator'
layout_builder_admin_theme.services.yml in ./layout_builder_admin_theme.services.yml
layout_builder_admin_theme.services.yml
1 service uses LBATAdminNegotiator
theme.negotiator.layout_builder_admin_theme in ./layout_builder_admin_theme.services.yml
Drupal\layout_builder_admin_theme\Theme\LBATAdminNegotiator

File

src/Theme/LBATAdminNegotiator.php, line 14

Namespace

Drupal\layout_builder_admin_theme\Theme
View 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

Namesort descending Modifiers Type Description Overrides
LBATAdminNegotiator::$configFactory protected property The configuration factory.
LBATAdminNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
LBATAdminNegotiator::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiatorInterface::determineActiveTheme
LBATAdminNegotiator::__construct public function Layout Builder Admin Theme - Admin Negotiator constructor.