Skip to content
New issue

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

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

Already on GitHub? # to your account

Fix when csrf_protection is disabled #80

Merged
merged 1 commit into from
May 11, 2017
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
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