1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* @copyright 2014 Mautic Contributors. All rights reserved |
5
|
|
|
* @author Mautic |
6
|
|
|
* |
7
|
|
|
* @link http://mautic.org |
8
|
|
|
* |
9
|
|
|
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Mautic\CoreBundle\Form\EventListener; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
15
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
16
|
|
|
use Symfony\Component\Form\FormEvent; |
17
|
|
|
use Symfony\Component\Form\FormEvents; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class FormExitSubscriber. |
21
|
|
|
*/ |
22
|
|
|
class FormExitSubscriber implements EventSubscriberInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var \Mautic\CoreBundle\Model\CommonModel |
|
|
|
|
26
|
|
|
*/ |
27
|
|
|
private $model; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var array |
31
|
|
|
*/ |
32
|
|
|
private $options; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param \Mautic\CoreBundle\Model\CommonModel $model |
36
|
|
|
* @param array $options |
37
|
|
|
*/ |
38
|
|
|
public function __construct($model, $options = []) |
39
|
|
|
{ |
40
|
|
|
$this->model = $model; |
41
|
|
|
$this->options = $options; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
|
|
public static function getSubscribedEvents() |
48
|
|
|
{ |
49
|
|
|
return [FormEvents::PRE_SET_DATA => 'preSetData']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function preSetData(FormEvent $event) |
53
|
|
|
{ |
54
|
|
|
$id = !empty($this->options['data']) ? $this->options['data']->getId() : 0; |
55
|
|
|
if ($id && empty($this->options['ignore_formexit'])) { |
56
|
|
|
//add a hidden field that is used exclusively to warn a user to use save/cancel to exit a form |
57
|
|
|
$form = $event->getForm(); |
58
|
|
|
|
59
|
|
|
$form->add( |
60
|
|
|
'unlockModel', |
61
|
|
|
HiddenType::class, |
62
|
|
|
[ |
63
|
|
|
'data' => $this->model, |
64
|
|
|
'required' => false, |
65
|
|
|
'mapped' => false, |
66
|
|
|
'attr' => ['class' => 'form-exit-unlock-model'], |
67
|
|
|
] |
68
|
|
|
); |
69
|
|
|
|
70
|
|
|
$form->add( |
71
|
|
|
'unlockId', |
72
|
|
|
HiddenType::class, |
73
|
|
|
[ |
74
|
|
|
'data' => $id, |
75
|
|
|
'required' => false, |
76
|
|
|
'mapped' => false, |
77
|
|
|
'attr' => ['class' => 'form-exit-unlock-id'], |
78
|
|
|
] |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
if (isset($this->options['unlockParameter'])) { |
82
|
|
|
$form->add( |
83
|
|
|
'unlockParameter', |
84
|
|
|
HiddenType::class, |
85
|
|
|
[ |
86
|
|
|
'data' => $this->options['unlockParameter'], |
87
|
|
|
'required' => false, |
88
|
|
|
'mapped' => false, |
89
|
|
|
'attr' => ['class' => 'form-exit-unlock-parameter'], |
90
|
|
|
] |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths