handle disaled csrf protection in the Twig FormExtension
This commit is contained in:
parent
2a998e01b9
commit
3a1699a420
@ -33,7 +33,7 @@ class FormExtension extends \Twig_Extension
|
||||
protected $varStack;
|
||||
protected $template;
|
||||
|
||||
public function __construct(CsrfProviderInterface $csrfProvider, array $resources = array())
|
||||
public function __construct(CsrfProviderInterface $csrfProvider = null, array $resources = array())
|
||||
{
|
||||
$this->csrfProvider = $csrfProvider;
|
||||
$this->themes = new \SplObjectStorage();
|
||||
@ -298,6 +298,10 @@ class FormExtension extends \Twig_Extension
|
||||
*/
|
||||
public function getCsrfToken($intention)
|
||||
{
|
||||
if (!$this->csrfProvider instanceof CsrfProviderInterface) {
|
||||
throw new \BadMethodCallException('CSRF token can only be generated if the "form.csrf_provider" service is available');
|
||||
}
|
||||
|
||||
return $this->csrfProvider->generateCsrfToken($intention);
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ class FormHelper extends Helper
|
||||
*/
|
||||
public function csrfToken($intention)
|
||||
{
|
||||
if (! $this->csrfProvider instanceof CsrfProviderInterface) {
|
||||
if (!$this->csrfProvider instanceof CsrfProviderInterface) {
|
||||
throw new \BadMethodCallException('CSRF token can only be generated if the "form.csrf_provider" service is available');
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
||||
|
||||
<service id="twig.extension.form" class="%twig.extension.form.class%" public="false">
|
||||
<tag name="twig.extension" />
|
||||
<argument type="service" id="form.csrf_provider" />
|
||||
<argument type="service" id="form.csrf_provider" on-invalid="null" />
|
||||
<argument>%twig.form.resources%</argument>
|
||||
</service>
|
||||
|
||||
|
Reference in New Issue
Block a user