public function Paths::evaluate in Administration Language Negotiation 8
Evaluates the condition and returns TRUE or FALSE accordingly.
Return value
bool TRUE if the condition has been met, FALSE otherwise.
Overrides AdministrationLanguageNegotiationConditionBase::evaluate
File
- src/
Plugin/ AdministrationLanguageNegotiationCondition/ Paths.php, line 161
Class
- Paths
- Class for the Blacklisted paths condition plugin.
Namespace
Drupal\administration_language_negotiation\Plugin\AdministrationLanguageNegotiationConditionCode
public function evaluate() {
$langcode = $this->languageManager
->getCurrentLanguage()
->getId();
$prefixes = $this->configFactory
->get('language.negotiation')
->get('url.prefixes');
$admin_paths = array_filter($this->configuration[$this
->getPluginId()]);
foreach ($admin_paths as $admin_path) {
foreach ($prefixes as $prefix) {
$admin_paths[] = '/' . $prefix . '/' . trim($admin_path, '/');
}
}
// Check the path against a list of paths where that the module shouldn't
// run on.
// This list of paths is configurable on the admin page.
foreach ($admin_paths as $blacklisted_path) {
$request = $this->requestStack
->getCurrentRequest();
// Compare the lowercase path alias (if any) and internal path.
$path = $this->currentPath
->getPath($request);
// Do not trim a trailing slash if that is the complete path.
$path = $path === '/' ? $path : rtrim($path, '/');
// Aliases have a language property that must be used to
// search for a match on the current path alias, or the
// default language will be used instead.
$path_alias = mb_strtolower($this->aliasManager
->getAliasByPath($path, $langcode));
$is_on_blacklisted_path = $this->pathMatcher
->matchPath($path_alias, $blacklisted_path) || $path !== $path_alias && $this->pathMatcher
->matchPath($path, $blacklisted_path);
if ($is_on_blacklisted_path) {
return $this
->block();
}
}
return $this
->pass();
}