You are here

public function RequestPath::evaluate in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/src/Plugin/Condition/RequestPath.php \Drupal\system\Plugin\Condition\RequestPath::evaluate()

Evaluates the condition and returns TRUE or FALSE accordingly.

Return value

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

Overrides ConditionInterface::evaluate

File

core/modules/system/src/Plugin/Condition/RequestPath.php, line 145

Class

RequestPath
Provides a 'Request Path' condition.

Namespace

Drupal\system\Plugin\Condition

Code

public function evaluate() {

  // Convert path to lowercase. This allows comparison of the same path
  // with different case. Ex: /Page, /page, /PAGE.
  $pages = mb_strtolower($this->configuration['pages']);
  if (!$pages) {
    return TRUE;
  }
  $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));
  return $this->pathMatcher
    ->matchPath($path_alias, $pages) || $path != $path_alias && $this->pathMatcher
    ->matchPath($path, $pages);
}