|
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\Bundle\HookBundle\FormAwareHook; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Form\Exception\InvalidConfigurationException; |
|
15
|
|
|
use Symfony\Component\Form\FormInterface; |
|
16
|
|
|
use Zikula\Bundle\HookBundle\Hook\Hook; |
|
17
|
|
|
|
|
18
|
|
|
class FormAwareHook extends Hook |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var FormInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $form; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var array |
|
27
|
|
|
*/ |
|
28
|
|
|
private $templates = []; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param FormInterface $form |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(FormInterface $form) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->form = $form; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function getFormData() |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->form->getData(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param FormInterface|string|int $child |
|
48
|
|
|
* @param string|null $type |
|
49
|
|
|
* @param array $options |
|
50
|
|
|
* @return self |
|
51
|
|
|
*/ |
|
52
|
|
|
public function formAdd($child, $type = null, array $options = []) |
|
53
|
|
|
{ |
|
54
|
|
|
if (($child instanceof FormInterface) && ($child->getConfig()->getMapped() || $child->getConfig()->getAutoInitialize())) { |
|
|
|
|
|
|
55
|
|
|
throw new InvalidConfigurationException('Hooked child forms must disable `mapped` and `auto_initialize` options.'); |
|
56
|
|
|
} else { |
|
57
|
|
|
$options['mapped'] = false; |
|
58
|
|
|
$options['auto_initialize'] = false; |
|
59
|
|
|
} |
|
60
|
|
|
$this->form->add($child, $type, $options); |
|
61
|
|
|
|
|
62
|
|
|
return $this; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param string $template |
|
67
|
|
|
* @param array $templateVars |
|
68
|
|
|
* @return self |
|
69
|
|
|
*/ |
|
70
|
|
View Code Duplication |
public function addTemplate($template, $templateVars = []) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
|
|
if (!in_array($template, $this->templates)) { |
|
73
|
|
|
$this->templates[] = [$template, $templateVars]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return array |
|
81
|
|
|
*/ |
|
82
|
|
|
public function getTemplates() |
|
83
|
|
|
{ |
|
84
|
|
|
return $this->templates; |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.