Skip to content

Commit

Permalink
Fix when csrf_protection is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
sandorsasovits committed Nov 22, 2016
1 parent c62f30f commit 3991c07
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
25 changes: 14 additions & 11 deletions DataGrid/Extension/Symfony/ColumnTypeExtension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ class FormExtension extends ColumnAbstractTypeExtension
*/
protected $formFactory;

/**
* @var bool
*/
protected $csrfTokenEnabled;

/**
* Form Objects instances created by method CreateForm.
*
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions Resources/config/datagrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<service id="datagrid.column_extension.symfony.form" class="FSi\Bundle\DataGridBundle\DataGrid\Extension\Symfony\ColumnTypeExtension\FormExtension">
<tag name="datagrid.column_extension" alias="symfony.form"/>
<argument type="service" id="form.factory" />
<argument>%form.type_extension.csrf.enabled%</argument>
</service>
<service id="datagrid.subscriber.symfony.bindrequest" class="FSi\Bundle\DataGridBundle\DataGrid\Extension\Symfony\EventSubscriber\BindRequest">
<tag name="datagrid.subscriber" alias="symfony.form.bindrequest"/>
Expand Down

0 comments on commit 3991c07

Please # to comment.