You are here

class VisualDiffThemeNegotiator in Diff 8

Visual inline layout theme negotiator.

@package Drupal\diff

Hierarchy

Expanded class hierarchy of VisualDiffThemeNegotiator

1 file declares its use of VisualDiffThemeNegotiator
VisualDiffThemeNegotiatorTest.php in tests/src/Unit/VisualDiffThemeNegotiatorTest.php
1 string reference to 'VisualDiffThemeNegotiator'
diff.services.yml in ./diff.services.yml
diff.services.yml
1 service uses VisualDiffThemeNegotiator
theme.negotiator.visual_diff in ./diff.services.yml
Drupal\diff\VisualDiffThemeNegotiator

File

src/VisualDiffThemeNegotiator.php, line 14

Namespace

Drupal\diff
View source
class VisualDiffThemeNegotiator implements ThemeNegotiatorInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * VisualDiffThemeNegotiator 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 $routeMatch) {
    if ($routeMatch
      ->getParameter('filter') !== 'visual_inline') {
      return FALSE;
    }
    if (!$this
      ->isDiffRoute($routeMatch)) {
      return FALSE;
    }
    if ($this->configFactory
      ->get('diff.settings')
      ->get('general_settings.visual_inline_theme') !== 'default') {
      return FALSE;
    }
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    return $this->configFactory
      ->get('system.theme')
      ->get('default');
  }

  /**
   * Checks if route names for node or other entity are corresponding.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   Route match object.
   *
   * @return bool
   *   Return TRUE if route name is ok.
   */
  protected function isDiffRoute(RouteMatchInterface $route_match) {
    $regex_pattern = '/^entity\\..*\\.revisions_diff$/';
    return $route_match
      ->getRouteName() === 'diff.revisions_diff' || preg_match($regex_pattern, $route_match
      ->getRouteName());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
VisualDiffThemeNegotiator::$configFactory protected property The config factory.
VisualDiffThemeNegotiator::applies public function Whether this theme negotiator should be used to set the theme. Overrides ThemeNegotiatorInterface::applies
VisualDiffThemeNegotiator::determineActiveTheme public function Determine the active theme for the request. Overrides ThemeNegotiatorInterface::determineActiveTheme
VisualDiffThemeNegotiator::isDiffRoute protected function Checks if route names for node or other entity are corresponding.
VisualDiffThemeNegotiator::__construct public function VisualDiffThemeNegotiator constructor.