function ParamConversionEnhancer::copyRawVariables

Same name in other branches
  1. 9 core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer::copyRawVariables()
  2. 8.9.x core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer::copyRawVariables()
  3. 10 core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php \Drupal\Core\Routing\Enhancer\ParamConversionEnhancer::copyRawVariables()

Store a backup of the raw values that corresponding to the route pattern.

Parameters

array $defaults: The route defaults array.

Return value

\Symfony\Component\HttpFoundation\InputBag The input bag container with the raw variables.

1 call to ParamConversionEnhancer::copyRawVariables()
ParamConversionEnhancer::enhance in core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php
Updates the defaults for a route definition based on the request.

File

core/lib/Drupal/Core/Routing/Enhancer/ParamConversionEnhancer.php, line 59

Class

ParamConversionEnhancer
Provides a route enhancer that handles parameter conversion.

Namespace

Drupal\Core\Routing\Enhancer

Code

protected function copyRawVariables(array $defaults) {
    
    /** @var \Symfony\Component\Routing\Route $route */
    $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
    $variables = array_flip($route->compile()
        ->getVariables());
    // Foreach will copy the values from the array it iterates. Even if they
    // are references, use it to break them. This avoids any scenarios where raw
    // variables also get replaced with converted values.
    $raw_variables = [];
    foreach (array_intersect_key($defaults, $variables) as $key => $value) {
        $raw_variables[$key] = $value;
    }
    // Route defaults that do not start with a leading "_" are also
    // parameters, even if they are not included in path or host patterns.
    foreach ($route->getDefaults() as $name => $value) {
        if (!isset($raw_variables[$name]) && !str_starts_with($name, '_')) {
            $raw_variables[$name] = $value;
        }
    }
    return new InputBag($raw_variables);
}

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