Skip to content

Commit 88b322e

Browse files
[FrameworkBundle] Fix declaring fiel-attr tags in xml config files
1 parent 905d138 commit 88b322e

File tree

7 files changed

+58
-17
lines changed

7 files changed

+58
-17
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
252252
->arrayNode('field_attr')
253253
->performNoDeepMerging()
254254
->normalizeKeys(false)
255+
->useAttributeAsKey('name')
255256
->scalarPrototype()->end()
256257
->defaultValue(['data-controller' => 'csrf-protection'])
257258
->end()

src/Symfony/Bundle/FrameworkBundle/Resources/config/schema/symfony-1.0.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
<xsd:attribute name="field-name" type="xsd:string" />
8080
</xsd:complexType>
8181

82-
<xsd:complexType name="field_attr">
82+
<xsd:complexType name="field_attr" mixed="true">
8383
<xsd:attribute name="name" type="xsd:string" use="required"/>
8484
</xsd:complexType>
8585

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'annotations' => false,
5+
'http_method_override' => false,
6+
'handle_all_throwables' => true,
7+
'php_errors' => ['log' => true],
8+
'csrf_protection' => [
9+
'enabled' => true,
10+
],
11+
'form' => [
12+
'csrf_protection' => [
13+
'field-attr' => [
14+
'data-foo' => 'bar',
15+
'data-bar' => 'baz',
16+
],
17+
],
18+
],
19+
'session' => [
20+
'storage_factory_id' => 'session.storage.factory.native',
21+
],
22+
]);
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
<framework:config http-method-override="false" handle-all-throwables="true">
1010
<framework:annotations enabled="false" />
1111
<framework:php-errors log="true" />
12-
<framework:csrf-protection field-name="_custom" />
12+
<framework:csrf-protection enabled="true" />
13+
<framework:form>
14+
<framework:csrf-protection>
15+
<framework:field-attr name="data-foo">bar</framework:field-attr>
16+
<framework:field-attr name="data-bar">baz</framework:field-attr>
17+
</framework:csrf-protection>
18+
</framework:form>
1319
<framework:session storage-factory-id="session.storage.factory.native" />
1420
</framework:config>
1521
</container>

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/form_csrf_under_form_sets_field_name.xml

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
framework:
2+
annotations: false
3+
http_method_override: false
4+
handle_all_throwables: true
5+
php_errors:
6+
log: true
7+
csrf_protection:
8+
enabled: true
9+
form:
10+
csrf_protection:
11+
enabled: true
12+
field_attr:
13+
data-foo: bar
14+
data-bar: baz
15+
session:
16+
storage_factory_id: session.storage.factory.native

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,17 @@ public function testFormsCanBeEnabledWithoutCsrfProtection()
14131413
$this->assertFalse($container->getParameter('form.type_extension.csrf.enabled'));
14141414
}
14151415

1416+
public function testFormCsrfFieldAttr()
1417+
{
1418+
$container = $this->createContainerFromFile('form_csrf_field_attr');
1419+
1420+
$expected = [
1421+
'data-foo' => 'bar',
1422+
'data-bar' => 'baz',
1423+
];
1424+
$this->assertSame($expected, $container->getParameter('form.type_extension.csrf.field_attr'));
1425+
}
1426+
14161427
public function testStopwatchEnabledWithDebugModeEnabled()
14171428
{
14181429
$container = $this->createContainerFromFile('default_config', [

0 commit comments

Comments
 (0)