add() public method

Adds a child to the form.
public add ( Symfony\Component\Form\FormInterface $child ) : Form
$child Symfony\Component\Form\FormInterface The FormInterface to add as a child
return Form the current form
 protected function addField(Form $form, $municipio)
 {
     $formOptions = array('class' => 'SiSuCuentaBundle:Parroquia', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_parroquia'), 'required' => true, 'label' => 'Parroquia', 'query_builder' => function (EntityRepository $er) use($municipio) {
         return $er->createQueryBuilder('parroquia')->where('parroquia.municipio = :municipio')->setParameter('municipio', $municipio);
     });
     $form->add('parroquia', 'entity', $formOptions);
 }
 private function createLoginForm($operator = null)
 {
     $form = new Form('login', array('validator' => $this->get('validator')));
     $form->add(new TextField('email'));
     $form->add(new PasswordField('passwd'));
     return $form;
 }
 /**
  * @param TranslatableLabel $label
  * @param Form $form
  */
 protected function managePlural($label, $message, $form, $locale)
 {
     $labelManager = $this->labelManager;
     $explicitRules = array();
     $standardRules = array();
     $labelManager->getPluralForms($message, $standardRules, $explicitRules);
     for ($i = 0; $i < max(2, count($standardRules)); $i++) {
         $form->add(self::PLURAL_FIELD_PREFIX . $i, $labelManager->getValueFieldType($label), array('required' => false, 'label' => sprintf('bigfoot_core.translatable_label.plural.standard_%s', $i), 'data' => isset($standardRules[$i]) ? $standardRules[$i] : '', 'mapped' => false, 'attr' => array('data-locale' => $locale)));
     }
     foreach ($explicitRules as $interval => $value) {
         $form->add(self::PLURAL_FIELD_PREFIX . $labelManager->transformInterval($interval), $labelManager->getValueFieldType($label), array('required' => false, 'label' => $this->translator->trans('bigfoot_core.translatable_label.plural.explicit', array('%interval%' => $interval)), 'data' => $value, 'mapped' => false, 'attr' => array('data-locale' => $locale)));
     }
 }
Example #4
0
 /**
  * {@inheritDoc}
  *
  * @throws FormException  When the field is in mode HybridField::FIELD adding
  *                        subfields is not allowed
  */
 public function add($field)
 {
     if ($this->mode === self::FIELD) {
         throw new FormException('You cannot add nested fields while in mode FIELD');
     }
     return parent::add($field);
 }
Example #5
0
 public function testCollectSubmittedDataExpandedFormsErrors()
 {
     $child1Form = $this->createForm('child1');
     $child11Form = $this->createForm('child11');
     $child2Form = $this->createForm('child2');
     $child21Form = $this->createForm('child21');
     $child1Form->add($child11Form);
     $child2Form->add($child21Form);
     $this->form->add($child1Form);
     $this->form->add($child2Form);
     $this->dataExtractor->method('extractConfiguration')->will($this->returnValue(array()));
     $this->dataExtractor->method('extractDefaultData')->will($this->returnValue(array()));
     $this->dataExtractor->expects($this->at(10))->method('extractSubmittedData')->with($this->form)->will($this->returnValue(array('errors' => array())));
     $this->dataExtractor->expects($this->at(11))->method('extractSubmittedData')->with($child1Form)->will($this->returnValue(array('errors' => array())));
     $this->dataExtractor->expects($this->at(12))->method('extractSubmittedData')->with($child11Form)->will($this->returnValue(array('errors' => array('foo'))));
     $this->dataExtractor->expects($this->at(13))->method('extractSubmittedData')->with($child2Form)->will($this->returnValue(array('errors' => array())));
     $this->dataExtractor->expects($this->at(14))->method('extractSubmittedData')->with($child21Form)->will($this->returnValue(array('errors' => array())));
     $this->dataCollector->collectSubmittedData($this->form);
     $this->dataCollector->buildPreliminaryFormTree($this->form);
     $data = $this->dataCollector->getData();
     $formData = $data['forms']['name'];
     $child1Data = $formData['children']['child1'];
     $child11Data = $child1Data['children']['child11'];
     $child2Data = $formData['children']['child2'];
     $child21Data = $child2Data['children']['child21'];
     $this->assertTrue($formData['has_children_error']);
     $this->assertTrue($child1Data['has_children_error']);
     $this->assertFalse(isset($child11Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
     $this->assertFalse($child2Data['has_children_error']);
     $this->assertFalse(isset($child21Data['has_children_error']), 'The leaf data does not contains "has_children_error" property.');
 }
Example #6
0
 /**
  * @param FormBuilder|Form $builder
  */
 public function appendToForm(&$builder, $data, $formArea)
 {
     if ($formArea == 'features') {
         $name = strtolower($this->getName());
         if ($this->factory->serviceExists('mautic.form.type.social.' . $name)) {
             $builder->add('shareButton', 'socialmedia_' . $name, array('label' => 'mautic.integration.form.sharebutton', 'required' => false, 'data' => isset($data['shareButton']) ? $data['shareButton'] : array()));
         }
     }
 }
 protected function addFields(Form $form)
 {
     foreach ($this->elementsFrom as $element) {
         $options = $this->createOptionsFor($element);
         $name = $this->encodeFieldname($options['label']);
         $form->add($name, $this->attributes['type'], $options);
     }
     return $form;
 }
 protected function addField(Form $form, $estado)
 {
     // actualizamos el campo municipio, pasandole el estado a la opción
     // query_builder, para que el dql tome en cuenta el estado
     // y filtre la consulta por su valor.
     $formOptions = array('class' => 'SiSuCuentaBundle:Municipio', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_municipio'), 'required' => true, 'label' => 'Municipio', 'query_builder' => function (EntityRepository $er) use($estado) {
         return $er->createQueryBuilder('municipio')->where('municipio.estado = :estado')->setParameter('estado', $estado);
     });
     $form->add('municipio', 'entity', $formOptions);
 }
 public function testFinalFormReliesOnFormViewStructure()
 {
     $this->form->add($this->createForm('first'));
     $this->form->add($this->createForm('second'));
     $this->view->children['second'] = $this->childView;
     $this->dataCollector->buildPreliminaryFormTree($this->form);
     $this->assertSame(array('forms' => array('name' => array('children' => array('first' => array('children' => array()), 'second' => array('children' => array())))), 'nb_errors' => 0), $this->dataCollector->getData());
     $this->dataCollector->buildFinalFormTree($this->form, $this->view);
     $this->assertSame(array('forms' => array('name' => array('children' => array('second' => array('children' => array())))), 'nb_errors' => 0), $this->dataCollector->getData());
 }
Example #10
0
 /**
  * Add a field (in form of an array) to $_form
  * Sets the required option to what is defined in the validator.
  *
  * @param array $fieldArray Array consisting of child, type and options(inc. label) for the field
  *
  * @return Handler          Returns $this for chainability
  */
 protected function _addFieldToSymfonyForm(&$fieldArray)
 {
     $validatorField = $this->getValidator()->getField($this->_getChildName($fieldArray['child']));
     $fieldArray['options']['required'] = !$validatorField->optional;
     if ($this->_repeatable) {
         $this->_addCollection($fieldArray['child'], $fieldArray['type'], $fieldArray['options']);
     } else {
         $this->_form->add($fieldArray['child'], $fieldArray['type'], $fieldArray['options']);
     }
 }
 public function __construct(Form $form, Request $request, UserManagerInterface $userManager)
 {
     // borrando campos no necesarios
     $form->remove('gender');
     $form->remove('website');
     $form->remove('biography');
     $form->remove('timezone');
     $form->remove('phone');
     $form->remove('locale');
     $form->remove('dateOfBirth');
     // cargando nuevos campos
     $form->add('username', null, array('label' => 'Name of User'));
     $form->add('email');
     $form->add('organization');
     //        $form->add('gravatar', 'file', array(
     //        'mapped' => false,
     //        'attr' => ['class' => 'filestyle','data-buttonBefore'=> 'true', 'data-buttonText' => 'Choose file' ]
     //    ));
     parent::__construct($form, $request, $userManager);
 }
 /**
  * @param Form   $form         Main form.
  * @param string $providerName Provider.
  */
 protected function buildTypeSettingsForm(Form $form, $providerName)
 {
     // create sub-form wrapper
     $subForm = $form->getConfig()->getFormFactory()->createNamed('properties', 'form', null, array('label' => false, 'auto_initialize' => false));
     //Add provider form
     if ($providerName && isset($this->providers[$providerName])) {
         $provider = $this->providers[$providerName];
         // delegate form structure building for specific provider
         $provider->buildForm($subForm);
     }
     $form->add($subForm);
 }
 public function addField(Form $form, $parser = null)
 {
     if ($parser === null) {
         return false;
     }
     $options = $form->getConfig()->getOptions();
     $em = $options['em'];
     if (!$parser instanceof Newscoop\IngestPluginBundle\Entity\Parser) {
         $parser = $em->getRepository('Newscoop\\IngestPluginBundle\\Entity\\Parser')->findOneById($parser);
     }
     if ($parser->requiresUrl()) {
         $form->add('url', 'url', array('label' => 'plugin.ingest.feeds.url', 'required' => true));
     }
 }
Example #14
0
 public function testRemoveFields()
 {
     $dataMapper = $this->getMock('Symfony\\Component\\Form\\DataMapperInterface');
     $config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $config->expects($this->any())->method('getName')->will($this->returnValue('root'));
     $config->expects($this->any())->method('getCompound')->will($this->returnValue(true));
     $config->expects($this->any())->method('getDataMapper')->will($this->returnValue($dataMapper));
     $form = new Form($config);
     $config = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface');
     $config->expects($this->any())->method('getName')->will($this->returnValue('child'));
     $form->add(new Form($config));
     FormHelper::removeFields(array(), $form);
     $this->assertFalse(isset($form['child']));
 }
 /**
  * @param FormBuilder|Form $builder
  */
 public function appendToForm(&$builder, $data, $formArea)
 {
     if ($formArea == 'features' || $formArea == 'integration') {
         if ($this->isAuthorized()) {
             $name = strtolower($this->getName());
             if ($this->factory->serviceExists('mautic.form.type.emailmarketing.' . $name)) {
                 if ($formArea == 'integration' && isset($data['leadFields']) && empty($data['list_settings']['leadFields'])) {
                     $data['list_settings']['leadFields'] = $data['leadFields'];
                 }
                 $builder->add('list_settings', 'emailmarketing_' . $name, array('label' => false, 'form_area' => $formArea, 'data' => isset($data['list_settings']) ? $data['list_settings'] : array()));
             }
         }
     }
 }
 public function testFinalFormReliesOnFormViewStructure()
 {
     $this->form->add($child1 = $this->createForm('first'));
     $this->form->add($child2 = $this->createForm('second'));
     $this->view->children['second'] = $this->childView;
     $this->dataCollector->buildPreliminaryFormTree($this->form);
     $child1Data = array('children' => array());
     $child2Data = array('children' => array());
     $formData = array('children' => array('first' => $child1Data, 'second' => $child2Data));
     $this->assertSame(array('forms' => array('name' => $formData), 'forms_by_hash' => array(spl_object_hash($this->form) => $formData, spl_object_hash($child1) => $child1Data, spl_object_hash($child2) => $child2Data), 'nb_errors' => 0), $this->dataCollector->getData());
     $this->dataCollector->buildFinalFormTree($this->form, $this->view);
     $formData = array('children' => array('second' => $child2Data));
     $this->assertSame(array('forms' => array('name' => $formData), 'forms_by_hash' => array(spl_object_hash($this->form) => $formData, spl_object_hash($child1) => $child1Data, spl_object_hash($child2) => $child2Data), 'nb_errors' => 0), $this->dataCollector->getData());
 }
 protected function initForm()
 {
     $filters = array();
     if ($this->request->cookies->get('filters')) {
         $filters = unserialize($this->request->cookies->get('filters'));
     }
     $date = null;
     if (isset($filters['date'])) {
         $date = $filters['date'];
     }
     $this->form = $this->createFormBuilder();
     $this->form->setAction($this->generateUrl('datapresentation_filter_set'))->add('siteId', 'text', array('required' => false, 'attr' => array('value' => isset($filters['siteId']) ? $filters['siteId'] : '')))->add('userId', 'text', array('required' => false, 'attr' => array('value' => isset($filters['userId']) ? $filters['userId'] : '')))->add('customerId', 'text', array('required' => false, 'attr' => array('value' => isset($filters['customerId']) ? $filters['customerId'] : '')))->add('productId', 'text', array('required' => false, 'attr' => array('value' => isset($filters['productId']) ? $filters['productId'] : '')))->add('host', 'text', array('required' => false, 'attr' => array('value' => isset($filters['host']) ? $filters['host'] : '')))->add('page', 'text', array('required' => false, 'attr' => array('value' => isset($filters['page']) ? $filters['page'] : '')))->add('pageType', 'text', array('required' => false, 'attr' => array('value' => isset($filters['pageType']) ? $filters['pageType'] : '')))->add('event', 'text', array('required' => false, 'attr' => array('value' => isset($filters['event']) ? $filters['event'] : '')))->add('date', 'date', array('required' => false, 'input' => 'datetime', 'widget' => 'text', 'data' => $date, 'attr' => array('class' => 'date-input')))->add('today', 'checkbox', array('required' => false, 'attr' => array('class' => 'checkbox-input')));
     $this->form->add('save', 'submit', array('label' => ' ', 'attr' => array('class' => 'green-button fa fa-list fa-lg', 'title' => 'filter')));
     $this->form = $this->form->getForm()->handleRequest($this->request);
     $this->formView = $this->form->createView();
 }
Example #18
0
    public function getForm()
    {
        $instance = new Form(
            $this->getName(),
            $this->buildDispatcher(),
            $this->getTypes(),
            $this->getClientTransformers(),
            $this->getNormTransformers(),
            $this->getDataMapper(),
            $this->getValidators(),
            $this->getRequired(),
            $this->getReadOnly(),
            $this->getErrorBubbling(),
            $this->getEmptyData(),
            $this->getAttributes()
        );

        foreach ($this->buildChildren() as $child) {
            $instance->add($child);
        }

        if ($this->getData()) {
            $instance->setData($this->getData());
        }

        return $instance;
    }
Example #19
0
 public function testFormErrorsWithNonFormComponents()
 {
     if (!class_exists('Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType')) {
         $this->markTestSkipped('Not using Symfony Form >= 2.3 with submit type');
     }
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $factoryBuilder = new FormFactoryBuilder();
     $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\SubmitType());
     $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\ButtonType());
     $factory = $factoryBuilder->getFormFactory();
     $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher);
     $formConfigBuilder->setFormFactory($factory);
     $formConfigBuilder->setCompound(true);
     $formConfigBuilder->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface'));
     $fooConfig = $formConfigBuilder->getFormConfig();
     $form = new Form($fooConfig);
     $form->add('save', 'submit');
     try {
         $this->serialize($form);
     } catch (\Exception $e) {
         $this->assertTrue(false, 'Serialization should not throw an exception');
     }
 }
Example #20
0
 public function testMultipartFormsWithParentsRequireNoFiles()
 {
     $form = new Form('author', new Author(), $this->validator);
     $form->add($this->createMultipartMockField('file'));
     $form->setParent($this->createMockField('group'));
     // files are expected to be converted by the parent
     $form->bind(array('file' => 'test.txt'));
 }
Example #21
0
 /**
  * Create a group containing two fields, "visibleField" and "hiddenField"
  *
  * @return Form
  */
 protected function getGroupWithBothVisibleAndHiddenField()
 {
     $form = new Form('testGroup');
     // add a visible field
     $visibleField = $this->createMockField('visibleField');
     $visibleField->expects($this->once())->method('isHidden')->will($this->returnValue(false));
     $form->add($visibleField);
     // add a hidden field
     $hiddenField = $this->createMockField('hiddenField');
     $hiddenField->expects($this->once())->method('isHidden')->will($this->returnValue(true));
     $form->add($hiddenField);
     return $form;
 }
Example #22
0
 /**
  * {@inheritdoc}
  */
 public function getForm()
 {
     if ($this->locked) {
         throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
     }
     $this->resolveChildren();
     $form = new Form($this->getFormConfig());
     foreach ($this->children as $child) {
         // Automatic initialization is only supported on root forms
         $form->add($child->setAutoInitialize(false)->getForm());
     }
     if ($this->getAutoInitialize()) {
         // Automatically initialize the form if it is configured so
         $form->initialize();
     }
     return $form;
 }
Example #23
0
 /**
  * {@inheritdoc}
  */
 public function getForm()
 {
     $this->resolveChildren();
     $form = new Form($this->getFormConfig());
     foreach ($this->children as $child) {
         $form->add($child->getForm());
     }
     return $form;
 }
 public function testNestedFormErrors()
 {
     $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface');
     $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher);
     $formConfigBuilder->setCompound(true);
     $formConfigBuilder->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface'));
     $fooConfig = $formConfigBuilder->getFormConfig();
     $form = new Form($fooConfig);
     $form->addError(new FormError('This is the form error'));
     $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('bar', null, $dispatcher);
     $barConfig = $formConfigBuilder->getFormConfig();
     $child = new Form($barConfig);
     $child->addError(new FormError('Error of the child form'));
     $form->add($child);
     $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
 }
 /**
  * Disable a field from its name
  *
  * @param Form   $form Form
  * @param string $name Field name
  */
 protected function disableField(Form $form, $name)
 {
     // get form field and properties
     $formField = $form->get($name);
     $type = $formField->getConfig()->getType();
     $options = $formField->getConfig()->getOptions();
     // replace by disabled and read-only
     $options['disabled'] = true;
     $options['read_only'] = true;
     $options['auto_initialize'] = false;
     $formField = $this->factory->createNamed($name, $type, null, $options);
     $form->add($formField);
 }
Example #26
0
 public function testFieldsInitializedWithDataAreNotUpdatedWhenAddedToForms()
 {
     $author = new Author();
     $author->firstName = 'Bernhard';
     $field = new TestField('firstName', array('data' => 'foobar'));
     $form = new Form('author', array('data' => $author));
     $form->add($field);
     $this->assertEquals('foobar', $field->getData());
 }
 /**
  * @param Form $form
  */
 protected function updateDefaultTree(Form $form)
 {
     $form->add('defaultTree', 'entity', array('class' => $this->categoryClass, 'property' => 'label', 'select2' => true, 'query_builder' => function (EntityRepository $repository) {
         return $repository->getTreesQB();
     }));
 }
 /**
  * {@inheritDoc}
  */
 public function buildForm(Form $form)
 {
     $form->add('host', 'text', array('constraints' => array(new Type(array('type' => 'string')))))->add('username', 'text', array('required' => false))->add('password', 'text', array('required' => false))->add('create', new CheckboxType(), array('required' => false, 'constraints' => array(new Type(array('type' => 'bool')))))->add('mode', 'choice', array('required' => false, 'choices' => array(1 => 'ASCII', 2 => 'Binary')))->add('passive', new CheckboxType(), array('required' => false, 'constraints' => array(new Type(array('type' => 'bool')))))->add('ssl', new CheckboxType(), array('required' => false, 'constraints' => array(new Type(array('type' => 'bool')))));
 }
 protected function addField(Form $form, $estado = null)
 {
     $formOptions = array('class' => 'SiSuCuentaBundle:Estado', 'empty_value' => '-- Seleccionar --', 'attr' => array('class' => 'usuario_estado'), 'required' => true, 'label' => 'Estado');
     $form->add('estado', 'entity', $formOptions);
 }
Example #30
0
 public function buildForm(Form $form)
 {
     $form->add('content', 'textarea', ['mapped' => false]);
     return $form;
 }