Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Fixed exception: The option "csrf_protection" does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusOmar committed Apr 11, 2014
1 parent f86ed81 commit 749cf94
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Builder/DatagridBuilder.php
Expand Up @@ -42,6 +42,13 @@ class DatagridBuilder implements DatagridBuilderInterface
*/
protected $guesser;

/**
* Indicates that csrf protection enabled
*
* @var bool
*/
protected $csrfTokenEnabled;

/**
* @var PagerInterface
*/
Expand All @@ -51,12 +58,14 @@ class DatagridBuilder implements DatagridBuilderInterface
* @param FormFactory $formFactory
* @param FilterFactoryInterface $filterFactory
* @param TypeGuesserInterface $guesser
* @param bool $csrfTokenEnabled
*/
public function __construct(FormFactory $formFactory, FilterFactoryInterface $filterFactory, TypeGuesserInterface $guesser)
public function __construct(FormFactory $formFactory, FilterFactoryInterface $filterFactory, TypeGuesserInterface $guesser, $csrfTokenEnabled = true)
{
$this->formFactory = $formFactory;
$this->filterFactory = $filterFactory;
$this->guesser = $guesser;
$this->csrfTokenEnabled = $csrfTokenEnabled;
}

/**
Expand Down Expand Up @@ -151,7 +160,12 @@ public function addFilter(DatagridInterface $datagrid, $type = null, FieldDescri
*/
public function getBaseDatagrid(AdminInterface $admin, array $values = array())
{
$formBuilder = $this->formFactory->createNamedBuilder('filter', 'form', array(), array('csrf_protection' => false));
$defaultOptions = array();
if ($this->csrfTokenEnabled) {
$defaultOptions['csrf_protection'] = false;
}

$formBuilder = $this->formFactory->createNamedBuilder('filter', 'form', array(), $defaultOptions);

return new Datagrid($admin->createQuery(), $admin->getList(), $this->getPager(), $formBuilder, $values);
}
Expand Down
1 change: 1 addition & 0 deletions Resources/config/doctrine_phpcr.xml
Expand Up @@ -49,6 +49,7 @@
<argument type="service" id="form.factory" />
<argument type="service" id="sonata.admin.builder.filter.factory" />
<argument type="service" id="sonata.admin.guesser.doctrine_phpcr_datagrid_chain" />
<argument>%form.type_extension.csrf.enabled%</argument>
</service>

<service id="sonata.admin.guesser.doctrine_phpcr_datagrid" class="Sonata\DoctrinePHPCRAdminBundle\Guesser\FilterTypeGuesser">
Expand Down

0 comments on commit 749cf94

Please sign in to comment.