choiceList = $choiceList; } public function transform($model) { if (null === $model || '' === $model) { return ''; } if (!is_object($model)) { throw new UnexpectedTypeException($model, 'object'); } if (count($this->choiceList->getIdentifier()) > 1) { $availableModels = $this->choiceList->getModels(); return array_search($model, $availableModels); } return current($this->choiceList->getIdentifierValues($model)); } public function reverseTransform($key) { if ('' === $key || null === $key) { return null; } if (count($this->choiceList->getIdentifier()) > 1 && !is_numeric($key)) { throw new UnexpectedTypeException($key, 'numeric'); } if (!($model = $this->choiceList->getModel($key))) { throw new TransformationFailedException(sprintf('The model with key "%s" could not be found', $key)); } return $model; } }