You are here

public function LanguageCookieConditionBlacklistedPaths::evaluate in Language Cookie 8

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

bool TRUE if the condition has been met, FALSE otherwise.

Overrides LanguageCookieConditionBase::evaluate

File

src/Plugin/LanguageCookieCondition/LanguageCookieConditionBlacklistedPaths.php, line 97

Class

LanguageCookieConditionBlacklistedPaths
Class for the Blacklisted paths condition plugin.

Namespace

Drupal\language_cookie\Plugin\LanguageCookieCondition

Code

public function evaluate() {

  // Check the path against a list of paths where that the module shouldn't
  // run on.
  // This list of path is configurable on the admin page.
  foreach ((array) $this->configuration[$this
    ->getPluginId()] 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, '/');

    // @todo get the right alias for the current language (pass along langcode), or alternatively, store the system path only, so we don't have to compare against aliases.
    $path_alias = mb_strtolower($this->aliasManager
      ->getAliasByPath($path));
    $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();
}