You are here

public function LocalTaskDefault::getRouteParameters in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Menu/LocalTaskDefault.php \Drupal\Core\Menu\LocalTaskDefault::getRouteParameters()

Returns the route parameters needed to render a link for the local task.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

array An array of parameter names and values.

Overrides LocalTaskInterface::getRouteParameters

1 method overrides LocalTaskDefault::getRouteParameters()
UserTrackerTab::getRouteParameters in core/modules/tracker/src/Plugin/Menu/UserTrackerTab.php
Returns the route parameters needed to render a link for the local task.

File

core/lib/Drupal/Core/Menu/LocalTaskDefault.php, line 48
Contains \Drupal\Core\Menu\LocalTaskDefault.

Class

LocalTaskDefault
Default object used for LocalTaskPlugins.

Namespace

Drupal\Core\Menu

Code

public function getRouteParameters(RouteMatchInterface $route_match) {
  $parameters = isset($this->pluginDefinition['route_parameters']) ? $this->pluginDefinition['route_parameters'] : array();
  $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;
}