/** * @param EntityManager $entityManager * @param Entity\EntityAbstract $object */ public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object) { parent::__construct($object->get('underscore_entity_name')); $doctrineHydrator = new DoctrineHydrator($entityManager); $this->setHydrator($doctrineHydrator)->setObject($object); $builder = new AnnotationBuilder(); /* * Go over the different form elements and add them to the form */ foreach ($builder->createForm($object)->getElements() as $element) { /* * Go over each element to add the objectManager to the EntitySelect */ if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox || $element instanceof EntityRadio) { $element->setOptions(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager])); } if ($element instanceof Radio && !$element instanceof EntityRadio) { $attributes = $element->getAttributes(); $valueOptionsArray = 'get' . ucfirst($attributes['array']); $element->setOptions(array_merge_recursive($element->getOptions(), ['value_options' => $object->{$valueOptionsArray}()])); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } }
/** * @param EntityManager $entityManager * @param Entity\EntityAbstract $object */ public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object) { parent::__construct($object->get('underscore_entity_name')); $doctrineHydrator = new DoctrineHydrator($entityManager); $this->setHydrator($doctrineHydrator)->setObject($object); $builder = new AnnotationBuilder(); /* * Go over the different form elements and add them to the form */ foreach ($builder->createForm($object)->getElements() as $element) { /* * Go over each element to add the objectManager to the EntitySelect */ if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) { $element->setOptions(['object_manager' => $entityManager]); } if ($element instanceof Radio) { $attributes = $element->getAttributes(); $valueOptionsArray = 'get' . ucfirst($attributes['array']); $element->setOptions(['value_options' => $object->{$valueOptionsArray}()]); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'attributes' => ["class" => "form-control"], 'options' => ["label" => _("txt-source-file"), "help-block" => _("txt-attachment-requirements")]]); }