You are here

class ThemeNegotiator in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/Theme/ThemeNegotiator.php \Drupal\dashboards\Theme\ThemeNegotiator

Dashboard theme negotiator.

Hierarchy

Expanded class hierarchy of ThemeNegotiator

1 string reference to 'ThemeNegotiator'
dashboards.services.yml in ./dashboards.services.yml
dashboards.services.yml
1 service uses ThemeNegotiator
theme.negotiator.dashboard in ./dashboards.services.yml
Drupal\dashboards\Theme\ThemeNegotiator

File

src/Theme/ThemeNegotiator.php, line 14

Namespace

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

Namesort descending Modifiers Type Description Overrides
ThemeNegotiator::$config protected property The config factory.
ThemeNegotiator::$themeManager protected property Theme manager.
ThemeNegotiator::$user protected property The current user.
ThemeNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
ThemeNegotiator::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiatorInterface::determineActiveTheme
ThemeNegotiator::__construct public function Service constructor.