[Form] Moved auto_initialize option to the BaseType

This commit is contained in:
Jakub Zalas 2013-06-24 15:42:05 +01:00 committed by Fabien Potencier
parent d7999d7108
commit 6ed0fdfda4
4 changed files with 24 additions and 2 deletions

View File

@ -33,6 +33,7 @@ abstract class BaseType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->setDisabled($options['disabled']);
$builder->setAutoInitialize($options['auto_initialize']);
}
/**
@ -112,6 +113,7 @@ abstract class BaseType extends AbstractType
'label' => null,
'attr' => array(),
'translation_domain' => null,
'auto_initialize' => true,
));
$resolver->setAllowedTypes(array(

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Form\Extension\Core\Type;
use Symfony\Component\Form\ButtonTypeInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* A form button.
@ -35,4 +36,16 @@ class ButtonType extends BaseType implements ButtonTypeInterface
{
return 'button';
}
/**
* {@inheritdoc}
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
parent::setDefaultOptions($resolver);
$resolver->setDefaults(array(
'auto_initialize' => false,
));
}
}

View File

@ -55,7 +55,6 @@ class FormType extends BaseType
->setDataMapper($options['compound'] ? new PropertyPathMapper($this->propertyAccessor) : null)
->setMethod($options['method'])
->setAction($options['action'])
->setAutoInitialize($options['auto_initialize'])
;
if ($options['trim']) {
@ -189,7 +188,6 @@ class FormType extends BaseType
// According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
// section 4.2., empty URIs are considered same-document references
'action' => '',
'auto_initialize' => true,
));
$resolver->setAllowedTypes(array(

View File

@ -51,4 +51,13 @@ class SubmitTypeTest extends TypeTestCase
$this->assertTrue($button->isClicked());
}
public function testSubmitCanBeAddedToForm()
{
$form = $this->factory
->createBuilder('form')
->getForm();
$this->assertSame($form, $form->add('send', 'submit'));
}
}