Skip to content

Commit

Permalink
[Form][FrameworkBundle] Use auto-configuration to make the default CS…
Browse files Browse the repository at this point in the history
…RF token id apply only to the app; not to bundles
  • Loading branch information
nicolas-grekas committed Feb 7, 2025
1 parent d37a43d commit 06b9c6f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
6 changes: 2 additions & 4 deletions DependencyInjection/FrameworkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ public function load(array $configs, ContainerBuilder $container): void
$container->registerForAutoconfiguration(DataCollectorInterface::class)
->addTag('data_collector');
$container->registerForAutoconfiguration(FormTypeInterface::class)
->addTag('form.type');
->addTag('form.type', ['csrf_token_id' => '%.form.type_extension.csrf.token_id%']);
$container->registerForAutoconfiguration(FormTypeGuesserInterface::class)
->addTag('form.type_guesser');
$container->registerForAutoconfiguration(FormTypeExtensionInterface::class)
Expand Down Expand Up @@ -777,9 +777,7 @@ private function registerFormConfiguration(array $config, ContainerBuilder $cont
$container->setParameter('form.type_extension.csrf.enabled', true);
$container->setParameter('form.type_extension.csrf.field_name', $config['form']['csrf_protection']['field_name']);
$container->setParameter('form.type_extension.csrf.field_attr', $config['form']['csrf_protection']['field_attr']);

$container->getDefinition('form.type_extension.csrf')
->replaceArgument(7, $config['form']['csrf_protection']['token_id']);
$container->setParameter('.form.type_extension.csrf.token_id', $config['form']['csrf_protection']['token_id']);
} else {
$container->setParameter('form.type_extension.csrf.enabled', false);
}
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/form_csrf.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
param('validator.translation_domain'),
service('form.server_params'),
param('form.type_extension.csrf.field_attr'),
abstract_arg('framework.form.csrf_protection.token_id'),
param('.form.type_extension.csrf.token_id'),
])
->tag('form.type_extension')
;
Expand Down

0 comments on commit 06b9c6f

Please sign in to comment.