You are here

protected static function Routes::addRouteParameter in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::addRouteParameter()
  2. 9 core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::addRouteParameter()

Adds a parameter option to a route, overrides options of the same name.

The Symfony Route class only has a method for adding options which overrides any previous values. Therefore, it is tedious to add a single parameter while keeping those that are already set.

Parameters

\Symfony\Component\Routing\Route $route: The route to which the parameter is to be added.

string $name: The name of the parameter.

mixed $parameter: The parameter's options.

File

core/modules/jsonapi/src/Routing/Routes.php, line 388

Class

Routes
Defines dynamic routes.

Namespace

Drupal\jsonapi\Routing

Code

protected static function addRouteParameter(Route $route, $name, $parameter) {
  $parameters = $route
    ->getOption('parameters') ?: [];
  $parameters[$name] = $parameter;
  $route
    ->setOption('parameters', $parameters);
}