You are here

public function FieldPresenceEnhancer::enhance in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony-cmf/routing/Enhancer/FieldPresenceEnhancer.php \Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer::enhance()

Update the defaults based on its own data and the request.

Parameters

array $defaults the getRouteDefaults array.:

Request $request the Request instance.:

Return value

array the modified defaults. Each enhancer MUST return the $defaults but may add or remove values.

Overrides RouteEnhancerInterface::enhance

File

vendor/symfony-cmf/routing/Enhancer/FieldPresenceEnhancer.php, line 61

Class

FieldPresenceEnhancer
This enhancer sets a field to a fixed value. You can specify a source field name to only set the target field if the source is present.

Namespace

Symfony\Cmf\Component\Routing\Enhancer

Code

public function enhance(array $defaults, Request $request) {
  if (isset($defaults[$this->target])) {

    // no need to do anything
    return $defaults;
  }
  if (null !== $this->source && !isset($defaults[$this->source])) {
    return $defaults;
  }
  $defaults[$this->target] = $this->value;
  return $defaults;
}