示例#1
0
 /**
  * @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(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
 /**
  * Class constructor.
  */
 public function __construct(ServiceManager $serviceManager, EntityAbstract $object)
 {
     parent::__construct($object->get('underscore_entity_name'));
     $this->serviceManager = $serviceManager;
     $entityManager = $this->serviceManager->get('Doctrine\\ORM\\EntityManager');
     $objectSpecificFieldset = '\\Calendar\\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('action', '');
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]);
     $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' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-submit")]]);
 }