Completed
Push — master ( fd10c7...b50c82 )
by Craig
06:29
created

UserFormAwareEvent::formAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Zikula\UsersModule\Event;
13
14
use Symfony\Component\EventDispatcher\Event;
15
use Symfony\Component\Form\FormInterface;
16
17
class UserFormAwareEvent extends Event
18
{
19
    /**
20
     * @var FormInterface
21
     */
22
    private $form;
23
24
    /**
25
     * @var array
26
     */
27
    private $templates = [];
28
29
    /**
30
     * @param FormInterface $form
31
     */
32
    public function __construct(FormInterface $form)
33
    {
34
        $this->form = $form;
35
    }
36
37
    /**
38
     * @return mixed
39
     */
40
    public function getFormData()
41
    {
42
        return $this->form->getData();
43
    }
44
45
    /**
46
     * @param FormInterface|string|int $child
47
     * @param string|null $type
48
     * @param array $options
49
     * @return self - copy fluent interface of form class
50
     */
51
    public function formAdd($child, $type = null, array $options = [])
52
    {
53
        $this->form->add($child, $type, $options);
54
55
        return $this;
56
    }
57
58
    /**
59
     * @param string $template
60
     * @return self - copy fluent interface of form class
61
     */
62
    public function addTemplate($template)
63
    {
64
        if (!in_array($template, $this->templates)) {
65
            $this->templates[] = $template;
66
        }
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getTemplates()
75
    {
76
        return $this->templates;
77
    }
78
}
79