diff --git a/DataGrid/Extension/Symfony/ColumnTypeExtension/FormExtension.php b/DataGrid/Extension/Symfony/ColumnTypeExtension/FormExtension.php index dfd135b..3d474a9 100644 --- a/DataGrid/Extension/Symfony/ColumnTypeExtension/FormExtension.php +++ b/DataGrid/Extension/Symfony/ColumnTypeExtension/FormExtension.php @@ -27,6 +27,11 @@ class FormExtension extends ColumnAbstractTypeExtension */ protected $formFactory; + /** + * @var bool + */ + protected $csrfTokenEnabled; + /** * Form Objects instances created by method CreateForm. * @@ -37,9 +42,10 @@ class FormExtension extends ColumnAbstractTypeExtension /** * @param \Symfony\Component\Form\FormFactoryInterface $formFactory */ - public function __construct(FormFactoryInterface $formFactory) + public function __construct(FormFactoryInterface $formFactory, $csrfTokenEnabled = true) { $this->formFactory = $formFactory; + $this->csrfTokenEnabled = $csrfTokenEnabled; } /** @@ -217,16 +223,13 @@ private function createForm(ColumnTypeInterface $column, $index, $object) break; } - if ($this->isSymfony3()) { - $formBuilderOptions = array( - 'entry_type' => $this->getRowTypeName(), - 'csrf_protection' => false, - ); - } else { - $formBuilderOptions = array( - 'type' => new RowType($fields), - 'csrf_protection' => false, - ); + $formBuilderOptions = $this->isSymfony3() + ? array('entry_type' => $this->getRowTypeName()) + : array('type' => new RowType($fields)) + ; + + if ($this->csrfTokenEnabled) { + $formBuilderOptions['csrf_protection'] = false; } if ($this->isSymfony3()) { diff --git a/Resources/config/datagrid.xml b/Resources/config/datagrid.xml index c56c7c6..340474f 100644 --- a/Resources/config/datagrid.xml +++ b/Resources/config/datagrid.xml @@ -110,6 +110,7 @@ + %form.type_extension.csrf.enabled%