Skip to content

Commit 55e45fd

Browse files
committed
Use ConfigResolver to retrive the netgen.default.information_collection.form.use_csrf parameter
1 parent 5baecee commit 55e45fd

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

bundle/Form/Builder/FormBuilder.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use eZ\Publish\API\Repository\ContentTypeService;
66
use eZ\Publish\API\Repository\Values\Content\Location;
7+
use eZ\Publish\Core\MVC\ConfigResolverInterface;
78
use Netgen\Bundle\EzFormsBundle\Form\DataWrapper;
89
use Netgen\Bundle\EzFormsBundle\Form\Payload\InformationCollectionStruct;
910
use Netgen\Bundle\EzFormsBundle\Form\Type\InformationCollectionType;
@@ -20,9 +21,9 @@ class FormBuilder
2021
protected $formFactory;
2122

2223
/**
23-
* @var bool
24+
* @var ConfigResolverInterface
2425
*/
25-
protected $useCsrf;
26+
protected $configResolver;
2627

2728
/**
2829
* @var ContentTypeService
@@ -40,16 +41,16 @@ class FormBuilder
4041
* @param FormFactoryInterface $formFactory
4142
* @param ContentTypeService $contentTypeService
4243
* @param RouterInterface $router
43-
* @param bool $useCsrf
44+
* @param ConfigResolverInterface $configResolver
4445
*/
4546
public function __construct(
4647
FormFactoryInterface $formFactory,
4748
ContentTypeService $contentTypeService,
4849
RouterInterface $router,
49-
$useCsrf
50+
ConfigResolverInterface $configResolver
5051
) {
5152
$this->formFactory = $formFactory;
52-
$this->useCsrf = $useCsrf;
53+
$this->configResolver = $configResolver;
5354
$this->contentTypeService = $contentTypeService;
5455
$this->router = $router;
5556
}
@@ -69,6 +70,7 @@ public function createFormForLocation(Location $location, $useAjax = false)
6970
$contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
7071

7172
$data = new DataWrapper(new InformationCollectionStruct(), $contentType, $location);
73+
$useCsrf = $this->configResolver->getParameter('information_collection.form.use_csrf', 'netgen');
7274

7375
$formBuilder = $this->formFactory
7476
->createNamedBuilder(
@@ -78,7 +80,7 @@ public function createFormForLocation(Location $location, $useAjax = false)
7880
InformationCollectionType::class,
7981
$data,
8082
array(
81-
'csrf_protection' => $this->useCsrf,
83+
'csrf_protection' => $useCsrf,
8284
)
8385
);
8486

bundle/Resources/config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ services:
2929
- '@form.factory'
3030
- '@ezpublish.api.service.content_type'
3131
- '@router'
32-
- '%netgen.default.information_collection.form.use_csrf%'
32+
- '@ezpublish.config.resolver'
3333

3434
netgen_information_collection.listener:
3535
class: Netgen\Bundle\InformationCollectionBundle\Listener\InformationCollectedListener

0 commit comments

Comments
 (0)