8000 [FrameworkBundle] Fix declaring field-attr tags in xml config files by nicolas-grekas · Pull Request #60439 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Fix declaring field-attr tags in xml config files #60439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service 8000 and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private function addFormSection(ArrayNodeDefinition $rootNode, callable $enableI
->arrayNode('field_attr')
->performNoDeepMerging()
->normalizeKeys(false)
->useAttributeAsKey('name')
->scalarPrototype()->end()
->defaultValue(['data-controller' => 'csrf-protection'])
->end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<xsd:attribute name="field-name" type="xsd:string" />
</xsd:complexType>

<xsd:complexType name="field_attr">
<xsd:complexType name="field_attr" mixed="true">
<xsd:attribute name="name" type="xsd:string" use="required"/>
</xsd:complexType>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$container->loadFromExtension('framework', [
'annotations' => false,
'http_method_override' => false,
'handle_all_throwables' => true,
'php_errors' => ['log' => true],
'csrf_protection' => [
'enabled' => true,
],
'form' => [
'csrf_protection' => [
'field-attr' => [
'data-foo' => 'bar',
'data-bar' => 'baz',
],
],
],
'session' => [
'storage_factory_id' => 'session.storage.factory.native',
],
]);
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<framework:config http-method-override="false" handle-all-throwables="true">
<framework:annotations enabled="false" />
<framework:php-errors log="true" />
<framework:csrf-protection field-name="_custom" />
<framework:csrf-protection enabled="true" />
<framework:form>
<framework:csrf-protection>
<framework:field-attr name="data-foo">bar</framework:field-attr>
<framework:field-attr name="data-bar">baz</framework:field-attr>
</framework:csrf-protection>
</framework:form>
<framework:session storage-factory-id="session.storage.factory.native" />
</framework:config>
</container>

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
framework:
annotations: false
http_method_override: false
handle_all_throwables: true
php_errors:
log: true
csrf_protection:
enabled: true
form:
csrf_protection:
enabled: true
field_attr:
data-foo: bar
data-bar: baz
session:
storage_factory_id: session.storage.factory.native
6E17
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,17 @@ public function testFormsCanBeEnabledWithoutCsrfProtection()
$this->assertFalse($container->getParameter('form.type_extension.csrf.enabled'));
}

public function testFormCsrfFieldAttr()
{
$container = $this->createContainerFromFile('form_csrf_field_attr');

$expected = [
'data-foo' => 'bar',
'data-bar' => 'baz',
];
$this->assertSame($expected, $container->getParameter('form.type_extension.csrf.field_attr'));
}

public function testStopwatchEnabledWithDebugModeEnabled()
{
$container = $this->createContainerFromFile('default_config', [
Expand Down
Loading
0