You are here

public function LanguageSelectionPageConditionBlacklistedPaths::evaluate in Language Selection Page 8.2

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

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

Overrides LanguageSelectionPageConditionBase::evaluate

File

src/Plugin/LanguageSelectionPageCondition/LanguageSelectionPageConditionBlacklistedPaths.php, line 122

Class

LanguageSelectionPageConditionBlacklistedPaths
Class for the Blacklisted paths condition plugin.

Namespace

Drupal\language_selection_page\Plugin\LanguageSelectionPageCondition

Code

public function evaluate() {

  // 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 ((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, '/');
    $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();
}