| 1 | <?php |
||
| 14 | class EntityType extends AbstractType |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Manager registry. |
||
| 18 | * |
||
| 19 | * @var ManagerRegistry |
||
| 20 | */ |
||
| 21 | protected $manager; |
||
| 22 | |||
| 23 | public function __construct(ManagerRegistry $manager) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * {@inheritdoc} |
||
| 30 | */ |
||
| 31 | public function buildForm(FormBuilderInterface $builder, array $options) |
||
| 32 | { |
||
| 33 | if (!$options['class']) { |
||
| 34 | throw new LogicException('Option "class" must be set.'); |
||
| 35 | } |
||
| 36 | |||
| 37 | $modelTransformer = new IdentifierToObjectTransformer( |
||
| 38 | $this->manager->getRepository($options['class']), |
||
| 39 | $options['identifier'] |
||
| 40 | ); |
||
| 41 | |||
| 42 | $builder |
||
| 43 | ->addModelTransformer($modelTransformer) |
||
| 44 | ; |
||
| 45 | } |
||
| 46 | |||
| 47 | public function buildView(FormView $view, FormInterface $form, array $options) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | public function setDefaultOptions(OptionsResolverInterface $resolver) |
||
| 56 | { |
||
| 57 | $resolver->setDefaults(array( |
||
| 58 | 'identifier' => 'id', |
||
| 59 | 'empty_data' => null, |
||
| 60 | 'class' => null, |
||
| 61 | )) |
||
| 62 | ; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | public function getParent() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | public function getName() |
||
| 80 | } |
||
| 81 |