routeProvider = $route_provider; } /** * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { return new static( $configuration, $plugin_id, $plugin_definition, $container->get('router.route_provider') ); } /** * {@inheritdoc} */ public function getRouteName() { return $this->pluginDefinition['route_name']; } /** * {@inheritdoc} */ public function getTitle(Request $request = NULL) { // Subclasses may pull in the request or specific attributes as parameters. // The title from YAML file discovery may be a TranslatableMarkup object. return (string) $this->pluginDefinition['title']; } /** * {@inheritdoc} */ public function getWeight() { return $this->pluginDefinition['weight']; } /** * {@inheritdoc} */ public function getRouteParameters(RouteMatchInterface $route_match) { $parameters = isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : []; $route = $this->routeProvider->getRouteByName($this->getRouteName()); $variables = $route->compile()->getVariables(); // Normally the \Drupal\Core\ParamConverter\ParamConverterManager has // processed the Request attributes, and in that case the _raw_variables // attribute holds the original path strings keyed to the corresponding // slugs in the path patterns. For example, if the route's path pattern is // /filter/tips/{filter_format} and the path is /filter/tips/plain_text then // $raw_variables->get('filter_format') == 'plain_text'. $raw_variables = $route_match->getRawParameters(); foreach ($variables as $name) { if (isset($parameters[$name])) { continue; } if ($raw_variables && $raw_variables->has($name)) { $parameters[$name] = $raw_variables->get($name); } elseif ($value = $route_match->getRawParameter($name)) { $parameters[$name] = $value; } } // The UrlGenerator will throw an exception if expected parameters are // missing. This method should be overridden if that is possible. return $parameters; } /** * {@inheritdoc} */ public function getOptions(RouteMatchInterface $route_match) { return (array) $this->pluginDefinition['options']; } /** * {@inheritdoc} */ public function getCacheTags() { if (!isset($this->pluginDefinition['cache_tags'])) { return []; } return $this->pluginDefinition['cache_tags']; } /** * {@inheritdoc} */ public function getCacheContexts() { if (!isset($this->pluginDefinition['cache_contexts'])) { return []; } return $this->pluginDefinition['cache_contexts']; } /** * {@inheritdoc} */ public function getCacheMaxAge() { if (!isset($this->pluginDefinition['cache_max_age'])) { return Cache::PERMANENT; } return $this->pluginDefinition['cache_max_age']; } }