function ParamConverterManager::setRouteParameterConverters

Same name in other branches
  1. 9 core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php \Drupal\Core\ParamConverter\ParamConverterManager::setRouteParameterConverters()
  2. 8.9.x core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php \Drupal\Core\ParamConverter\ParamConverterManager::setRouteParameterConverters()
  3. 10 core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php \Drupal\Core\ParamConverter\ParamConverterManager::setRouteParameterConverters()

Overrides ParamConverterManagerInterface::setRouteParameterConverters

File

core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php, line 46

Class

ParamConverterManager
Manages converter services for converting request parameters to full objects.

Namespace

Drupal\Core\ParamConverter

Code

public function setRouteParameterConverters(RouteCollection $routes) {
    foreach ($routes->all() as $route) {
        if (!($parameters = $route->getOption('parameters'))) {
            // Continue with the next route if no parameters have been defined.
            continue;
        }
        // Loop over all defined parameters and look up the right converter.
        foreach ($parameters as $name => &$definition) {
            if (isset($definition['converter'])) {
                // Skip parameters that already have a manually set converter.
                continue;
            }
            foreach (array_keys($this->converters) as $converter) {
                if ($this->getConverter($converter)
                    ->applies($definition, $name, $route)) {
                    $definition['converter'] = $converter;
                    break;
                }
            }
        }
        // Override the parameters array.
        $route->setOption('parameters', $parameters);
    }
}

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