Tour::hasMatchingRoute

public Tour::hasMatchingRoute($route_name, $route_params)

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 137

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 = array();
    foreach ($this->getRoutes() as $route) {
      $this->keyedRoutes[$route['route_name']] = isset($route['route_params']) ? $route['route_params'] : array();
    }
  }
  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;
}
doc_Drupal
2016-10-29 09:48:49
Comments
Leave a Comment

Please login to continue.