public function RouteCondition::evaluate in Route Condition 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/Condition/RouteCondition.php \Drupal\route_condition\Plugin\Condition\RouteCondition::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
- src/
Plugin/ Condition/ RouteCondition.php, line 108
Class
- RouteCondition
- Provides a 'Route' condition.
Namespace
Drupal\route_condition\Plugin\ConditionCode
public function evaluate() {
// Convert routes to lowercase.
$routes = mb_strtolower($this->configuration['routes']);
$routes = str_replace([
"\r\n",
"\r",
], "\n", $routes);
$routes = explode("\n", $routes);
if (!$routes) {
return TRUE;
}
$current_route = $this->currentRouteMatch
->getCurrentRouteMatch();
$current_route_name = $current_route
->getRouteName();
foreach ($routes as $route) {
$negate = isset($route[0]) && $route[0] === '~';
$route = ltrim($route, '~');
if ($route === $current_route_name || $this
->evaluateRouteWildcards($route, $current_route_name)) {
return !$negate;
}
}
return FALSE;
}