/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('subject', 'text', ['required' => true, 'label' => 'orocrm.call.subject.label'])->add('phoneNumber', 'orocrm_call_phone', ['required' => true, 'label' => 'orocrm.call.phone_number.label', 'suggestions' => $options['phone_suggestions']])->add('notes', 'oro_resizeable_rich_text', ['required' => false, 'label' => 'orocrm.call.notes.label'])->add('callDateTime', 'oro_datetime', ['required' => true, 'label' => 'orocrm.call.call_date_time.label'])->add('callStatus', 'entity', ['required' => true, 'label' => 'orocrm.call.call_status.label', 'class' => 'OroCRM\\Bundle\\CallBundle\\Entity\\CallStatus'])->add('duration', 'oro_time_interval', ['required' => false, 'label' => 'orocrm.call.duration.label'])->add('direction', 'translatable_entity', ['required' => true, 'label' => 'orocrm.call.direction.label', 'class' => 'OroCRM\\Bundle\\CallBundle\\Entity\\CallDirection']); if ($builder->has('contexts')) { $builder->addEventListener(FormEvents::POST_SET_DATA, [$this, 'addPhoneContextListener']); } }
/** * @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(); }
/** * addHiddenValues * @param FormBuilderInterface $builder * @return FormBuilderInterface */ public function addHiddenValues(FormBuilderInterface $builder) { $data = array(); $nom = 'hiddenData'; foreach ($this->parametres as $key => $value) { if (is_string($value) || is_array($value) || is_bool($value)) { $data[$key] = $value; } } if ($builder->has($nom)) { $builder->remove($nom); } $builder->add($nom, 'hidden', array('data' => urlencode(json_encode($data, true)), 'mapped' => false)); return $builder; }
public function buildForm(FormBuilderInterface $builder, array $options) { if (!$builder->has('basic')) { return; } $basic = $builder->get('basic'); /* * Don't require current password. */ if ($basic->has('current_password')) { $basic->remove('current_password'); } /* * This subscriber will require / unrequire the plainPassword field * depending on if it's a new user or existing. */ $builder->addEventSubscriber(new UserTypeSubscriber()); }
public function buildForm(FormBuilderInterface $builder, array $options) { $event = new GadgetFormBuilderEvent($builder, $this->request, $this->gadget); $this->dispatcher->dispatch(KeosuEvents::GADGET_CONF_FORM_BUILD . $this->gadget->getName(), $event); if (!$event->isOverrideForm()) { $config = $this->packageManager->getConfigPackage($this->gadget->getName()); if (isset($config['param'])) { $params = $config['param']; foreach ($params as $p) { if ($builder->has($p['name'])) { throw new \LogicException('The property ' . $p['name'] . ' already exists, maybe you forgot to enable overrideForm ?'); } if (isset($p['options'])) { $builder->add($p['name'], $p['type'], $p['options']); } else { $builder->add($p['name'], $p['type']); } } } } }
/** * {@inheritdoc} */ public function has($key) { return $this->formBuilder->has($key); }
private function getPersonForm(FormBuilderInterface $formBuilder, Person $person) { if ($formBuilder->has('person') === false) { $formBuilder->add('person', new DynamicPersonType(), array('label' => false)); } return $formBuilder->get('person'); }