public function ParamConverterManager::enhance

Implements \Symfony\Cmf\Component\Routing\Enhancer\ŖouteEnhancerIterface.

Iterates over all registered converters and allows them to alter the defaults.

Parameters

array $defaults: The getRouteDefaults array.

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

array The modified defaults.

Overrides RouteEnhancerInterface::enhance

File

drupal/core/lib/Drupal/Core/ParamConverter/ParamConverterManager.php, line 63
Contains Drupal\Core\ParamConverter\ParamConverterManager.

Class

ParamConverterManager
Provides a service which allows to enhance (say alter) the arguments coming from the URL.

Namespace

Drupal\Core\ParamConverter

Code

public function enhance(array $defaults, Request $request) {

  // This array will collect the names of all variables which have been
  // altered by a converter.
  // This serves two purposes:
  // 1. It might prevent converters later in the pipeline to process
  //    a variable again.
  // 2. To check if upcasting was successfull after each converter had
  //    a go. See below.
  $converters = array();
  $route = $defaults[RouteObjectInterface::ROUTE_OBJECT];
  foreach ($this->converters as $converter) {
    $converter
      ->process($defaults, $route, $converters);
  }

  // Check if all upcasting yielded a result.
  // If an upcast value is NULL do a 404.
  foreach ($converters as $variable) {
    if ($defaults[$variable] === NULL) {
      throw new NotFoundHttpException();
    }
  }
  return $defaults;
}