[Form] Fixed outstanding issues mentioned in the PR

This commit is contained in:
Bernhard Schussek 2012-01-24 11:59:07 +01:00
parent 7c7097675b
commit 5f6f75c026
7 changed files with 51 additions and 19 deletions

View File

@ -168,7 +168,7 @@ To get the diff between two versions, go to https://github.com/symfony/symfony/c
* [BC BREAK] greatly improved `ChoiceListInterface` and all of its * [BC BREAK] greatly improved `ChoiceListInterface` and all of its
implementations. `EntityChoiceList` was adapted, the methods `getEntities()`, implementations. `EntityChoiceList` was adapted, the methods `getEntities()`,
`getEntitiesByByKeys()`, `getIdentifier()` and `getIdentifierValues()` were `getEntitiesByKeys()`, `getIdentifier()` and `getIdentifierValues()` were
removed/made private. Instead of the first two you can use `getChoices()` removed/made private. Instead of the first two you can use `getChoices()`
and `getChoicesByValues()`, for the latter two no replacement exists. and `getChoicesByValues()`, for the latter two no replacement exists.
`ArrayChoiceList` was replaced by `SimpleChoiceList`. `ArrayChoiceList` was replaced by `SimpleChoiceList`.

View File

@ -74,7 +74,9 @@ class EntityChoiceList extends ObjectChoiceList
* @param string $labelPath The property path used for the label * @param string $labelPath The property path used for the label
* @param EntityLoaderInterface $entityLoader An optional query builder * @param EntityLoaderInterface $entityLoader An optional query builder
* @param array $entities An array of choices * @param array $entities An array of choices
* @param string $groupPath * @param string $groupPath A property path pointing to the property used
* to group the choices. Only allowed if
* the choices are given as flat array.
*/ */
public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null) public function __construct(ObjectManager $manager, $class, $labelPath = null, EntityLoaderInterface $entityLoader = null, $entities = null, $groupPath = null)
{ {

View File

@ -21,17 +21,19 @@ interface EntityLoaderInterface
/** /**
* Returns an array of entities that are valid choices in the corresponding choice list. * Returns an array of entities that are valid choices in the corresponding choice list.
* *
* @return array * @return array The entities.
*/ */
function getEntities(); function getEntities();
/** /**
* Returns an array of entities matching the given identifiers. * Returns an array of entities matching the given identifiers.
* *
* @param string $identifier * @param string $identifier The identifier field of the object. This method
* @param array $values * is not applicable for fields with multiple
* identifiers.
* @param array $values The values of the identifiers.
* *
* @return array * @return array The entities.
*/ */
function getEntitiesByIds($identifier, array $values); function getEntitiesByIds($identifier, array $values);
} }

View File

@ -51,6 +51,20 @@ interface ChoiceListInterface
* Returns the choice views of the preferred choices as nested array with * Returns the choice views of the preferred choices as nested array with
* the choice groups as top-level keys. * the choice groups as top-level keys.
* *
* Example:
*
* <source>
* array(
* 'Group 1' => array(
* 10 => ChoiceView object,
* 20 => ChoiceView object,
* ),
* 'Group 2' => array(
* 30 => ChoiceView object,
* ),
* )
* </source>
*
* @return array A nested array containing the views with the corresponding * @return array A nested array containing the views with the corresponding
* choice indices as keys on the lowest levels and the choice * choice indices as keys on the lowest levels and the choice
* group names in the keys of the higher levels. * group names in the keys of the higher levels.
@ -61,6 +75,20 @@ interface ChoiceListInterface
* Returns the choice views of the choices that are not preferred as nested * Returns the choice views of the choices that are not preferred as nested
* array with the choice groups as top-level keys. * array with the choice groups as top-level keys.
* *
* Example:
*
* <source>
* array(
* 'Group 1' => array(
* 10 => ChoiceView object,
* 20 => ChoiceView object,
* ),
* 'Group 2' => array(
* 30 => ChoiceView object,
* ),
* )
* </source>
*
* @return array A nested array containing the views with the corresponding * @return array A nested array containing the views with the corresponding
* choice indices as keys on the lowest levels and the choice * choice indices as keys on the lowest levels and the choice
* group names in the keys of the higher levels. * group names in the keys of the higher levels.

View File

@ -120,7 +120,7 @@ class SimpleChoiceList extends ChoiceList
/** /**
* Converts the choices to a valid PHP array keys. * Converts the choices to valid PHP array keys.
* *
* @param array $choices The choices. * @param array $choices The choices.
* *

View File

@ -53,7 +53,7 @@ class ChoiceToValueTransformer implements DataTransformerInterface
$choices = $this->choiceList->getChoicesForValues(array($value)); $choices = $this->choiceList->getChoicesForValues(array($value));
if (count($choices) !== 1) { if (count($choices) !== 1) {
throw new TransformationFailedException('The choice "' . $value . '" does not exist'); throw new TransformationFailedException('The choice "' . $value . '" does not exist or is not unique');
} }
$choice = current($choices); $choice = current($choices);