function Tour::hasMatchingRoute

Same name and namespace in other branches
  1. 9 core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour::hasMatchingRoute()
  2. 8.9.x core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour::hasMatchingRoute()
  3. 11.x 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 143

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']] = $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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.