/**
  * {@inheritdoc}
  */
 public function handle(Request $request, FormHandlerInterface $handler, FormInterface $form = null)
 {
     if (null !== $form) {
         $handler->setForm($form);
     } elseif (null === ($form = $handler->getForm())) {
         if ($handler instanceof NamedFormHandlerInterface && null !== ($name = $handler->getName())) {
             $form = $this->form_factory->createNamed($name, $handler->getType(), $handler->getData(), $handler->getOptions());
         } else {
             $form = $this->form_factory->create($handler->getType(), $handler->getData(), $handler->getOptions());
         }
         if (!$form instanceof FormInterface) {
             throw new FormNotFoundException($handler);
         }
         // set the form which is associated with the handler
         $handler->setForm($form);
     }
     $form->handleRequest($request);
     if (!$form->isSubmitted()) {
         return null;
     }
     if ($form->isValid()) {
         if ($handler instanceof FormSuccessHandlerInterface) {
             return $handler->onSuccess($request);
         }
     } elseif ($handler instanceof FormFailureHandlerInterface) {
         return $handler->onFailure($request);
     }
 }
 /**
  * Builds proper field form.
  *
  * @param FormEvent $event
  */
 public function buildForm(FormEvent $event)
 {
     if (null === ($fieldValue = $event->getData())) {
         return;
     }
     $form = $event->getForm();
     $options = array('label' => $fieldValue->getPresentation(), 'auto_initialize' => false, 'attr' => array('data-field-name' => $fieldValue->getName(), 'data-field-addable' => false));
     if (is_array($fieldValue->getConfiguration())) {
         $options = array_merge_recursive($options, $fieldValue->getConfiguration());
     }
     $name = 'value';
     if (FieldTypes::CHOICE === $fieldValue->getType()) {
         $option = $fieldValue->getField()->getOption();
         $sortBy = $fieldValue->getField()->getOrder();
         $type = new OptionValueChoiceType($option, $sortBy);
         if ($fieldValue->getAllowMultiple()) {
             $name = 'values';
             $options['multiple'] = true;
             $options['expanded'] = true;
         }
         $options['attr']['data-field-addable'] = $fieldValue->isAddable();
     } else {
         $type = $fieldValue->getType();
     }
     $form->remove('field')->add($this->factory->createNamed($name, $type, null, $options));
 }
示例#3
0
 public function testSetInvalidYearsOption()
 {
     $help = 'Having trouble with the internets? Tell us about it.';
     $form = $this->factory->createNamed('__test___field', $this->getTestedType(), null, ['help' => $help]);
     $view = $form->createView();
     $this->assertSame($help, $view->vars['help']);
 }
 /**
  * @param FormInterface $form
  * @param string        $ruleType
  * @param array         $data
  */
 protected function addConfigurationFields(FormInterface $form, $ruleType, array $data = [])
 {
     /** @var RuleCheckerInterface $checker */
     $checker = $this->checkerRegistry->get($ruleType);
     $configurationField = $this->factory->createNamed('configuration', $checker->getConfigurationFormType(), $data, ['auto_initialize' => false]);
     $form->add($configurationField);
 }
 public function createAndHandle($name, $type, IEntity $entity)
 {
     $request = $this->request_stack->getMasterRequest();
     $form = $this->form_factory->createNamed($name, $type, $entity, ['method' => 'POST']);
     $form->handleRequest($request);
     return $form;
 }
 /**
  * @return FormInterface
  */
 public function createForm()
 {
     $user = $this->userDiscriminator->getCurrentUserConfig();
     $type = $user->getFormType($this->type);
     $name = $user->getFormName($this->type);
     $validationGroups = $user->getFormValidationGroups($this->type);
     return $this->formFactory->createNamed($name, $type, null, array('validation_groups' => $validationGroups));
 }
 /**
  * @param FormEvent $event
  */
 public function addAttributeAsLabelField(FormEvent $event)
 {
     $data = $event->getData();
     if ($data instanceof FamilyInterface && $data->getId()) {
         $form = $event->getForm();
         $form->add($this->factory->createNamed('attributeAsLabel', 'entity', $data->getAttributeAsLabel(), ['required' => true, 'label' => 'Attribute used as label', 'class' => $this->attributeClass, 'choices' => $data->getAttributeAsLabelChoices(), 'auto_initialize' => false, 'select2' => true, 'disabled' => !$this->securityFacade->isGranted('pim_enrich_family_edit_properties')]));
     }
 }
 /**
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $taxon = $event->getData();
     if (null === $taxon) {
         return;
     }
     $event->getForm()->add($this->factory->createNamed('parent', TaxonChoiceType::class, $taxon->getParent(), ['filter' => $this->getFilterTaxonOption($taxon), 'required' => false, 'label' => 'sylius.form.taxon.parent', 'placeholder' => '---', 'auto_initialize' => false]));
 }
 /**
  * Builds proper taxon form after setting the product.
  *
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $taxon = $event->getData();
     if (null === $taxon) {
         return;
     }
     $event->getForm()->add($this->factory->createNamed('parent', 'sylius_taxon_choice', $taxon->getParent(), array('taxonomy' => $taxon->getTaxonomy(), 'filter' => $this->getFilterTaxonOption($taxon), 'required' => false, 'label' => 'sylius.form.taxon.parent', 'empty_value' => '---', 'auto_initialize' => false)));
 }
示例#10
0
 /**
  * Return the populated entity if everything is ok,
  * if the data is not valid will throw a FormValidationException
  *
  * @param $formServiceName
  * @param $entityToPopulate
  *
  * @return FormInterface
  */
 public function populateEntityFromRequest($formServiceName, $entityToPopulate, $nameForm = '')
 {
     $form = $this->formFactory->createNamed($nameForm, $formServiceName, $entityToPopulate);
     $form->handleRequest($this->requestStack->getCurrentRequest());
     if (!$form->isSubmitted()) {
         $form->submit([]);
     }
     return $form;
 }
 /**
  * @param Request $request
  * @return View
  */
 private function processForm(Request $request)
 {
     $form = $this->formFactory->createNamed('', 'user_search');
     $form->handleRequest($request);
     if (!$form->isEmpty() && !$form->isValid()) {
         return new View($form, 400);
     }
     return new View($this->useCase->listUsers($form->getData()), 200);
 }
 /**
  * {@inheritdoc}
  */
 public function createForm(array $options = [], $data = null)
 {
     $options = array_merge(['validation_groups' => $this->validationGroups], $options);
     $form = $this->formFactory->createNamed($this->name, $this->type, null, $options);
     if (null !== $data) {
         $form->setData($data);
     }
     return $form;
 }
示例#13
0
 /**
  * {@inheritdoc}
  */
 public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource)
 {
     $formType = $requestConfiguration->getFormType();
     $formOptions = $requestConfiguration->getFormOptions();
     if ($requestConfiguration->isHtmlRequest()) {
         return $this->formFactory->create($formType, $resource, $formOptions);
     }
     return $this->formFactory->createNamed('', $formType, $resource, array_merge($formOptions, ['csrf_protection' => false]));
 }
 /**
  * @param User $user
  * @param Request $request
  * @return View
  */
 private function processForm(User $user, Request $request)
 {
     $form = $this->formFactory->createNamed('', 'user_create', $user);
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return new View($form, 400);
     }
     $this->useCase->createUser($user, false);
     return new View($user, 201, ['Location' => $this->router->generate('arkon_user_getUser', ['id' => $user->getId()], true)]);
 }
 /**
  * @param FormEvent $event
  */
 public function addConfigurationFields(FormEvent $event)
 {
     $attribute = $event->getData();
     $form = $event->getForm();
     try {
         $requiredFields = $this->factory->createNamed('configuration', 'sylius_attribute_type_configuration_' . $attribute->getType(), null, ['auto_initialize' => false, 'label' => 'sylius.form.attribute_type.configuration']);
         $form->add($requiredFields);
     } catch (InvalidArgumentException $exception) {
     }
 }
示例#16
0
 /**
  * Checkt form fields by PRE_SET_DATA FormEvent
  *
  * @param FormEvent $event
  */
 public function preSetData(FormEvent $event)
 {
     $user = $event->getData();
     if (null === $user) {
         return;
     }
     if ($this->currentUser !== null && $this->currentUser !== $user) {
         $event->getForm()->add($this->factory->createNamed('activated', 'checkbox', null, array('data' => $user->getRegistrationToken() ? false : true, 'auto_initialize' => false, 'label' => 'Activated', 'required' => false, 'mapped' => false)));
     }
 }
 /**
  * On PreSetDate event handler
  *
  * @param FormEvent $event
  */
 public function onPreSetData(FormEvent $event)
 {
     $form = $event->getForm();
     $data = $event->getData();
     if (null === $data) {
         return;
     }
     $transferCustodian = $data->getTransferCustodian();
     $form->add($this->factory->createNamed('transfer_custodian_id', 'hidden', null, array('data' => $transferCustodian ? $transferCustodian->getId() : null, 'property_path' => false)))->add($this->factory->createNamed('is_firm_not_appear', 'checkbox', null, array('mapped' => false, 'data' => $transferCustodian ? false : true, 'required' => false)));
 }
 /**
  * @param PhoneNumber $phoneNumber
  * @param Request $request
  * @return View
  */
 private function processForm(PhoneNumber $phoneNumber, Request $request)
 {
     $form = $this->formFactory->createNamed('', 'phone_number_edit', $phoneNumber);
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return new View($form, 400);
     }
     $this->useCase->editPhoneNumber($phoneNumber, false);
     return new View($phoneNumber, 200);
 }
示例#19
0
 /**
  * Creates new entity
  *
  * @return mixed
  */
 public function execute()
 {
     $form = $this->formFactory->createNamed('', $this->type, $this->object);
     $form->handleRequest($this->stack->getCurrentRequest());
     if ($form->isValid()) {
         $this->postUpdate($this->object);
         return $this->object;
     }
     return $form;
 }
示例#20
0
 /**
  * {@inheritdoc}
  */
 public function create(RequestConfiguration $requestConfiguration, ResourceInterface $resource)
 {
     $formType = $requestConfiguration->getFormType();
     if (false !== strpos($formType, '\\')) {
         $formType = new $formType();
     }
     if ($requestConfiguration->isHtmlRequest()) {
         return $this->formFactory->create($formType, $resource);
     }
     return $this->formFactory->createNamed('', $formType, $resource, ['csrf_protection' => false]);
 }
 /**
  * @param PhoneNumber $number
  * @param User $user
  * @param Request $request
  * @return View
  */
 private function processForm(PhoneNumber $number, User $user, Request $request)
 {
     $number->setOwner($user);
     $form = $this->formFactory->createNamed('phoneNumber', 'phone_number_add', $number);
     $form->handleRequest($request);
     if (!$form->isValid()) {
         return new View($form, 400);
     }
     $this->useCase->addNumberToUser($number, $user, false);
     return new View($number, 201, ['Location' => $this->router->generate('arkon_phonebook_get_user_number', ['id' => $user->getId(), 'numberId' => $number->getId()], true)]);
 }
 /**
  * Add configuration fields to the form
  *
  * @param FormInterface $form
  * @param string        $rendererType
  * @param array         $data
  */
 public function addConfigurationFields(FormInterface $form, $rendererType, array $data = array())
 {
     $renderer = $this->rendererRegistry->get($rendererType);
     $formType = sprintf('sylius_renderer_%s', $renderer->getType());
     try {
         $configurationField = $this->factory->createNamed('rendererConfiguration', $formType, $data, array('auto_initialize' => false));
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
 /**
  * Add configuration fields to the form.
  *
  * @param FormInterface $form
  * @param string        $calculatorType
  * @param array         $data
  */
 protected function addConfigurationFields(FormInterface $form, $calculatorType, array $data = array())
 {
     $calculator = $this->calculatorRegistry->get($calculatorType);
     $formType = sprintf('sylius_price_calculator_%s', $calculator->getType());
     try {
         $configurationField = $this->factory->createNamed('pricingConfiguration', $formType, $data, array('auto_initialize' => false));
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
 /**
  * Builds choices for attribute form.
  *
  * @param FormEvent $event
  */
 public function buildChoices(FormEvent $event)
 {
     $attribute = $event->getData();
     if (null === $attribute) {
         return;
     }
     $type = $attribute->getType();
     if (null === $type || AttributeTypes::CHOICE === $type) {
         $event->getForm()->add($this->factory->createNamed('choices', 'collection', null, array('type' => 'text', 'allow_add' => true, 'allow_delete' => true, 'by_reference' => false)));
     }
 }
 /**
  * Add configuration fields to the form.
  *
  * @param FormInterface $form
  * @param string        $dataFetcherType
  * @param array         $config
  */
 protected function addConfigurationFields(FormInterface $form, $dataFetcherType, array $config = [])
 {
     $dataFetcher = $this->dataFecherRegistry->get($dataFetcherType);
     $formType = $dataFetcher->getType();
     try {
         $configurationField = $this->factory->createNamed('dataFetcherConfiguration', $formType, $config, ['auto_initialize' => false]);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
示例#26
0
 /**
  * Creates new entity
  *
  * @return FormInterface
  */
 public function execute()
 {
     $form = $this->formFactory->createNamed('', $this->type);
     $form->handleRequest($this->stack->getCurrentRequest());
     if ($form->isValid()) {
         $object = $form->getData();
         $this->repository->add($object);
         $this->postCreate($object);
         return $object;
     }
     return $form;
 }
 /**
  * Add configuration fields to the form.
  *
  * @param FormInterface $form
  * @param string        $rendererType
  * @param array         $data
  */
 public function addConfigurationFields(FormInterface $form, $rendererType, array $data = [])
 {
     /** @var RendererInterface $renderer */
     $renderer = $this->rendererRegistry->get($rendererType);
     $formType = $renderer->getType();
     try {
         $configurationField = $this->factory->createNamed('rendererConfiguration', $formType, $data, ['auto_initialize' => false]);
     } catch (\InvalidArgumentException $e) {
         return;
     }
     $form->add($configurationField);
 }
示例#28
0
 /**
  * 
  * @return \Symfony\Component\Form\Form 
  */
 public function createForm()
 {
     $type = $this->userDiscriminator->getFormType($this->type);
     $name = $this->userDiscriminator->getFormName($this->type);
     $validationGroups = $this->userDiscriminator->getFormValidationGroups($this->type);
     if (array_key_exists($name, $this->forms)) {
         return $this->forms[$name];
     }
     $form = $this->formFactory->createNamed($name, $type, null, array('validation_groups' => $validationGroups));
     $this->forms[$name] = $form;
     return $form;
 }
示例#29
-1
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function loginAction(Request $request)
 {
     $lastError = $this->authenticationUtils->getLastAuthenticationError();
     $lastUsername = $this->authenticationUtils->getLastUsername();
     $template = $request->attributes->get('_sylius[template]', 'SyliusUiBundle:Security:login.html.twig', true);
     $formType = $request->attributes->get('_sylius[form]', 'sylius_security_login', true);
     $form = $this->formFactory->createNamed('', $formType);
     return $this->templatingEngine->renderResponse($template, ['form' => $form->createView(), 'last_username' => $lastUsername, 'last_error' => $lastError]);
 }
示例#30
-1
 /**
  * @param Request $request
  *
  * @return Response
  */
 public function loginAction(Request $request)
 {
     $lastError = $this->authenticationUtils->getLastAuthenticationError();
     $lastUsername = $this->authenticationUtils->getLastUsername();
     $options = $request->attributes->get('_sylius');
     $template = isset($options['template']) ? $options['template'] : 'SyliusUiBundle:Security:login.html.twig';
     $formType = isset($options['form']) ? $options['form'] : SecurityLoginType::class;
     $form = $this->formFactory->createNamed('', $formType);
     return $this->templatingEngine->renderResponse($template, ['form' => $form->createView(), 'last_username' => $lastUsername, 'last_error' => $lastError]);
 }