You are here

class ThemeNegotiator in Gin Login 8

Contains \Drupal\gin_login\Theme\ThemeNegotiator Credit to jimconte https://jimconte.com/blog/web/dynamic-theme-switching-in-drupal-8.

Hierarchy

Expanded class hierarchy of ThemeNegotiator

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

File

src/Theme/ThemeNegotiator.php, line 13

Namespace

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

  /** @var ConfigFactoryInterface */
  protected $configFactory;
  public function __construct(ConfigFactoryInterface $configFactory) {
    $this->configFactory = $configFactory;
  }

  /**
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   * @return bool
   */
  public function applies(RouteMatchInterface $route_match) {
    return $this
      ->negotiateRoute($route_match) ? TRUE : FALSE;
  }

  /**
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   * @return null|string
   */
  public function determineActiveTheme(RouteMatchInterface $route_match) {
    return $this
      ->negotiateRoute($route_match) ?: NULL;
  }

  /**
   * Function that does all of the work in selecting a theme.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *
   * @return bool|string
   */
  private function negotiateRoute(RouteMatchInterface $route_match) {
    if ($route_match
      ->getRouteName() == 'user.login' || $route_match
      ->getRouteName() == 'user.pass' || $route_match
      ->getRouteName() == 'user.register') {
      return $this->configFactory
        ->get('system.theme')
        ->get('admin');
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ThemeNegotiator::$configFactory protected property @var ConfigFactoryInterface
ThemeNegotiator::applies public function Overrides ThemeNegotiatorInterface::applies
ThemeNegotiator::determineActiveTheme public function Overrides ThemeNegotiatorInterface::determineActiveTheme
ThemeNegotiator::negotiateRoute private function Function that does all of the work in selecting a theme.
ThemeNegotiator::__construct public function