function Routes::addRouteParameter

Same name in other branches
  1. 8.9.x core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::addRouteParameter()
  2. 10 core/modules/jsonapi/src/Routing/Routes.php \Drupal\jsonapi\Routing\Routes::addRouteParameter()
  3. 11.x 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.

2 calls to Routes::addRouteParameter()
Routes::getFileUploadRoutesForResourceType in core/modules/jsonapi/src/Routing/Routes.php
Gets the file upload route collection for the given resource type.
Routes::getRoutesForResourceType in core/modules/jsonapi/src/Routing/Routes.php
Gets applicable resource routes for a JSON:API resource type.

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

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