public function buildForm(FormBuilder $builder, array $options) { $builder->add('firstname', 'text', array('label' => 'form.label.firstname'))->add('lastname', 'text', array('label' => 'form.label.lastname'))->add('states', 'choice', array('choices' => array('foo' => 'bar'), 'empty_value' => 'form.states.empty_value'))->add('countries', 'choice', array('empty_value' => false))->add('password', 'repeated', array('first_options' => array('label' => 'form.label.password'), 'second_options' => array('label' => 'form.label.password_repeated'), 'invalid_message' => 'form.error.password_mismatch'))->add('street', 'text', array('label' => 'form.label.street', 'translation_domain' => 'address'))->add('zip', 'text', array('label' => 'form.label.zip', 'translation_domain' => 'address'))->add('field_with_placeholder', 'text', array('label' => 'field.with.placeholder', 'attr' => array('placeholder' => 'form.placeholder.text')))->add('field_without_label', 'text', array('label' => false, 'attr' => array('placeholder' => 'form.placeholder.text.but.no.label'))); $child = $builder->create('created', 'text', array('label' => 'form.label.created')); $builder->add('dueDate', 'date', array('empty_value' => array('year' => 'form.dueDate.empty.year', 'month' => 'form.dueDate.empty.month', 'day' => 'form.dueDate.empty.day'))); $builder->add('field_with_ignored_label', 'text', array('label' => 'form.ignored')); }
/** * {@inheritdoc} */ public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create('$$' . $options['prototype_name'] . '$$', $options['type'], $options['options']); $builder->setAttribute('prototype', $prototype->getForm()); } $listener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']); $builder->addEventSubscriber($listener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']); }
public function buildForm(FormBuilder $builder, array $options) { $child = $builder->create('user', 'form', array('data_class' => $this->class)); $this->buildUserForm($child, $options); $builder ->add($child) ->add('current', 'password') ; }
/** * Returns the field associated to a FieldDescriptionInterface * ie : build the embedded form from the related AdminInterface instance * * @throws RuntimeException * @param \Symfony\Component\Form\FormBuilder $formBuilder * @param \Sonata\AdminBundle\Admin\FieldDescriptionInterface $fieldDescription * @param null $fieldName * @return FieldGroup */ protected function defineChildFormBuilder(FormBuilder $formBuilder, FieldDescriptionInterface $fieldDescription, $fieldName = null) { $fieldName = $fieldName ?: $fieldDescription->getFieldName(); $associatedAdmin = $fieldDescription->getAssociationAdmin(); if (!$associatedAdmin) { throw new \RuntimeException(sprintf('inline mode for field `%s` required an Admin definition', $fieldName)); } // retrieve the related object $childBuilder = $formBuilder->create($fieldName, 'sonata_type_admin', array('field_description' => $fieldDescription)); $formBuilder->add($childBuilder); $associatedAdmin->defineFormBuilder($childBuilder); }
/** * {@inheritdoc} */ public function buildForm(FormBuilder $builder, array $options) { if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create($options['prototype_name'], $options['type'], array_replace(array('label' => $options['prototype_name'] . 'label__'), $options['options'])); $builder->setAttribute('prototype', $prototype->getForm()); } $resizeListener = new ResizeFormListener($builder->getFormFactory(), $options['type'], $options['options'], $options['allow_add'], $options['allow_delete']); $builder->addEventSubscriber($resizeListener)->setAttribute('allow_add', $options['allow_add'])->setAttribute('allow_delete', $options['allow_delete']); // Enable support for adders/removers unless "by_reference" is disabled // (explicit calling of the setter is desired) if ($options['by_reference']) { $builder->addEventSubscriber(new MergeCollectionListener($options['allow_add'], $options['allow_delete'], MergeCollectionListener::MERGE_INTO_PARENT, $options['add_method'], $options['remove_method'])); } }
public function buildForm(FormBuilder $builder, array $options) { $builder->add('firstname', 'text', array('label' => 'form.label.firstname'))->add('lastname', 'text', array('label' => 'form.label.lastname'))->add('states', 'choice', array('choices' => array('foo' => 'bar'), 'empty_value' => 'form.states.empty_value'))->add('countries', 'choice', array('empty_value' => false))->add('password', 'repeated', array('first_options' => array('label' => 'form.label.password'), 'second_options' => array('label' => 'form.label.password_repeated'), 'invalid_message' => 'form.error.password_mismatch'))->add('street', 'text', array('label' => 'form.label.street', 'translation_domain' => 'address'))->add('zip', 'text', array('label' => 'form.label.zip', 'translation_domain' => 'address')); $child = $builder->create('created', 'text', array('label' => 'form.label.created')); }
/** * This function return the form used in the product view page * * @param \Sonata\Component\Product\ProductInterface $product A Sonata product instance * @param \Symfony\Component\Form\FormBuilder $formBuilder Symfony form builder * @param boolean $showQuantity Specifies if quantity field will be displayed (default true) * @param array $options An options array * @return void */ public function defineAddBasketForm(ProductInterface $product, FormBuilder $formBuilder, $showQuantity = true, array $options = array()) { $basketElement = $this->createBasketElement($product); // create the product form $formBuilder->setData($basketElement)->add('productId', 'hidden'); if ($showQuantity) { $formBuilder->add('quantity', 'integer'); } else { $transformer = new QuantityTransformer(); $formBuilder->add($formBuilder->create('quantity', 'hidden', array('data' => 1))->addModelTransformer($transformer)); } }
/** * @param FormBuilder $builder */ protected function buildDataGridActions(FormBuilder $builder) { $actionsBuilder = $builder->create('actions', FormType::class, ['label' => false]); foreach ($this->getActions() as $code => $options) { $type = empty($options['form_type']) ? LinkType::class : $options['form_type']; unset($options['form_type']); $actionsBuilder->add($code, $type, $options); } $builder->add($actionsBuilder); }