public function FieldMapEnhancer::enhance

If the target field is not set but the source field is, map the field

Overrides RouteEnhancerInterface::enhance

File

drupal/core/vendor/symfony-cmf/routing/Symfony/Cmf/Component/Routing/Enhancer/FieldMapEnhancer.php, line 45

Class

FieldMapEnhancer
This enhancer can fill one field with the result of a hashmap lookup of another field. If the target field is already set, it does nothing.

Namespace

Symfony\Cmf\Component\Routing\Enhancer

Code

public function enhance(array $defaults, Request $request) {
  if (isset($defaults[$this->target])) {
    return $defaults;
  }
  if (!isset($defaults[$this->source])) {
    return $defaults;
  }
  if (!isset($this->hashmap[$defaults[$this->source]])) {
    return $defaults;
  }
  $defaults[$this->target] = $this->hashmap[$defaults[$this->source]];
  return $defaults;
}