You are here

class ThemeNegotiatorWrapper in Devel 8

Same name and namespace in other branches
  1. 8.3 webprofiler/src/Theme/ThemeNegotiatorWrapper.php \Drupal\webprofiler\Theme\ThemeNegotiatorWrapper
  2. 8.2 webprofiler/src/Theme/ThemeNegotiatorWrapper.php \Drupal\webprofiler\Theme\ThemeNegotiatorWrapper
  3. 4.x webprofiler/src/Theme/ThemeNegotiatorWrapper.php \Drupal\webprofiler\Theme\ThemeNegotiatorWrapper

Class ThemeNegotiatorWrapper

Hierarchy

Expanded class hierarchy of ThemeNegotiatorWrapper

1 file declares its use of ThemeNegotiatorWrapper
ThemeDataCollector.php in webprofiler/src/DataCollector/ThemeDataCollector.php

File

webprofiler/src/Theme/ThemeNegotiatorWrapper.php, line 11

Namespace

Drupal\webprofiler\Theme
View source
class ThemeNegotiatorWrapper extends ThemeNegotiator {

  /**
   * @var \Drupal\Core\Theme\ThemeNegotiatorInterface
   */
  private $negotiator;

  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {

    // This method has changed in Drupal 8.4.x, to maintain compatibility with
    // Drupal 8.3.x we check the existence or not of the classResolver
    // property.
    // TODO: remove this logic when we decide to drop Drupal 8.3.x support.
    if (property_exists($this, 'classResolver')) {
      $classResolver = $this->classResolver;
      $negotiators = $this->negotiators;
    }
    else {
      $classResolver = \Drupal::classResolver();
      $negotiators = $this
        ->getSortedNegotiators();
    }
    foreach ($negotiators as $negotiator_id) {
      if (property_exists($this, 'classResolver')) {
        $negotiator = $classResolver
          ->getInstanceFromDefinition($negotiator_id);
      }
      else {
        $negotiator = $negotiator_id;
      }
      if ($negotiator
        ->applies($route_match)) {
        $theme = $negotiator
          ->determineActiveTheme($route_match);
        if ($theme !== NULL && $this->themeAccess
          ->checkAccess($theme)) {
          $this->negotiator = $negotiator;
          return $theme;
        }
      }
    }
  }

  /**
   * @return \Drupal\Core\Theme\ThemeNegotiatorInterface
   */
  public function getNegotiator() {
    return $this->negotiator;
  }

  /**
   * Returns the sorted array of theme negotiators.
   *
   * @return array|\Drupal\Core\Theme\ThemeNegotiatorInterface[]
   *   An array of theme negotiator objects.
   *
   * TODO: remove this method when we decide to drop Drupal 8.3.x support.
   */
  protected function getSortedNegotiators() {
    if (!isset($this->sortedNegotiators)) {

      // Sort the negotiators according to priority.
      krsort($this->negotiators);

      // Merge nested negotiators from $this->negotiators into
      // $this->sortedNegotiators.
      $this->sortedNegotiators = [];
      foreach ($this->negotiators as $builders) {
        $this->sortedNegotiators = array_merge($this->sortedNegotiators, $builders);
      }
    }
    return $this->sortedNegotiators;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeNegotiator::$classResolver protected property The class resolver.
ThemeNegotiator::$negotiators protected property Holds an array of theme negotiator IDs, sorted by priority.
ThemeNegotiator::$themeAccess protected property The access checker for themes.
ThemeNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
ThemeNegotiator::__construct public function Constructs a new ThemeNegotiator.
ThemeNegotiatorWrapper::$negotiator private property
ThemeNegotiatorWrapper::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiator::determineActiveTheme
ThemeNegotiatorWrapper::getNegotiator public function
ThemeNegotiatorWrapper::getSortedNegotiators protected function Returns the sorted array of theme negotiators.