From 9e745df8fef1eb6a67cd83ac956b67844d557fda Mon Sep 17 00:00:00 2001 From: Moritz Schroeder Date: Fri, 19 Feb 2016 21:40:05 +0100 Subject: [PATCH] Added missing "property" option --- Form/Type/ModelType.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index f97c915..6b13f4c 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -204,12 +204,32 @@ class ModelType extends AbstractType return $query; }; + $choiceLabelNormalizer = function (Options $options, $choiceLabel) { + if ($choiceLabel === null) { + if ($options['property'] == null) { + $choiceLabel = array(__CLASS__, 'createChoiceLabel'); + } else { + $valueProperty = $options['property']; + /** @var ModelCriteria $query */ + $query = $options['query']; + $getter = 'get' . ucfirst($query->getTableMap()->getColumn($valueProperty)->getPhpName()); + + $choiceLabel = function($choice) use ($getter) { + return call_user_func([$choice, $getter]); + }; + } + } + + return $choiceLabel; + }; + $resolver->setDefaults([ 'query' => null, 'index_property' => null, + 'property' => null, 'choices' => null, 'choice_loader' => $choiceLoader, - 'choice_label' => array(__CLASS__, 'createChoiceLabel'), + 'choice_label' => null, 'choice_name' => $choiceName, 'choice_value' => $choiceValue, 'choice_translation_domain' => false, @@ -217,6 +237,7 @@ class ModelType extends AbstractType $resolver->setRequired(array('class')); $resolver->setNormalizer('query', $queryNormalizer); + $resolver->setNormalizer('choice_value', $choiceLabelNormalizer); $resolver->setAllowedTypes('query', ['null', 'Propel\Runtime\ActiveQuery\ModelCriteria']); }