1<?php
2/**
3 * Copyright since 2007 PrestaShop SA and Contributors
4 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA
5 *
6 * NOTICE OF LICENSE
7 *
8 * This source file is subject to the Open Software License (OSL 3.0)
9 * that is bundled with this package in the file LICENSE.md.
10 * It is also available through the world-wide-web at this URL:
11 * https://opensource.org/licenses/OSL-3.0
12 * If you did not receive a copy of the license and are unable to
13 * obtain it through the world-wide-web, please send an email
14 * to license@prestashop.com so we can send you a copy immediately.
15 *
16 * DISCLAIMER
17 *
18 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
19 * versions in the future. If you wish to customize PrestaShop for your
20 * needs please refer to https://devdocs.prestashop.com/ for more information.
21 *
22 * @author    PrestaShop SA and Contributors <contact@prestashop.com>
23 * @copyright Since 2007 PrestaShop SA and Contributors
24 * @license   https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
25 */
26
27namespace PrestaShopBundle\Form\Admin\Improve\International\Translations;
28
29use PrestaShop\PrestaShop\Core\Form\FormHandlerInterface;
30use PrestaShop\PrestaShop\Core\Hook\HookDispatcherInterface;
31use Symfony\Component\Form\FormFactoryInterface;
32
33final class TranslationsSettingsFormHandler implements FormHandlerInterface
34{
35    /**
36     * @var FormFactoryInterface the form builder
37     */
38    protected $formFactory;
39
40    /**
41     * @var HookDispatcherInterface the event dispatcher
42     */
43    protected $hookDispatcher;
44
45    /**
46     * @var string the hook name to be dispatched
47     */
48    protected $hookName;
49
50    /**
51     * @var string
52     */
53    protected $form;
54
55    /**
56     * @param FormFactoryInterface $formFactory
57     * @param HookDispatcherInterface $hookDispatcher
58     * @param string $form
59     * @param string $hookName
60     */
61    public function __construct(
62        FormFactoryInterface $formFactory,
63        HookDispatcherInterface $hookDispatcher,
64        string $form,
65        string $hookName
66    ) {
67        $this->formFactory = $formFactory;
68        $this->hookDispatcher = $hookDispatcher;
69        $this->form = $form;
70        $this->hookName = $hookName;
71    }
72
73    /**
74     * {@inheritdoc}
75     */
76    public function getForm()
77    {
78        $formBuilder = $this->formFactory->createNamedBuilder('form', $this->form);
79
80        $this->hookDispatcher->dispatchWithParameters(
81            "action{$this->hookName}Form",
82            [
83                'form_builder' => $formBuilder,
84            ]
85        );
86
87        return $formBuilder->getForm();
88    }
89
90    /**
91     * {@inheritdoc}
92     */
93    public function save(array $data)
94    {
95        // Translations forms do not save data
96        return [];
97    }
98}
99