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\Translation\Storage\Provider\Definition\ThemeProviderDefinition;
30use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
31use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
32use Symfony\Component\Form\FormBuilderInterface;
33use Symfony\Component\Translation\TranslatorInterface;
34
35/**
36 * Class ModifyTranslationsType is responsible for building 'Modify translations' form
37 * in 'Improve > International > Translations' page.
38 */
39class ModifyTranslationsType extends TranslatorAwareType
40{
41    public const CORE_TRANSLATIONS_CHOICE_INDEX = '0';
42    /**
43     * @var array
44     */
45    private $translationTypeChoices;
46
47    /**
48     * @var array
49     */
50    private $emailContentTypeChoices;
51
52    /**
53     * @var array
54     */
55    private $themeChoices;
56
57    /**
58     * @var array
59     */
60    private $moduleChoices;
61
62    /**
63     * @param TranslatorInterface $translator
64     * @param array $locales
65     * @param array $translationTypeChoices
66     * @param array $emailContentTypeChoices
67     * @param array $themeChoices
68     * @param array $moduleChoices
69     */
70    public function __construct(
71        TranslatorInterface $translator,
72        array $locales,
73        array $translationTypeChoices,
74        array $emailContentTypeChoices,
75        array $themeChoices,
76        array $moduleChoices
77    ) {
78        parent::__construct($translator, $locales);
79        $this->translationTypeChoices = $translationTypeChoices;
80        $this->emailContentTypeChoices = $emailContentTypeChoices;
81        $this->themeChoices = $themeChoices;
82        $this->moduleChoices = $moduleChoices;
83    }
84
85    /**
86     * {@inheritdoc}
87     */
88    public function buildForm(FormBuilderInterface $builder, array $options)
89    {
90        $noTheme = $this->trans('Core (no theme selected)', 'Admin.International.Feature');
91
92        $themeChoiceAttributes = [
93            $noTheme => [
94                'class' => 'js-no-theme',
95            ],
96        ];
97
98        if (isset($this->themeChoices[ThemeProviderDefinition::DEFAULT_THEME_NAME])) {
99            $themeChoiceAttributes[ThemeProviderDefinition::DEFAULT_THEME_NAME] = [
100                'class' => 'js-default-theme',
101            ];
102        }
103
104        $builder
105            ->add('translation_type', ChoiceType::class, [
106                'label' => $this->trans('Type of translation', 'Admin.International.Feature'),
107                'attr' => [
108                    'class' => 'js-translation-type',
109                ],
110                'choices' => $this->translationTypeChoices,
111                'choice_translation_domain' => false,
112            ])
113            ->add('email_content_type', ChoiceType::class, [
114                'label' => $this->trans('Select the type of email content', 'Admin.International.Feature'),
115                'row_attr' => [
116                    'class' => 'js-email-form-group d-none',
117                ],
118                'attr' => [
119                    'class' => 'js-email-content-type',
120                ],
121                'choices' => $this->emailContentTypeChoices,
122                'choice_translation_domain' => false,
123            ])
124            ->add('theme', ChoiceType::class, [
125                'label' => $this->trans('Select your theme', 'Admin.International.Feature'),
126                'row_attr' => [
127                    'class' => 'js-theme-form-group d-none',
128                ],
129                'choices' => [$noTheme => self::CORE_TRANSLATIONS_CHOICE_INDEX] + $this->themeChoices,
130                'choice_attr' => $themeChoiceAttributes,
131                'choice_translation_domain' => false,
132            ])
133            ->add('module', ChoiceType::class, [
134                'label' => $this->trans('Select your module', 'Admin.International.Feature'),
135                'row_attr' => [
136                    'class' => 'js-module-form-group d-none',
137                ],
138                'placeholder' => '---',
139                'attr' => [
140                    'data-minimumResultsForSearch' => '7',
141                    'data-toggle' => 'select2',
142                ],
143                'choices' => $this->moduleChoices,
144                'choice_translation_domain' => false,
145            ])
146            ->add('language', ChoiceType::class, [
147                'label' => $this->trans('Select your language', 'Admin.International.Feature'),
148                'placeholder' => $this->trans('Language', 'Admin.Global'),
149                'choices' => $this->getLocaleChoices(),
150                'choice_translation_domain' => false,
151            ]);
152    }
153}
154