Skip to content

Commit 71af590

Browse files
authored
check csrf protection availability before using it
1 parent 541d93e commit 71af590

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

src/Controller/DatagridControllerHelper.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,15 @@ trait DatagridControllerHelper
1010
{
1111
public function createFilterFormBuilder(string $name = 'filters', string $method = 'GET', bool $csrfProtection = false, array $options = []): FormBuilderInterface
1212
{
13-
return $this->container->get('form.factory')
14-
->createNamedBuilder($name, options: array_merge([
15-
'method' => $method,
16-
'csrf_protection' => $csrfProtection,
17-
], $options));
13+
$defaultOptions = [
14+
'method' => $method,
15+
];
16+
17+
if ($this->container->get('form.factory')->create()->getConfig()->hasOption('csrf_protection')) {
18+
$defaultOptions['csrf_protection'] = $csrfProtection;
19+
}
20+
21+
return $this->container->get('form.factory')->createNamedBuilder($name, options: array_merge($defaultOptions, $options));
1822
}
1923

2024
protected function assertCsrfTokenValid(Request $request, $tokenId, string $tokenName = '_token'): void

0 commit comments

Comments
 (0)