public function formExtensions(Container $c, FormFactoryBuilderInterface $builder) { $builder->addExtension(new ValidatorExtension($c['validator'])); if (isset($c['translator']) && method_exists($c['translator'], 'addResource')) { $r = new \ReflectionClass('Symfony\\Component\\Form\\Form'); $c['translator']->addResource('xliff', dirname($r->getFilename()) . '/Resources/translations/validators.' . $c['locale'] . '.xlf', $c['locale'], 'validators'); } }
private function addExtensions() { // Create CsrfTokenManager $csrfTokenManager = new CsrfTokenManager(); // List of extensions for app's FormFactory $extensions = [$this->getCsrfExtension($csrfTokenManager), $this->getValidatorExtension()]; // Load extensions from the list foreach ($extensions as $extension) { $this->formFactoryBuilder->addExtension($extension); } // Extend Twig for proper work with FormFactory $this->extendTwig($csrfTokenManager); }
/** * @param Request $request * @param string $type * @param array $data * @param array $options * @param ContainerInterface $container * @deprecated Thelia forms should not be instantiated directly. Please use BaseController::createForm() instead * @see BaseController::createForm() */ public function __construct(Request $request, $type = "form", $data = array(), $options = array(), ContainerInterface $container = null) { // Generate the form name from the complete class name $this->formUniqueIdentifier = strtolower(str_replace('\\', '_', get_class($this))); $this->request = $request; $this->type = $type; if (null !== $container) { $this->container = $container; $this->dispatcher = $container->get("event_dispatcher"); $this->initFormWithContainer($type, $data, $options); } else { $this->initFormWithRequest($type, $data, $options); } if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) { $this->formFactoryBuilder->addExtension(new CsrfExtension(new CsrfTokenManager(null, new SessionTokenStorage($this->getRequest()->getSession())))); } $this->formBuilder = $this->formFactoryBuilder->addExtension(new ValidatorExtension($this->validatorBuilder->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options)); /** * Build the form */ $name = $this->getName(); $event = null; $dispatchEvents = $this->hasContainer() && $name !== null && $name !== ''; // We need to wrap the dispatch with a condition for backward compatibility if ($dispatchEvents) { $event = new TheliaFormEvent($this); /** * If the form has the container, disptach the events */ $this->dispatcher->dispatch(TheliaEvents::FORM_BEFORE_BUILD . "." . $name, $event); } $this->buildForm(); if ($dispatchEvents) { /** * If the form has the container, disptach the events */ $this->dispatcher->dispatch(TheliaEvents::FORM_AFTER_BUILD . "." . $name, $event); } // If not already set, define the success_url field // This field is not included in the standard form hidden fields // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('success_url')) { $this->formBuilder->add("success_url", "hidden"); } // If not already set, define the error_url field // This field is not included in the standard form hidden fields // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('error_url')) { $this->formBuilder->add("error_url", "hidden"); } // The "error_message" field defines the error message displayed if // the form could not be validated. If it is empty, a standard error message is displayed instead. // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('error_message')) { $this->formBuilder->add("error_message", "hidden"); } $this->form = $this->formBuilder->getForm(); }
public function testExtraViewChild() { $view = $this->factoryBuilder->addTypeExtension(new ExtraViewChildrenExtension(array('extra1', 'extra2')))->getFormFactory()->createBuilder()->add('foo', 'form', array('position' => 'last'))->add('bar', 'form', array('position' => 'first'))->getForm()->createView(); $this->assertPositions($view, array('bar', 'foo', 'extra1', 'extra2')); }
public function formExtensions(Container $c, FormFactoryBuilderInterface $builder) { $builder->addExtensions(array($c['form.extension.csrf'], new HttpFoundationExtension()))->setResolvedTypeFactory($c['form.resolved_type_factory']); }