예제 #1
0
 /**
  * @param EntityManager  $entityManager
  * @param EntityAbstract $object
  */
 public function __construct(EntityManager $entityManager, 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(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager]));
         }
         if ($element instanceof Radio) {
             $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);
         }
     }
 }
예제 #2
0
 /**
  * @param ServiceManager $serviceManager
  * @param EntityAbstract $object
  */
 public function __construct(ServiceManager $serviceManager, EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $this->serviceManager = $serviceManager;
     $entityManager = $this->serviceManager->get('doctrine.entitymanager.orm_default');
     $objectSpecificFieldset = '\\Affiliation\\Form\\' . ucfirst($object->get('entity_name')) . 'Fieldset';
     /**
      * Load a specific fieldSet when present
      */
     if (class_exists($objectSpecificFieldset)) {
         $objectFieldset = new $objectSpecificFieldset($entityManager, $object);
     } else {
         $objectFieldset = new ObjectFieldset($entityManager, $object);
     }
     $objectFieldset->setUseAsBaseFieldset(true);
     $this->add($objectFieldset);
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-submit")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'delete', 'attributes' => ['class' => "btn btn-danger", 'value' => _("txt-delete")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]);
 }