You are here

class ThemeNegotiator in Visually Impaired Support (module) 8

Defines the theme negotiator.

Hierarchy

Expanded class hierarchy of ThemeNegotiator

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

File

src/Theme/ThemeNegotiator.php, line 13

Namespace

Drupal\visually_impaired_module\Theme
View source
class ThemeNegotiator implements ThemeNegotiatorInterface {

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

  /**
   * Route Admin Context.
   *
   * @var \Drupal\Core\Routing\AdminContext
   */
  protected $routerAdminContext;

  /**
   * ThemeNegotiator constructor.
   *
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *
   *   The Config Factory.
   * @param \Drupal\Core\Routing\AdminContext $router_admin_context
   *
   *   The Router Admin Context.
   */
  public function __construct(ConfigFactoryInterface $config_factory, AdminContext $router_admin_context) {
    $this->configFactory = $config_factory;
    $this->routerAdminContext = $router_admin_context;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(RouteMatchInterface $route_match) {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    $config = $this->configFactory
      ->get('visually_impaired_module.visually_impaired_module.settings');
    $is_admin = $this->routerAdminContext
      ->isAdminRoute($route_match
      ->getRouteObject());
    if (isset($_COOKIE['visually_impaired']) && $_COOKIE['visually_impaired'] == 'on' && $is_admin == FALSE) {
      return $config
        ->get('visually_impaired_theme');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeNegotiator::$configFactory protected property Config factory.
ThemeNegotiator::$routerAdminContext protected property Route Admin Context.
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 ThemeNegotiator constructor.