public function createAssociationField($form, $metaData, $fieldName) { $formField = new SelectField(array()); $formField->setLabel($this->translateName($fieldName)); $formField->setName($fieldName); $formField->setRequired(true); $targetEntityName = $metaData->getAssociationTargetClass($fieldName); $targetEntity = $this->doctrineService->getRepository($targetEntityName); if ($metaData->isCollectionValuedAssociation($fieldName)) { $formField->setMultiple(true); } $collection = $this->entityToCollection($targetEntity->findAll(), !$formField->isMultiple()); $formField->setCollection($collection); $form->addField($formField); }
/** * @param FormBuilder $form * @param ClassMetadata $metaData * @param string $fieldName */ public function createAssociationField($form, $metaData, $fieldName) { $formField = new SelectField(array()); $formField->setLabel($this->translateName($fieldName)); $formField->setName($fieldName); $mapping = $metaData->getAssociationMapping($fieldName); $required = false; $targetEntityName = $metaData->getAssociationTargetClass($fieldName); $targetEntity = $this->doctrineService->getRepository($targetEntityName); if ($metaData->isCollectionValuedAssociation($fieldName)) { $formField->setMultiple(true); $formField->setRequired(false); } else { foreach ($mapping['joinColumns'] as $joinColumn) { if (!$joinColumn['nullable']) { $required = true; break; } } $formField->setRequired($required); } $collection = $this->entityToCollection($targetEntity->findAll(), !$formField->isMultiple()); $formField->setCollection($collection); $form->addField($formField); }