Exemplo n.º 1
0
 public function __construct($name = null, $options = array())
 {
     parent::__construct($name ?: 'ldc-user-profile', $options);
     $this->setObject(new \stdClass());
     $this->setHydrator(new ObjectProperty());
     $submitElement = new \Zend\Form\Element\Button('submit');
     $submitElement->setLabel('Save Changes')->setAttributes(array('type' => 'submit'));
     $this->add($submitElement, array('priority' => -1000));
 }
Exemplo n.º 2
0
 /**
  * Retorna a form para o cadastro da entidade
  */
 public function getForm($entityClass = null)
 {
     if (null === $entityClass) {
         $entityClass = $this->getEntityClass();
     }
     $builder = new AnnotationBuilder();
     $form = $builder->createForm($entityClass);
     $hasEntity = false;
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'setObjectManager')) {
             $element->setObjectManager($this->getEntityManager());
             $hasEntity = true;
         } elseif (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($this->getEntityManager());
                 $hasEntity = true;
             }
         }
     }
     if ($hasEntity) {
         $hydrator = new DoctrineHydrator($this->getEntityManager(), $entityClass);
         $form->setHydrator($hydrator);
     } else {
         $form->setHydrator(new ClassMethods());
     }
     $form->add(['type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf', 'attributes' => ['id' => 'csrf']]);
     $submitElement = new \Zend\Form\Element\Button('submit');
     $submitElement->setAttributes(['type' => 'submit', 'class' => 'btn btn-primary']);
     $submitElement->setLabel('Salvar');
     $form->add($submitElement, ['priority' => -100]);
     $cancelarElement = new \Zend\Form\Element\Button('cancelar');
     $cancelarElement->setAttributes(['type' => 'button', 'class' => 'btn btn-default', 'onclick' => 'top.location=\'' . $this->url()->fromRoute($this->getActionRoute('list')) . '\'']);
     $cancelarElement->setLabel('Cancelar');
     $form->add($cancelarElement, ['priority' => -100]);
     return $form;
 }