public function PageThemeNegotiator::applies in Switch Page Theme 8
Same name and namespace in other branches
- 8.3 src/Theme/PageThemeNegotiator.php \Drupal\switch_page_theme\Theme\PageThemeNegotiator::applies()
- 8.2 src/Theme/PageThemeNegotiator.php \Drupal\switch_page_theme\Theme\PageThemeNegotiator::applies()
Select specified pages for specified role and apply theme.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match object.
Return value
bool TRUE if this negotiator should be used or FALSE to let other negotiators decide.
Overrides ThemeNegotiatorInterface::applies
File
- src/
Theme/ PageThemeNegotiator.php, line 114
Class
- PageThemeNegotiator
- Sets the selected theme on specified pages.
Namespace
Drupal\switch_page_theme\ThemeCode
public function applies(RouteMatchInterface $route_match) {
global $theme;
$applies = FALSE;
// Get multiple configurations saved for different pages.
$spt_table = $this->configFactory
->get('switch_page_theme.settings')
->get('spt_table');
if (!$spt_table) {
// Configuration has not been set yet.
return FALSE;
}
foreach ($spt_table as $value) {
$value += [
'domain' => [],
'language' => [],
];
$condition = FALSE;
// Check if rule is enabled.
if ($value['status'] == 1) {
// Check condition for basic rules.
$condition = $this->request
->getCurrentRequest()->attributes
->get("_route") != "system.403" && ($this->pathMatcher
->matchPath($this->currentPath
->getPath(), $value["pages"]) || $this->pathMatcher
->matchPath($this->pathAlias
->getAliasByPath($this->currentPath
->getPath()), $value["pages"])) && (empty($value["theme_key"]) || $this->request
->getCurrentRequest()
->get('theme_key') == $value["theme_key"]) && (!array_filter($value["roles"]) || !empty(array_intersect($value["roles"], $this->account
->getRoles())));
// Check if domain module is enabled.
if ($this->moduleHandler
->moduleExists('domain') && !empty($this->negotiator
->getActiveDomain())) {
// Check condition for domain.
$condition = $condition && (!array_filter($value["domain"]) || !empty(array_intersect($value["domain"], [
$this->negotiator
->getActiveDomain()
->id(),
])));
}
// Check if site is multilingual.
if ($this->languageManager
->isMultilingual() || $this->moduleHandler
->moduleExists('language')) {
// Check condition for language.
$condition = $condition && (!array_filter($value["language"]) || !empty(array_intersect($value["language"], [
$this->languageManager
->getCurrentLanguage()
->getId(),
])));
}
// Check if all conditions match.
if ($condition) {
$applies = TRUE;
// Set the theme to apply on page into global variable.
$theme = $value['theme'];
}
}
}
// Use the theme.
return $applies;
}