function Tour::hasMatchingRoute

Same name 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()
  3. 11.x core/modules/tour/src/Entity/Tour.php \Drupal\tour\Entity\Tour::hasMatchingRoute()

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;
}

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