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\Product;
28
29use PrestaShop\PrestaShop\Adapter\Category\CategoryDataProvider;
30use PrestaShopBundle\Form\Admin\Type\ChoiceCategoriesTreeType;
31use PrestaShopBundle\Form\Admin\Type\TranslatorAwareType;
32use Symfony\Component\Form\FormBuilderInterface;
33use Symfony\Component\Translation\TranslatorInterface;
34
35/**
36 * This class render Product Categories Form in Product List Page.
37 */
38class ProductCategories extends TranslatorAwareType
39{
40    /**
41     * @var CategoryDataProvider
42     */
43    private $categoryProvider;
44
45    /**
46     * @var int
47     */
48    private $languageId;
49
50    /**
51     * @param TranslatorInterface $translator
52     * @param CategoryDataProvider $categoryDataProvider
53     * @param array $languages
54     * @param int $languageId
55     */
56    public function __construct(
57        TranslatorInterface $translator,
58        CategoryDataProvider $categoryDataProvider,
59        array $languages,
60        $languageId
61    ) {
62        $this->categoryProvider = $categoryDataProvider;
63        $this->languageId = $languageId;
64        parent::__construct($translator, $languages);
65    }
66
67    /**
68     * {@inheritdoc}
69     */
70    public function buildForm(FormBuilderInterface $builder, array $options)
71    {
72        $builder->add('categories', ChoiceCategoriesTreeType::class, [
73            'label' => $this->trans('Categories', 'Admin.Catalog.Feature'),
74            'list' => $this->categoryProvider->getNestedCategories(null, $this->languageId, false),
75            'valid_list' => [],
76            'multiple' => false,
77            'expanded' => false,
78        ]);
79    }
80
81    /**
82     * {@inheritdoc}
83     */
84    public function getBlockPrefix()
85    {
86        return 'product_categories';
87    }
88}
89