merged branch jakzal/2.3-form-button-fix (PR #8349)
This PR was squashed before being merged into the 2.3 branch (closes #8349).
Discussion
----------
[Form] Moved auto_initialize option to the BaseType
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #8162
| License | MIT
| Doc PR | -
I'm not fully confident in this change, so let someone review it before mergin please. My thinking was - since "auto_initialized" option is always passed to a form factory, it should be required by the base type.
Commits
-------
6ed0fdf
[Form] Moved auto_initialize option to the BaseType
This commit is contained in:
commit
2b2c1167ef
@ -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(
|
||||
|
@ -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,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -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']) {
|
||||
@ -188,7 +187,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(
|
||||
|
@ -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'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user