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
- class \Drupal\gin_login\Theme\ThemeNegotiator implements ThemeNegotiatorInterface
Expanded class hierarchy of ThemeNegotiator
1 string reference to 'ThemeNegotiator'
1 service uses ThemeNegotiator
File
- src/
Theme/ ThemeNegotiator.php, line 13
Namespace
Drupal\gin_login\ThemeView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ThemeNegotiator:: |
protected | property | @var ConfigFactoryInterface | |
ThemeNegotiator:: |
public | function |
Overrides ThemeNegotiatorInterface:: |
|
ThemeNegotiator:: |
public | function |
Overrides ThemeNegotiatorInterface:: |
|
ThemeNegotiator:: |
private | function | Function that does all of the work in selecting a theme. | |
ThemeNegotiator:: |
public | function |