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 */
26declare(strict_types=1);
27
28namespace PrestaShopBundle\Form\Admin\Improve\International\Translations;
29
30use PrestaShop\PrestaShop\Core\Translation\Storage\Provider\Definition\ThemeProviderDefinition;
31use PrestaShopBundle\Form\Admin\Type\RadioWithChoiceChildrenType;
32use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
33use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
34use Symfony\Component\Form\FormBuilderInterface;
35use Symfony\Component\Translation\TranslatorInterface;
36
37/**
38 * Class ExportThemeLanguageType is responsible for building export language form
39 * in 'Improve > International > Translations' page.
40 */
41class ExportCataloguesType extends TranslatorAwareType
42{
43    /**
44     * @var array
45     */
46    private $exportTranslationCoreTypeChoices;
47
48    /**
49     * @var array
50     */
51    private $themeChoices;
52
53    /**
54     * @var array
55     */
56    private $moduleChoices;
57
58    /**
59     * @param TranslatorInterface $translator
60     * @param array $locales
61     * @param array $themeChoices
62     * @param array $exportTranslationCoreTypeChoices
63     * @param array $moduleChoices
64     */
65    public function __construct(
66        TranslatorInterface $translator,
67        array $locales,
68        array $exportTranslationCoreTypeChoices,
69        array $themeChoices,
70        array $moduleChoices
71    ) {
72        parent::__construct($translator, $locales);
73        $this->exportTranslationCoreTypeChoices = $exportTranslationCoreTypeChoices;
74        $this->themeChoices = $themeChoices;
75        $this->moduleChoices = $moduleChoices;
76    }
77
78    /**
79     * {@inheritdoc}
80     */
81    public function buildForm(FormBuilderInterface $builder, array $options): void
82    {
83        $builder
84            ->add('iso_code', ChoiceType::class, [
85                'label' => $this->trans(
86                    'Language',
87                    'Admin.Global'
88                ),
89                'choices' => $this->getLocaleChoices(),
90                'choice_translation_domain' => false,
91            ]);
92
93        $builder->add('core_selectors', RadioWithChoiceChildrenType::class, [
94            'radio_name' => 'core_type',
95            'radio_label' => $this->trans('PrestaShop translations', 'Admin.International.Feature'),
96            'required' => false,
97            'label' => $this->trans('Export', 'Admin.Actions'),
98            'child_choice' => [
99                'name' => 'selected_value',
100                'choices' => $this->exportTranslationCoreTypeChoices,
101                'label' => false,
102                'multiple' => true,
103            ],
104        ]);
105
106        $builder->add('themes_selectors', RadioWithChoiceChildrenType::class, [
107            'radio_name' => 'themes_type',
108            'radio_label' => $this->trans('Theme translations', 'Admin.International.Feature'),
109            'required' => false,
110            'label' => null,
111            'child_choice' => [
112                'name' => 'selected_value',
113                'empty' => $this->trans('Select a theme', 'Admin.International.Feature'),
114                'choices' => $this->excludeDefaultThemeFromChoices($this->themeChoices),
115                'label' => false,
116                'multiple' => false,
117            ],
118        ]);
119
120        $builder->add('modules_selectors', RadioWithChoiceChildrenType::class, [
121            'radio_name' => 'modules_type',
122            'radio_label' => $this->trans('Installed module translations', 'Admin.International.Feature'),
123            'required' => false,
124            'label' => null,
125            'child_choice' => [
126                'name' => 'selected_value',
127                'empty' => $this->trans('Select a module', 'Admin.International.Feature'),
128                'choices' => $this->moduleChoices,
129                'label' => false,
130                'multiple' => false,
131            ],
132        ]);
133    }
134
135    /**
136     * @param array $themeChoices
137     *
138     * @return array
139     */
140    private function excludeDefaultThemeFromChoices(array $themeChoices): array
141    {
142        unset($themeChoices[ThemeProviderDefinition::DEFAULT_THEME_NAME]);
143
144        return $themeChoices;
145    }
146}
147