source = $source; $this->target = $target; $this->map = $map; } /** * If the source field is instance of one of the entries in the map, * target is set to the value of that map entry. * * {@inheritdoc} */ public function enhance(array $defaults, Request $request) { if (isset($defaults[$this->target])) { // no need to do anything return $defaults; } if (!isset($defaults[$this->source])) { return $defaults; } // we need to loop over the array and do instanceof in case the content // class extends the specified class // i.e. phpcr-odm generates proxy class for the content. foreach ($this->map as $class => $value) { if ($defaults[$this->source] instanceof $class) { // found a matching entry in the map $defaults[$this->target] = $value; return $defaults; } } return $defaults; } }