These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\PagePartBundle\Controller; |
||
4 | |||
5 | use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface; |
||
6 | use Kunstmaan\PagePartBundle\Helper\PagePartInterface; |
||
7 | use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdmin; |
||
8 | use Symfony\Component\Routing\Annotation\Route; |
||
9 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
||
10 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
11 | use Symfony\Component\Form\Extension\Core\Type\FormType; |
||
12 | use Symfony\Component\HttpFoundation\Request; |
||
13 | |||
14 | /** |
||
15 | * Controller for the pagepart administration |
||
16 | */ |
||
17 | class PagePartAdminController extends Controller |
||
0 ignored issues
–
show
|
|||
18 | { |
||
19 | /** |
||
20 | * @Route("/newPagePart", name="KunstmaanPagePartBundle_admin_newpagepart") |
||
21 | * @Template("KunstmaanPagePartBundle:PagePartAdminTwigExtension:pagepart.html.twig") |
||
22 | * |
||
23 | * @param \Symfony\Component\HttpFoundation\Request $request |
||
24 | * |
||
25 | * @return array |
||
26 | */ |
||
27 | public function newPagePartAction(Request $request) |
||
28 | { |
||
29 | $em = $this->get('doctrine.orm.entity_manager'); |
||
30 | |||
31 | $pageId = $request->get('pageid'); |
||
32 | $pageClassName = $request->get('pageclassname'); |
||
33 | $context = $request->get('context'); |
||
34 | $pagePartClass = $request->get('type'); |
||
35 | |||
36 | /** @var HasPagePartsInterface $page */ |
||
37 | $page = $em->getRepository($pageClassName)->find($pageId); |
||
38 | |||
39 | if (false === $page instanceof HasPagePartsInterface) { |
||
40 | throw new \RuntimeException(sprintf('Given page (%s:%d) has no pageparts', $pageClassName, $pageId)); |
||
41 | } |
||
42 | |||
43 | $pagePartConfigurationReader = $this->container->get('kunstmaan_page_part.page_part_configuration_reader'); |
||
44 | $pagePartAdminConfigurators = $pagePartConfigurationReader->getPagePartAdminConfigurators($page); |
||
45 | |||
46 | $pagePartAdminConfigurator = null; |
||
47 | foreach ($pagePartAdminConfigurators as $ppac) { |
||
48 | if ($context == $ppac->getContext()) { |
||
49 | $pagePartAdminConfigurator = $ppac; |
||
50 | } |
||
51 | } |
||
52 | |||
53 | if (is_null($pagePartAdminConfigurator)) { |
||
54 | throw new \RuntimeException(sprintf('No page part admin configurator found for context "%s".', $context)); |
||
55 | } |
||
56 | |||
57 | $pagePartAdmin = new PagePartAdmin($pagePartAdminConfigurator, $em, $page, $context, $this->container); |
||
58 | /** @var PagePartInterface $pagePart */ |
||
59 | $pagePart = new $pagePartClass(); |
||
60 | |||
61 | if (false === $pagePart instanceof PagePartInterface) { |
||
62 | throw new \RuntimeException(sprintf( |
||
63 | 'Given pagepart expected to implement PagePartInterface, %s given', |
||
64 | $pagePartClass |
||
65 | )); |
||
66 | } |
||
67 | |||
68 | $formFactory = $this->container->get('form.factory'); |
||
69 | $formBuilder = $formFactory->createBuilder(FormType::class); |
||
70 | $pagePartAdmin->adaptForm($formBuilder); |
||
71 | $id = 'newpp_' . time(); |
||
72 | |||
73 | $data = $formBuilder->getData(); |
||
74 | $data['pagepartadmin_' . $id] = $pagePart; |
||
75 | |||
76 | $formBuilder->add('pagepartadmin_' . $id, $pagePart->getDefaultAdminType()); |
||
77 | $formBuilder->setData($data); |
||
78 | $form = $formBuilder->getForm(); |
||
79 | $formview = $form->createView(); |
||
80 | $extended = $this->getParameter('kunstmaan_page_part.extended'); |
||
81 | |||
82 | return [ |
||
83 | 'id' => $id, |
||
84 | 'form' => $formview, |
||
85 | 'pagepart' => $pagePart, |
||
86 | 'pagepartadmin' => $pagePartAdmin, |
||
87 | 'page' => $pagePartAdmin->getPage(), |
||
88 | 'editmode' => true, |
||
89 | 'extended' => $extended, |
||
90 | ]; |
||
91 | } |
||
92 | } |
||
93 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.