1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Kunstmaan\PagePartBundle\Helper\FormWidgets; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\EntityManager; |
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
7
|
|
|
use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget; |
8
|
|
|
use Kunstmaan\NodeBundle\Entity\HasNodeInterface; |
9
|
|
|
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; |
10
|
|
|
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdmin; |
11
|
|
|
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminConfiguratorInterface; |
12
|
|
|
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdminFactory; |
13
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
14
|
|
|
use Symfony\Component\Form\FormView; |
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
16
|
|
|
|
17
|
|
|
class PagePartWidget extends FormWidget |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var EntityManagerInterface |
21
|
|
|
*/ |
22
|
|
|
protected $em; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var PagePartAdminFactory |
26
|
|
|
*/ |
27
|
|
|
protected $pagePartAdminFactory; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var PagePartAdmin |
31
|
|
|
*/ |
32
|
|
|
protected $pagePartAdmin; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var HasNodeInterface |
36
|
|
|
*/ |
37
|
|
|
protected $page; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var Request |
41
|
|
|
*/ |
42
|
|
|
protected $request; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var PagePartAdminConfiguratorInterface |
46
|
|
|
*/ |
47
|
|
|
protected $pagePartAdminConfigurator; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param HasPagePartsInterface $page The page |
51
|
|
|
* @param Request $request The request |
52
|
|
|
* @param EntityManagerInterface $em The entity manager |
53
|
|
|
* @param PagePartAdminConfiguratorInterface $pagePartAdminConfigurator The page part admin configurator |
54
|
|
|
* @param PagePartAdminFactory $pagePartAdminFactory The page part admin factory |
55
|
|
|
*/ |
56
|
|
|
public function __construct(HasPagePartsInterface $page, Request $request, EntityManagerInterface $em, PagePartAdminConfiguratorInterface $pagePartAdminConfigurator, PagePartAdminFactory $pagePartAdminFactory) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
parent::__construct(); |
59
|
|
|
|
60
|
|
|
$this->page = $page; |
61
|
|
|
$this->em = $em; |
62
|
|
|
$this->pagePartAdminFactory = $pagePartAdminFactory; |
63
|
|
|
$this->request = $request; |
64
|
|
|
$this->pagePartAdminConfigurator = $pagePartAdminConfigurator; |
65
|
|
|
|
66
|
|
|
$this->pagePartAdmin = $pagePartAdminFactory->createList($pagePartAdminConfigurator, $em, $page); |
67
|
|
|
$this->setTemplate('@KunstmaanPagePart/FormWidgets/PagePartWidget/widget.html.twig'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param FormBuilderInterface $builder The form builder |
72
|
|
|
*/ |
73
|
|
|
public function buildForm(FormBuilderInterface $builder) |
74
|
|
|
{ |
75
|
|
|
parent::buildForm($builder); |
76
|
|
|
|
77
|
|
|
$this->pagePartAdmin->preBindRequest($this->request); |
78
|
|
|
$this->pagePartAdmin->adaptForm($builder); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param Request $request |
83
|
|
|
*/ |
84
|
|
|
public function bindRequest(Request $request) |
85
|
|
|
{ |
86
|
|
|
parent::bindRequest($request); |
87
|
|
|
|
88
|
|
|
$this->pagePartAdmin->bindRequest($request); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param EntityManager $em The entity manager |
93
|
|
|
*/ |
94
|
|
|
public function persist(EntityManager $em) |
95
|
|
|
{ |
96
|
|
|
parent::persist($em); |
97
|
|
|
|
98
|
|
|
$this->pagePartAdmin->persist($this->request); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @param FormView $formView |
103
|
|
|
* |
104
|
|
|
* @return array |
105
|
|
|
*/ |
106
|
|
|
public function getFormErrors(FormView $formView) |
107
|
|
|
{ |
108
|
|
|
$errors = parent::getFormErrors($formView); |
109
|
|
|
|
110
|
|
|
$formHelper = $this->getFormHelper(); |
111
|
|
|
$key = 'pagepartadmin_' . $this->pagePartAdmin->getContext(); |
112
|
|
|
if (isset($formView[$key])) { |
113
|
|
|
$errors = array_merge($errors, $formHelper->getRecursiveErrorMessages($formView['pagepartadmin_' . $this->pagePartAdmin->getContext()])); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
return $errors; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return PagePartAdmin |
121
|
|
|
*/ |
122
|
|
|
public function getPagePartAdmin() |
123
|
|
|
{ |
124
|
|
|
return $this->pagePartAdmin; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param Request $request |
129
|
|
|
* |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getExtraParams(Request $request) |
133
|
|
|
{ |
134
|
|
|
$params = array(); |
135
|
|
|
$editPagePart = $request->get('edit'); |
136
|
|
|
if (isset($editPagePart)) { |
137
|
|
|
$params['editpagepart'] = $editPagePart; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return $params; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return PagePartAdminConfiguratorInterface |
145
|
|
|
*/ |
146
|
|
|
public function getPagePartAdminConfigurator() |
147
|
|
|
{ |
148
|
|
|
return $this->pagePartAdminConfigurator; |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|