diff --git a/src/Symfony/Bridge/Propel1/Form/DataTransformer/ModelToIdTransformer.php b/src/Symfony/Bridge/Propel1/Form/DataTransformer/ModelToIdTransformer.php deleted file mode 100644 index 08061a231f01..000000000000 --- a/src/Symfony/Bridge/Propel1/Form/DataTransformer/ModelToIdTransformer.php +++ /dev/null @@ -1,72 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Symfony\Bridge\Propel1\Form\DataTransformer; - -use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList; -use Symfony\Component\Form\DataTransformerInterface; -use Symfony\Component\Form\Exception\UnexpectedTypeException; -use Symfony\Component\Form\Exception\TransformationFailedException; - -/** - * @author William Durand - */ -class ModelToIdTransformer implements DataTransformerInterface -{ - /** - * @var \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList - */ - private $choiceList; - - /** - * @param \Propel\PropelBundle\Form\ChoiceList\ModelChoiceList $choiceList - */ - public function __construct(ModelChoiceList $choiceList) - { - $this->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; - } -} diff --git a/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php b/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php index 254727da5d13..d24cb06d9cbc 100644 --- a/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php +++ b/src/Symfony/Bridge/Propel1/Form/Type/ModelType.php @@ -12,7 +12,6 @@ namespace Symfony\Bridge\Propel1\Form\Type; use Symfony\Bridge\Propel1\Form\ChoiceList\ModelChoiceList; -use Symfony\Bridge\Propel1\Form\DataTransformer\ModelToIdTransformer; use Symfony\Bridge\Propel1\Form\DataTransformer\ModelsToArrayTransformer; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; @@ -28,8 +27,6 @@ public function buildForm(FormBuilder $builder, array $options) { if ($options['multiple']) { $builder->prependClientTransformer(new ModelsToArrayTransformer($options['choice_list'])); - } else { - $builder->prependClientTransformer(new ModelToIdTransformer($options['choice_list'])); } }