Commit 42bda7b7 authored by Fabien Potencier's avatar Fabien Potencier

bug #1360 Registering the silex form extension last to ensure user specified ex… (skalpa)

This PR was merged into the 2.0.x-dev branch.

Discussion
----------

Registering the silex form extension last to ensure user specified ex…

…tensions can modify the behavior of the CSRF and Validator extensions.

Fixes #1358

Commits
-------

c21798c2 Registering the silex form extension last to ensure user specified extensions can modify the behavior of the CSRF and Validator extensions.
parents 7a20e74b c21798c2
...@@ -69,7 +69,6 @@ class FormServiceProvider implements ServiceProviderInterface ...@@ -69,7 +69,6 @@ class FormServiceProvider implements ServiceProviderInterface
$app['form.extensions'] = function ($app) { $app['form.extensions'] = function ($app) {
$extensions = array( $extensions = array(
$app['form.extension.silex'],
new HttpFoundationExtension(), new HttpFoundationExtension(),
); );
...@@ -80,6 +79,7 @@ class FormServiceProvider implements ServiceProviderInterface ...@@ -80,6 +79,7 @@ class FormServiceProvider implements ServiceProviderInterface
if (isset($app['validator'])) { if (isset($app['validator'])) {
$extensions[] = new FormValidatorExtension($app['validator']); $extensions[] = new FormValidatorExtension($app['validator']);
} }
$extensions[] = $app['form.extension.silex'];
return $extensions; return $extensions;
}; };
......
...@@ -284,6 +284,24 @@ class FormServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -284,6 +284,24 @@ class FormServiceProviderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue(isset($form->createView()['_token'])); $this->assertTrue(isset($form->createView()['_token']));
} }
public function testUserExtensionCanConfigureDefaultExtensions()
{
$app = new Application();
$app->register(new FormServiceProvider());
$app->register(new SessionServiceProvider());
$app->register(new CsrfServiceProvider());
$app['session.test'] = true;
$app->extend('form.type.extensions', function ($extensions) {
$extensions[] = new FormServiceProviderTest\DisableCsrfExtension();
return $extensions;
});
$form = $app['form.factory']->createBuilder('Symfony\Component\Form\Extension\Core\Type\FormType', array())->getForm();
$this->assertFalse($form->getConfig()->getOption('csrf_protection'));
}
} }
if (!class_exists('Symfony\Component\Form\Deprecated\FormEvents')) { if (!class_exists('Symfony\Component\Form\Deprecated\FormEvents')) {
......
<?php
namespace Silex\Tests\Provider\FormServiceProviderTest;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\OptionsResolver\OptionsResolver;
class DisableCsrfExtension extends AbstractTypeExtension
{
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'csrf_protection' => false,
));
}
public function getExtendedType()
{
return FormType::class;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment