Completed
Push — master ( 1a29b3...803c2a )
by Bukashk0zzz
01:49
created

FormTypeExtension::getExtendedTypes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php declare(strict_types = 1);
2
3
namespace Bukashk0zzz\FilterBundle\Form\Extension;
4
5
use Bukashk0zzz\FilterBundle\Form\EventListener\FilterListener;
6
use Bukashk0zzz\FilterBundle\Service\Filter;
7
use Symfony\Component\Form\AbstractTypeExtension;
8
use Symfony\Component\Form\Extension\Core\Type\FormType;
9
use Symfony\Component\Form\FormBuilderInterface;
10
11
/**
12
 * Class FormTypeExtension
13
 */
14
class FormTypeExtension extends AbstractTypeExtension
15
{
16
    /**
17
     * @var Filter
18
     */
19
    protected $filterService;
20
21
    /**
22
     * @var bool
23
     */
24
    protected $autoFilter;
25
26
    /**
27
     * FilterListener constructor.
28
     *
29
     * @param Filter $filterService
30
     * @param bool   $autoFilter
31
     */
32
    public function __construct(Filter $filterService, bool $autoFilter)
33
    {
34
        $this->filterService = $filterService;
35
        $this->autoFilter = $autoFilter;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     *
41
     * @deprecated since Symfony 4.2, use getExtendedTypes() instead.
42
     */
43
    public function getExtendedType()
44
    {
45
        return self::getExtendedTypes()[0];
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public static function getExtendedTypes()
52
    {
53
        return [FormType::class];
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function buildForm(FormBuilderInterface $builder, array $options)
60
    {
61
        if (!$this->autoFilter) {
62
            return;
63
        }
64
65
        $builder->addEventSubscriber(new FilterListener($this->filterService));
66
    }
67
}
68