tipsCollection = new TipsPluginCollection(\Drupal::service('plugin.manager.tour.tip'), $this->tips); } /** * {@inheritdoc} */ public function getRoutes() { return $this->routes; } /** * {@inheritdoc} */ public function getTip($id) { return $this->tipsCollection->get($id); } /** * {@inheritdoc} */ public function getTips() { $tips = []; foreach ($this->tips as $id => $tip) { $tips[] = $this->getTip($id); } uasort($tips, function ($a, $b) { if ($a->getWeight() == $b->getWeight()) { return 0; } return ($a->getWeight() < $b->getWeight()) ? -1 : 1; }); \Drupal::moduleHandler()->alter('tour_tips', $tips, $this); return array_values($tips); } /** * {@inheritdoc} */ public function getModule() { return $this->module; } /** * {@inheritdoc} */ 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; } /** * {@inheritdoc} */ public function resetKeyedRoutes() { unset($this->keyedRoutes); } /** * {@inheritdoc} */ public function calculateDependencies() { parent::calculateDependencies(); foreach ($this->tipsCollection as $instance) { $definition = $instance->getPluginDefinition(); $this->addDependency('module', $definition['provider']); } $this->addDependency('module', $this->module); return $this; } }