/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); if ($options['allow_add'] && $options['prototype']) { $prototype = $builder->create('${id}', $options['type'], $options['options']); $builder->setAttribute('prototype', $prototype->getForm()); } }
public function buildForm(FormBuilderInterface $builder, array $options) { if ($options['controller']) { $options['type'] = $options['controller']->getFormType(); } if (isset($options['type']) && $options['type'] instanceof FormTypeInterface) { $options['prototype_name'] = '__' . $options['type']->getName() . '__'; } parent::buildForm($builder, $options); }
public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $preListener = function (FormEvent $event) use($options) { /** @var Form $form */ $form = $event->getForm(); $data = $event->getData(); if (null === $data) { $data = array(); } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\\Traversable and \\ArrayAccess)'); } // First remove all rows foreach ($form as $name => $child) { $form->remove($name); } // Then add all rows again in the correct order foreach ($data as $name => $value) { $className = 'VulnModule\\Form\\Condition\\' . $name . 'Type'; $type = class_exists($className) ? new $className() : 'condition'; $opts = array_replace(array('property_path' => '[' . $name . ']'), $options['options'] ?: []); $opts['cascade_validation'] = $options['cascade_validation']; $form->add($name, $type, $opts); } }; $builder->addEventListener(FormEvents::PRE_SET_DATA, $preListener); $builder->addEventListener(FormEvents::PRE_SUBMIT, $preListener); $builder->addEventListener(FormEvents::SUBMIT, function (FormEvent $event) use($options) { // /** @var Form $form */ // $form = $event->getForm(); $data = $event->getData(); if (null === $data) { return; } if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { throw new UnexpectedTypeException($data, 'array or (\\Traversable and \\ArrayAccess)'); } /** * @var string $name * @var Condition $value */ foreach ($data as $name => $value) { if ($value->getName() == $name) { continue; } $className = 'VulnModule\\Config\\Condition\\' . $name; /** @var Condition $element */ $element = new $className(); $element->fillFromArray($value->toArray()); $data[$name] = $element; } $event->setData($data); }); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { $columnCount = $event->getForm()->getConfig()->getOption('column_count'); $data = $event->getData(); if (empty($data) || !count($data)) { $sizeKeys = range(0, $columnCount - 1); $data = array_fill_keys(['xs', 'sm', 'md', 'lg'], array_fill_keys($sizeKeys, 12 / $columnCount)); $event->setData($data); } }); parent::buildForm($builder, $options); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { parent::buildForm($builder, $options); $builder->addEventListener(FormEvents::POST_SUBMIT, array($this, 'onPostSubmit')); }