/** * @param mixed $model */ public function setModel($model) { $modelClass = get_class($model); $this->form = $this->annotationBuilder->createForm($modelClass); $this->form->bind($model); $this->setVariables(['form' => $this->form, 'object' => $model, 'title' => $this->getFieldSetTitle($model)]); $this->buildFormViewModel($this->form, $this); }
public function authenticateAction() { $user = new Forms\Login(); $builder = new AnnotationBuilder(); $form = $builder->createForm($user); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $user = $request->getPost('username'); $pass = $request->getPost('password'); $redir = urldecode($this->params()->fromQuery('redir')); $authService = $this->getAuthService(); $authService->setIdentity($user); $authService->setCredential($pass); $result = $authService->authenticate(); /* $d = new \Zend\Debug\Debug(); $d->dump($result); die; */ foreach ($result->getMessages() as $message) { //save message temporary into flashmessenger $this->flashmessenger()->addMessage($message); } $conf = $this->getServiceLocator()->get('IdAuth\\Config'); if ($conf['settings']['usePrevPageRedir']) { return $this->redirect()->toUrl($redir); } else { return $this->redirect()->toRoute('idAuth'); } } } return $this->redirect()->toRoute('idAuth/login'); }
/** * @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); } } $this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'organisation', 'options' => ['disable_inarray_validator' => true, "label" => _("txt-organisation"), "help-block" => _("txt-organisation-help-block")]]); $this->add(['type' => '\\Zend\\Form\\Element\\Text', 'name' => 'branch', 'options' => ["label" => _("txt-branch"), "help-block" => _("txt-branch-help-block")]]); }
/** * The default action - show the home page */ public function indexAction() { // init vars $data = NULL; $table = $this->getServiceLocator()->get('city-codes-table'); $catList = $this->getServiceLocator()->get('form-demo-categories'); $cityList = $table->getAllCityCodesForForm(); $countryList = $table->getAllCountryCodesForForm(); // submit button $submit = new Submit('submit'); $submit->setAttribute('value', 'Submit'); // build form $builder = new AnnotationBuilder(); $entity = $this->getServiceLocator()->get('form-demo-listings-entity'); $form = $builder->createForm($entity); $form->get('category')->setValueOptions(array_combine($catList, $catList)); $form->getInputFilter()->get('category')->getValidatorChain()->attachByName('InArray', array('haystack' => $catList)); $form->get('country')->setValueOptions($countryList); $form->getInputFilter()->get('country')->getValidatorChain()->attachByName('InArray', array('haystack' => $countryList)); $form->add($submit); $form->bind($entity); if ($this->getRequest()->isPost()) { $form->setData($this->params()->fromPost()); if ($form->isValid()) { $data = $form->getData(); } } return new ViewModel(array('form' => $form, 'data' => $data, 'cityList' => $cityList)); }
/** * @param object|string $entity * * @return void|\Zend\Form\Form */ public function createForm($entity) { $this->triggerEvent(FormEvent::EVENT_FORM_CREATE_PRE, $this, array('entity' => $entity)); $form = parent::createForm($entity); $this->triggerEvent(FormEvent::EVENT_FORM_CREATE_POST, $form, array('entity' => $entity)); return $form; }
/** * @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); } } }
public function addAction() { // The annotation builder help us create a form from the annotations in the user entity. $builder = new AnnotationBuilder(); $entity = $this->serviceLocator->get('user-entity'); $form = $builder->createForm($entity); $form->add(array('name' => 'password_verify', 'type' => 'Zend\\Form\\Element\\Password', 'attributes' => array('placeholder' => 'Verify Password Here...', 'required' => 'required'), 'options' => array('label' => 'Verify Password')), array('priority' => $form->get('password')->getOption('priority'))); // This is the special code that protects our form being submitted from automated scripts $form->add(array('name' => 'csrf', 'type' => 'Zend\\Form\\Element\\Csrf')); // This is the submit button $form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Submit', 'required' => 'false'))); // We bind the entity to the user. If the form tries to read/write data from/to the entity // it will use the hydrator specified in the entity to achieve this. In our case we use ClassMethods // hydrator which means that reading will happen calling the getter methods and writing will happen by // calling the setter methods. $form->bind($entity); if ($this->getRequest()->isPost()) { $data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray()); $form->setData($data); if ($form->isValid()) { // We use now the Doctrine 2 entity manager to save user data to the database $entityManager = $this->serviceLocator->get('entity-manager'); $entityManager->persist($entity); $entityManager->flush(); $this->flashmessenger()->addSuccessMessage('User was added successfully.'); $event = new EventManager('user'); $event->trigger('register', $this, array('user' => $entity)); // redirect the user to the view user action return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'view', 'id' => $entity->getId())); } } // pass the data to the view for visualization return array('form1' => $form); }
/** * @param EntityManager $entityManager */ public function __construct(EntityManager $entityManager) { parent::__construct('doa'); $doa = new Entity\Doa(); $doctrineHydrator = new DoctrineHydrator($entityManager, 'Affiliation\\Entity\\Doa'); $this->setHydrator($doctrineHydrator)->setObject($doa); $builder = new AnnotationBuilder(); /** * Go over the different form elements and add them to the form */ foreach ($builder->createForm($doa)->getElements() as $element) { /** * Go over each element to add the objectManager to the EntitySelect */ if ($element instanceof EntitySelect) { $element->setOptions(['object_manager' => $entityManager]); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } $this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'contact', 'options' => ["label" => "txt-signer"]]); $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-source-file", "help-block" => _("txt-attachment-requirements")]]); }
/** * For JS AJAX validation - validates a property of Equipment object. * @return JSON status=ok|error,message={string} */ public function validateJSONAction() { try { $propName = $this->params()->fromPost('propName'); if (!in_array($propName, Equipment::propertyNames())) { throw new \Exception('Wrong property provided.'); } $value = $this->params()->fromPost('value'); if (!$propName || !$value) { throw new \Exception('No property and/or value given.'); } $equipment = new Equipment(); $builder = new AnnotationBuilder(); $form = $builder->createForm($equipment); $form->setData(array($propName => $value))->isValid(); $elements = $form->getElements(); $element = $elements[$propName]; if (count($element->getMessages())) { return $this->myJsonModel(array('status' => 'error', 'message' => $element->getMessages())); } else { return $this->myJsonModel(array('status' => 'ok', 'message' => '')); } } catch (\Exception $e) { // @TODO: set status to syserror so JS doesn't confuse with // validation error return $this->myJsonModel(array('status' => 'error', 'message' => $e->getMessage())); } }
protected function getForm() { $builder = new AnnotationBuilder(); $entity = new TestEntity(); $form = $builder->createForm($entity); return $form; }
/** * @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")]]); }
/** * Returns constructed Feedback * * @param ServiceManager $sm ServiceManager * * @return Form */ public static function getFeedbackForm(ServiceManager $sm) { $builder = new AnnotationBuilder(); $form = $builder->createForm('\\Swissbib\\Feedback\\Form\\FeedbackForm'); $form->add(new Csrf('security')); $form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'feedback.form.submit']]); return $form; }
public function getForm() { if (!$this->form) { $user = new User(); $builder = new AnnotationBuilder(); $this->form = $builder->createForm($user); } return $this->form; }
private function getForm() { if (!$this->form) { $form = new LoginForm(); $builder = new AnnotationBuilder(); $this->form = $builder->createForm($form); } return $this->form; }
public function __construct() { $this->lastAttemptResult = LoginLogoutService::$failedLoginAttempt; $this->authservice = new AuthenticationService(); $this->authservice->setStorage(new \Main\Service\UserSessionStorage()); $user = new User(); $builder = new AnnotationBuilder(); $this->form = $builder->createForm($user); }
/** * @param ServiceManager $sm * * @return Form */ public static function getCopyForm(ServiceManager $sm) { AbstractValidator::setDefaultTranslator($sm->get('\\VuFind\\Translator')); $builder = new AnnotationBuilder(); $form = $builder->createForm('\\Swissbib\\Record\\Form\\CopyForm'); $form->add(new Csrf('security')); $form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'request_copy_text']]); return $form; }
public static function factory(PeepEntity $peep = null) { if (null === $peep) { $peep = __NAMESPACE__ . '\\PeepEntity'; } $builder = new AnnotationBuilder(); $form = $builder->createForm($peep); $form->add(new CsrfElement('secure')); $form->add(array('name' => 'peep', 'attributes' => array('type' => 'submit', 'value' => 'Peep!'))); if ($peep instanceof PeepEntity) { $form->bind($peep); } return $form; }
/** * {@inheritDoc} */ protected function getCreateForm() { $entityManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $builder = new AnnotationBuilder($entityManager); $form = $builder->createForm($this->getEntity()); $options = $entityManager->getRepository('Comment\\Entity\\EntityType')->getEntities(); $select = $form->getElements()['entity']; $select->setValueOptions($options); $select->setOptions(array('empty_option' => 'Please choose entity')); $form->setInputFilter(new Filter\EntityTypeInputFilter($this->getServiceLocator())); $urlHelper = $this->getUrlHelper(); $form->setAttribute('action', $urlHelper('comment/default', ['controller' => 'entity-type', 'action' => 'create'])); // $form->setData(['isVisible' => true, 'isEnabled' => true]); return $form; }
/** * Create service * * @param ServiceLocatorInterface $sm * @return \Zend\Form\Form */ public function createService(ServiceLocatorInterface $sm) { $seo = new Seo(Null, Null, Null, Null); $builder = new AnnotationBuilder(); $form = $builder->createForm($seo); $form->bind($seo); $form->get('type')->setValueOptions(Seo::$entityType); // $form->add(array( // 'type' => 'DoctrineModule\Form\Element\ObjectSelect', // 'name' => 'pageId', // 'priority' => 5, // 'options' => array( // 'label' => 'Homeowners', // 'object_manager' => $sm->get('doctrine.entitymanager.orm_default'), // 'target_class' => '\BuilderJob\Entity\Homeowner', // 'property' => 'email', // 'empty_option' => '--- please choose ---', // 'is_method' => true, // 'find_method' => array( // 'name' => 'findAll', // ), // ), // )); $form->add(array('type' => 'DoctrineModule\\Form\\Element\\ObjectSelect', 'name' => 'pageId', 'priority' => 5, 'options' => array('label' => 'Builder', 'object_manager' => $sm->get('doctrine.entitymanager.orm_default'), 'target_class' => '\\BuilderJob\\Entity\\Builder', 'property' => 'email', 'empty_option' => '--- please choose ---', 'is_method' => true, 'find_method' => array('name' => 'findAll')))); $form->getInputFilter()->add(array('name' => 'pageId', 'required' => TRUE)); // // $form->add(array( // 'type' => 'DoctrineModule\Form\Element\ObjectSelect', // 'name' => 'pageId', // 'priority' => 5, // 'options' => array( // 'label' => 'Job', // 'object_manager' => $sm->get('doctrine.entitymanager.orm_default'), // 'target_class' => '\BuilderJob\Entity\Job', // 'property' => 'title', // 'empty_option' => '--- please choose ---', // 'is_method' => true, // 'find_method' => array( // 'name' => 'findAll', // ), // ), // )); $form->add(array('name' => 'security', 'type' => 'Zend\\Form\\Element\\Csrf')); $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Add Seo'))); return $form; }
private function getRadarForm() { $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $event = new Event(); $builder = new AnnotationBuilder(); $form = $builder->createForm($event); $form->setHydrator(new DoctrineObject($em))->setObject($event); $categories = $em->getRepository('Application\\Entity\\RadarCategory')->findBy(array('defaultradarcategory' => true)); if ($categories) { $cat = $categories[0]; $form->add(new CustomFieldset($this->getServiceLocator(), $cat->getId())); //uniquement les champs ajoutés par conf $form->get('custom_fields')->remove($cat->getRadarfield()->getId()); $form->get('custom_fields')->remove($cat->getStatefield()->getId()); } return $form; }
public function annotationSimpleAction() { // prepare data $comment = new \Mod2\Entity\Comment1(); $comment->type = 2; $comment->comment = 'Test annotation'; $builder = new AnnotationBuilder(); $form = $builder->createForm($comment); $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Go', 'id' => 'submitbutton'))); $form->bind($comment); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { var_dump($comment); } } return array('form' => $form); }
public function __construct(EntityManager $entityManager) { // we want to ignore the name passed parent::__construct('entity-create-form'); $this->setAttribute('method', 'post')->setHydrator(new DoctrineHydrator($entityManager, 'Application\\Entity\\Place'))->setObject(new Place()); $builder = new AnnotationBuilder(); $repository = $entityManager->getRepository('Application\\Entity\\Place'); $id = 1; //(int)$this->params()->fromQuery('id'); $place = $repository->find($id); $entity = $place; // new Place(); //Add the fieldset, and set it as the base fieldset $fieldset = $builder->createForm($entity); $fieldset->setUseAsBaseFieldset(true); //var_dump($fieldset); $this->add($fieldset); $this->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf')); $this->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Save'))); }
public function loginAction() { $view = new ViewModel(); $login = new Login(); $builder = new AnnotationBuilder(); $form = $builder->createForm($login); $request = $this->getRequest(); $ldap = $this->getServiceLocator()->get('Zf2LdapAuth\\Client\\Ldap'); if ($request->isPost()) { $form->bind($login); $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); try { $auth = $ldap->authenticate($data->name, $data->password); if ($auth === TRUE) { $view->data = "Authentication Successful, Redirecting..."; if ($ldap->useCallBack()) { $userData = $ldap->getUserObj($data->name); if ($userData !== FALSE) { $callBackFunction = $ldap->getCallBackFunction(); $callBackFunction::setData($userData); } } /* User already has a session so redirect back */ return $this->redirect()->toUrl($ldap->getRedirectLocation()); } else { $view->error = $auth; $view->form = $form; return $view; } } catch (\Exception $exc) { $view->data = $exc->getMessage(); return $view; } } } else { $view->form = $form; return $view; } }
/** * @param $entity * @return null|\Zend\Form\Form */ public function convertEntity(BaseInterface $entity) { if (empty($entity)) { throw new \InvalidArgumentException("Entity must not be null!"); } $className = get_class($entity); // if passed a null object, instantiate a new doctrine object of that class if ($entity->isNull()) { // null object, get $className = substr($className, 0, -4); $entity = new $className(); } $builder = new AnnotationBuilder(); // use the entity annotations and create a zend form object $form = $builder->createForm($className); // set strategy for how to transfer data between form elements and $form->setHydrator(new DoctrineHydrator($this->em(), $className)); // populate form with entity $form->bind($entity); return $form; }
/** * @param EntityManager $entityManager * @param Entity\EntityAbstract $object */ public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object) { parent::__construct($object->get('underscore_entity_name')); $contact = new Entity\Contact(); $doctrineHydrator = new DoctrineHydrator($entityManager, 'Contact\\Entity\\Contact'); $this->setHydrator($doctrineHydrator)->setObject($contact); $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('object_manager' => $entityManager)); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } $contactPhone = new ContactPhoneFieldset($entityManager, new Entity\Phone()); $contactPhone->setObject(new Entity\Phone()); $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'phone', 'options' => array('label' => _("txt-phone-information"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactPhone))); $contactProfileFieldset = new \Contact\Form\ContactProfileFieldset($entityManager, new Entity\Profile()); $this->add($contactProfileFieldset); $contactPhoto = new \Contact\Form\ContactPhotoFieldset($entityManager, new Entity\Photo()); $contactPhoto->setObject(new Entity\Photo()); $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'photo', 'options' => array('label' => _("txt-profile-photo"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => false, 'target_element' => $contactPhoto))); $contactAddress = new ContactAddressFieldset($entityManager, new Entity\Address()); $contactAddress->setObject(new Entity\Address()); $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'address', 'options' => array('label' => _("txt-address-information"), 'count' => 1, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactAddress))); $contactCommunity = new ContactCommunityFieldset($entityManager, new Entity\Community()); $contactCommunity->setObject(new Entity\Community()); $this->add(array('type' => 'Zend\\Form\\Element\\Collection', 'name' => 'community', 'options' => array('label' => _("txt-community-information"), 'count' => 5, 'should_create_template' => true, 'template_placeholder' => '__placeholder__', 'allow_add' => true, 'target_element' => $contactCommunity))); $contactOrganisationFieldset = new \Contact\Form\ContactOrganisationFieldset($entityManager, new Entity\ContactOrganisation()); $this->add($contactOrganisationFieldset); }
/** * @param EntityManager $entityManager * @param Entity\EntityAbstract $object */ public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object) { parent::__construct($object->get('underscore_entity_name')); $phone = new Entity\Phone(); $doctrineHydrator = new DoctrineHydrator($entityManager, 'Contact\\Entity\\Phone'); $this->setHydrator($doctrineHydrator)->setObject($phone); $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('object_manager' => $entityManager)); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } }
/** * Ensure user defined \Type or type attribute overrides the listener one */ public function testEnsureCustomTypeOrAttributeTypeIsUsedInAnnotations() { $userDefinedTypeOverridesListenerType = true; $entity = new FormEntity(); $zendAnnotationBuilder = new ZendAnnotationBuilder(); $zendForm = $zendAnnotationBuilder->createForm($entity); $spec = $this->builder->getFormSpecification($entity); $annotationForm = $this->builder->createForm($entity); $attributesToTest = array('specificType', 'specificMultiType', 'specificAttributeType'); foreach ($spec['elements'] as $element) { $elementName = $element['spec']['name']; if (in_array($elementName, $attributesToTest)) { $annotationFormElement = $annotationForm->get($elementName); $zendFormElement = $zendForm->get($elementName); $annotationElementAttribute = $annotationFormElement->getAttribute('type'); $zendElementAttribute = $zendFormElement->getAttribute('type'); if (get_class($zendFormElement) !== get_class($annotationFormElement) || $annotationElementAttribute !== $zendElementAttribute) { $userDefinedTypeOverridesListenerType = false; } } } $this->assertTrue($userDefinedTypeOverridesListenerType); }
/** * @param EntityManager $entityManager * @param Entity\EntityAbstract $object */ public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object) { parent::__construct($object->get('underscore_entity_name')); $photo = new Entity\Photo(); $doctrineHydrator = new DoctrineHydrator($entityManager, 'Contact\\Entity\\Photo'); $this->setHydrator($doctrineHydrator)->setObject($photo); $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('object_manager' => $entityManager)); } //Add only when a type is provided if (array_key_exists('type', $element->getAttributes())) { $this->add($element); } } $this->add(array('type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => array("label" => "txt-photo-file", "help-block" => _("txt-photo-requirements")))); }
private function getForm($alarmid = null) { $objectManager = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $alarm = new Event(); $builder = new AnnotationBuilder(); $form = $builder->createForm($alarm); $form->setHydrator(new DoctrineObject($objectManager))->setObject($alarm); $alarmcat = $objectManager->getRepository('Application\\Entity\\AlarmCategory')->findAll()[0]; // TODO $form->add(new CustomFieldset($this->getServiceLocator(), $alarmcat->getId())); $form->get('scheduled')->setValue(false); if ($alarmid) { $alarm = $objectManager->getRepository('Application\\Entity\\Event')->find($alarmid); if ($alarm) { // custom fields values foreach ($objectManager->getRepository('Application\\Entity\\CustomField')->findBy(array('category' => $alarm->getCategory()->getId())) as $customfield) { $customfieldvalue = $objectManager->getRepository('Application\\Entity\\CustomFieldValue')->findOneBy(array('event' => $alarm->getId(), 'customfield' => $customfield->getId())); if ($customfieldvalue) { $form->get('custom_fields')->get($customfield->getId())->setAttribute('value', $customfieldvalue->getValue()); } } $form->bind($alarm); $form->setData($alarm->getArrayCopy()); } $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Modifier', 'class' => 'btn btn-primary'))); } else { // alarm : punctual, impact : info, organisation, category : alarm, status : open (closed when aknowledged) // all these information are just here to validate form $form->get('impact')->setValue(5); $form->get('punctual')->setValue(true); $form->get('category')->setValue($alarmcat->getId()); $form->get('status')->setValue($objectManager->getRepository('Application\\Entity\\Status')->findOneBy(array('open' => true, 'defaut' => true))->getId()); if ($this->zfcUserAuthentication()->hasIdentity()) { $form->get('organisation')->setValue($this->zfcUserAuthentication()->getIdentity()->getOrganisation()->getId()); } else { throw new \ZfcRbac\Exception\UnauthorizedException(); } $form->add(array('name' => 'submit', 'attributes' => array('type' => 'submit', 'value' => 'Ajouter', 'class' => 'btn btn-primary'))); } return array('form' => $form, 'alarm' => $alarm); }
public function testInputFilterInputAnnotation() { $entity = new TestAsset\Annotation\EntityWithInputFilterInput(); $builder = new Annotation\AnnotationBuilder(); $form = $builder->createForm($entity); $inputFilter = $form->getInputFilter(); $this->assertTrue($inputFilter->has('input')); foreach (array('Zend\\InputFilter\\InputInterface', 'ZendTest\\Form\\TestAsset\\Annotation\\InputFilterInput') as $expectedInstance) { $this->assertInstanceOf($expectedInstance, $inputFilter->get('input')); } }