You are here

public function Tour::hasMatchingRoute in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour::hasMatchingRoute()
  2. 10 core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour::hasMatchingRoute()

Whether the tour matches a given set of route parameters.

Parameters

string $route_name: The route name the parameters are for.

array $route_params: Associative array of raw route params.

Return value

bool TRUE if the tour matches the route parameters.

Overrides TourInterface::hasMatchingRoute

File

core/modules/tour/src/Entity/Tour.php, line 146

Class

Tour
Defines the configured tour entity.

Namespace

Drupal\tour\Entity

Code

public function hasMatchingRoute($route_name, $route_params) {
  if (!isset($this->keyedRoutes)) {
    $this->keyedRoutes = [];
    foreach ($this
      ->getRoutes() as $route) {
      $this->keyedRoutes[$route['route_name']] = isset($route['route_params']) ? $route['route_params'] : [];
    }
  }
  if (!isset($this->keyedRoutes[$route_name])) {

    // We don't know about this route.
    return FALSE;
  }
  if (empty($this->keyedRoutes[$route_name])) {

    // We don't need to worry about route params, the route name is enough.
    return TRUE;
  }
  foreach ($this->keyedRoutes[$route_name] as $key => $value) {

    // If a required param is missing or doesn't match, return FALSE.
    if (empty($route_params[$key]) || $route_params[$key] !== $value) {
      return FALSE;
    }
  }
  return TRUE;
}