Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

NodeBundle/Controller/NodeAdminController.php (1 issue)

Upgrade to new PHP Analysis Engine

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\NodeBundle\Controller;
4
5
use DateTime;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\EntityManager;
8
use InvalidArgumentException;
9
use Kunstmaan\AdminBundle\Entity\BaseUser;
10
use Kunstmaan\AdminBundle\Entity\EntityInterface;
11
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
12
use Kunstmaan\AdminBundle\Helper\FormWidgets\FormWidget;
13
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\Tab;
14
use Kunstmaan\AdminBundle\Helper\FormWidgets\Tabs\TabPane;
15
use Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper;
16
use Kunstmaan\AdminBundle\Helper\Security\Acl\Permission\PermissionMap;
17
use Kunstmaan\AdminBundle\Service\AclManager;
18
use Kunstmaan\AdminListBundle\AdminList\AdminList;
19
use Kunstmaan\NodeBundle\AdminList\NodeAdminListConfigurator;
20
use Kunstmaan\NodeBundle\Entity\HasNodeInterface;
21
use Kunstmaan\NodeBundle\Entity\Node;
22
use Kunstmaan\NodeBundle\Entity\NodeTranslation;
23
use Kunstmaan\NodeBundle\Entity\NodeVersion;
24
use Kunstmaan\NodeBundle\Event\AdaptFormEvent;
25
use Kunstmaan\NodeBundle\Event\CopyPageTranslationNodeEvent;
26
use Kunstmaan\NodeBundle\Event\Events;
27
use Kunstmaan\NodeBundle\Event\NodeEvent;
28
use Kunstmaan\NodeBundle\Event\RecopyPageTranslationNodeEvent;
29
use Kunstmaan\NodeBundle\Event\RevertNodeAction;
30
use Kunstmaan\NodeBundle\Form\NodeMenuTabAdminType;
31
use Kunstmaan\NodeBundle\Form\NodeMenuTabTranslationAdminType;
32
use Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeAdminPublisher;
33
use Kunstmaan\NodeBundle\Helper\NodeAdmin\NodeVersionLockHelper;
34
use Kunstmaan\NodeBundle\Repository\NodeVersionRepository;
35
use Kunstmaan\UtilitiesBundle\Helper\ClassLookup;
36
use Symfony\Component\Routing\Annotation\Route;
37
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
38
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
39
use Symfony\Component\HttpFoundation\JsonResponse;
40
use Symfony\Component\HttpFoundation\RedirectResponse;
41
use Symfony\Component\HttpFoundation\Request;
42
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
43
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
44
use Symfony\Component\Translation\TranslatorInterface;
45
46
/**
47
 * NodeAdminController
48
 */
49
class NodeAdminController extends Controller
50
{
51
    /**
52
     * @var EntityManager
53
     */
54
    protected $em;
55
56
    /**
57
     * @var string
58
     */
59
    protected $locale;
60
61
    /**
62
     * @var AuthorizationCheckerInterface
63
     */
64
    protected $authorizationChecker;
65
66
    /**
67
     * @var BaseUser
68
     */
69
    protected $user;
70
71
    /**
72
     * @var AclHelper
73
     */
74
    protected $aclHelper;
75
76
    /**
77
     * @var AclManager
78
     */
79
    protected $aclManager;
80
81
    /**
82
     * @var NodeAdminPublisher
83
     */
84
    protected $nodePublisher;
85
86
    /**
87
     * @var TranslatorInterface
88
     */
89
    protected $translator;
90
91
    /**
92
     * init
93
     *
94
     * @param Request $request
95
     */
96
    protected function init(Request $request)
97
    {
98
        $this->em = $this->getDoctrine()->getManager();
99
        $this->locale = $request->getLocale();
100
        $this->authorizationChecker = $this->container->get('security.authorization_checker');
101
        $this->user = $this->getUser();
102
        $this->aclHelper = $this->container->get('kunstmaan_admin.acl.helper');
103
        $this->aclManager = $this->container->get('kunstmaan_admin.acl.manager');
104
        $this->nodePublisher = $this->container->get('kunstmaan_node.admin_node.publisher');
105
        $this->translator = $this->container->get('translator');
106
    }
107
108
    /**
109
     * @Route("/", name="KunstmaanNodeBundle_nodes")
110
     * @Template("KunstmaanNodeBundle:Admin:list.html.twig")
111
     *
112
     * @param Request $request
113
     *
114
     * @return array
115
     */
116
    public function indexAction(Request $request)
117
    {
118
        $this->init($request);
119
120
        $nodeAdminListConfigurator = new NodeAdminListConfigurator(
121
            $this->em,
122
            $this->aclHelper,
123
            $this->locale,
124
            PermissionMap::PERMISSION_VIEW,
125
            $this->authorizationChecker
126
        );
127
128
        $locale = $this->locale;
129
        $acl = $this->authorizationChecker;
130
        $itemRoute = function (EntityInterface $item) use ($locale, $acl) {
131
            if ($acl->isGranted(PermissionMap::PERMISSION_VIEW, $item->getNode())) {
132
                return array(
133
                    'path' => '_slug_preview',
134
                    'params' => ['_locale' => $locale, 'url' => $item->getUrl()],
135
                );
136
            }
137
        };
138
        $nodeAdminListConfigurator->addSimpleItemAction('action.preview', $itemRoute, 'eye');
139
        $nodeAdminListConfigurator->setDomainConfiguration($this->get('kunstmaan_admin.domain_configuration'));
140
        $nodeAdminListConfigurator->setShowAddHomepage($this->getParameter('kunstmaan_node.show_add_homepage') && $this->isGranted('ROLE_SUPER_ADMIN'));
141
142
        /** @var AdminList $adminlist */
143
        $adminlist = $this->get('kunstmaan_adminlist.factory')->createList($nodeAdminListConfigurator);
144
        $adminlist->bindRequest($request);
145
146
        return array(
147
            'adminlist' => $adminlist,
148
        );
149
    }
150
151
    /**
152
     * @Route(
153
     *      "/{id}/copyfromotherlanguage",
154
     *      requirements={"id" = "\d+"},
155
     *      name="KunstmaanNodeBundle_nodes_copyfromotherlanguage",
156
     *      methods={"GET"}
157
     * )
158
     *
159
     * @param Request $request
160
     * @param int     $id      The node id
161
     *
162
     * @return RedirectResponse
163
     *
164
     * @throws AccessDeniedException
165
     */
166
    public function copyFromOtherLanguageAction(Request $request, $id)
167
    {
168
        $this->init($request);
169
        /* @var Node $node */
170
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
171
172
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
173
174
        $originalLanguage = $request->get('originallanguage');
175
        $otherLanguageNodeTranslation = $node->getNodeTranslation($originalLanguage, true);
176
        $otherLanguageNodeNodeVersion = $otherLanguageNodeTranslation->getPublicNodeVersion();
177
        $otherLanguagePage = $otherLanguageNodeNodeVersion->getRef($this->em);
178
        $myLanguagePage = $this->get('kunstmaan_admin.clone.helper')
179
            ->deepCloneAndSave($otherLanguagePage);
180
181
        /* @var NodeTranslation $nodeTranslation */
182
        $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
183
            ->createNodeTranslationFor($myLanguagePage, $this->locale, $node, $this->user);
184
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
185
186
        $this->get('event_dispatcher')->dispatch(
187
            Events::COPY_PAGE_TRANSLATION,
188
            new CopyPageTranslationNodeEvent(
189
                $node,
190
                $nodeTranslation,
191
                $nodeVersion,
192
                $myLanguagePage,
193
                $otherLanguageNodeTranslation,
194
                $otherLanguageNodeNodeVersion,
195
                $otherLanguagePage,
196
                $originalLanguage
197
            )
198
        );
199
200
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id)));
201
    }
202
203
    /**
204
     * @Route(
205
     *      "/{id}/recopyfromotherlanguage",
206
     *      requirements={"id" = "\d+"},
207
     *      name="KunstmaanNodeBundle_nodes_recopyfromotherlanguage",
208
     *      methods={"POST"}
209
     * )
210
     *
211
     * @param Request $request
212
     * @param int     $id      The node id
213
     *
214
     * @return RedirectResponse
215
     *
216
     * @throws AccessDeniedException
217
     */
218
    public function recopyFromOtherLanguageAction(Request $request, $id)
219
    {
220
        $this->init($request);
221
        /* @var Node $node */
222
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
223
224
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
225
226
        $otherLanguageNodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')->find($request->get('source'));
227
        $otherLanguageNodeNodeVersion = $otherLanguageNodeTranslation->getPublicNodeVersion();
228
        $otherLanguagePage = $otherLanguageNodeNodeVersion->getRef($this->em);
229
        $myLanguagePage = $this->get('kunstmaan_admin.clone.helper')
230
            ->deepCloneAndSave($otherLanguagePage);
231
232
        /* @var NodeTranslation $nodeTranslation */
233
        $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
234
            ->addDraftNodeVersionFor($myLanguagePage, $this->locale, $node, $this->user);
235
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
236
237
        $this->get('event_dispatcher')->dispatch(
238
            Events::RECOPY_PAGE_TRANSLATION,
239
            new RecopyPageTranslationNodeEvent(
240
                $node,
241
                $nodeTranslation,
242
                $nodeVersion,
243
                $myLanguagePage,
244
                $otherLanguageNodeTranslation,
245
                $otherLanguageNodeNodeVersion,
246
                $otherLanguagePage,
247
                $otherLanguageNodeTranslation->getLang()
248
            )
249
        );
250
251
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id, 'subaction' => NodeVersion::DRAFT_VERSION)));
252
    }
253
254
    /**
255
     * @Route(
256
     *      "/{id}/createemptypage",
257
     *      requirements={"id" = "\d+"},
258
     *      name="KunstmaanNodeBundle_nodes_createemptypage",
259
     *      methods={"GET"}
260
     * )
261
     *
262
     * @param Request $request
263
     * @param int     $id
264
     *
265
     * @return RedirectResponse
266
     *
267
     * @throws AccessDeniedException
268
     */
269
    public function createEmptyPageAction(Request $request, $id)
270
    {
271
        $this->init($request);
272
        /* @var Node $node */
273
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
274
275
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
276
277
        $entityName = $node->getRefEntityName();
278
        /* @var HasNodeInterface $myLanguagePage */
279
        $myLanguagePage = new $entityName();
280
        $myLanguagePage->setTitle('New page');
281
282
        $this->em->persist($myLanguagePage);
283
        $this->em->flush();
284
        /* @var NodeTranslation $nodeTranslation */
285
        $nodeTranslation = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
286
            ->createNodeTranslationFor($myLanguagePage, $this->locale, $node, $this->user);
287
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
288
289
        $this->get('event_dispatcher')->dispatch(
290
            Events::ADD_EMPTY_PAGE_TRANSLATION,
291
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $myLanguagePage)
292
        );
293
294
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id)));
295
    }
296
297
    /**
298
     * @Route("/{id}/publish", requirements={"id" =
299
     *                         "\d+"},
300
     *                         name="KunstmaanNodeBundle_nodes_publish", methods={"GET", "POST"})
301
     *
302
     * @param Request $request
303
     * @param int     $id
304
     *
305
     * @return RedirectResponse
306
     *
307
     * @throws AccessDeniedException
308
     */
309 View Code Duplication
    public function publishAction(Request $request, $id)
310
    {
311
        $this->init($request);
312
        /* @var Node $node */
313
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
314
315
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
316
        $request = $this->get('request_stack')->getCurrentRequest();
317
        $this->nodePublisher->chooseHowToPublish($request, $nodeTranslation, $this->translator);
318
319
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId())));
320
    }
321
322
    /**
323
     * @Route(
324
     *      "/{id}/unpublish",
325
     *      requirements={"id" = "\d+"},
326
     *      name="KunstmaanNodeBundle_nodes_unpublish",
327
     *      methods={"GET", "POST"}
328
     * )
329
     *
330
     * @param Request $request
331
     * @param int     $id
332
     *
333
     * @return RedirectResponse
334
     *
335
     * @throws AccessDeniedException
336
     */
337 View Code Duplication
    public function unPublishAction(Request $request, $id)
338
    {
339
        $this->init($request);
340
        /* @var Node $node */
341
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
342
343
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
344
        $request = $this->get('request_stack')->getCurrentRequest();
345
        $this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator);
346
347
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $node->getId())));
348
    }
349
350
    /**
351
     * @Route(
352
     *      "/{id}/unschedulepublish",
353
     *      requirements={"id" = "\d+"},
354
     *      name="KunstmaanNodeBundle_nodes_unschedule_publish",
355
     *      methods={"GET", "POST"}
356
     * )
357
     *
358
     * @param Request $request
359
     * @param int     $id
360
     *
361
     * @return RedirectResponse
362
     *
363
     * @throws AccessDeniedException
364
     */
365 View Code Duplication
    public function unSchedulePublishAction(Request $request, $id)
366
    {
367
        $this->init($request);
368
369
        /* @var Node $node */
370
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
371
372
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
373
        $this->nodePublisher->unSchedulePublish($nodeTranslation);
374
375
        $this->addFlash(
376
            FlashTypes::SUCCESS,
377
            $this->get('translator')->trans('kuma_node.admin.unschedule.flash.success')
378
        );
379
380
        return $this->redirect($this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $id)));
381
    }
382
383
    /**
384
     * @Route(
385
     *      "/{id}/delete",
386
     *      requirements={"id" = "\d+"},
387
     *      name="KunstmaanNodeBundle_nodes_delete",
388
     *      methods={"POST"}
389
     * )
390
     *
391
     * @param Request $request
392
     * @param int     $id
393
     *
394
     * @return RedirectResponse
395
     *
396
     * @throws AccessDeniedException
397
     */
398
    public function deleteAction(Request $request, $id)
399
    {
400
        $this->init($request);
401
        /* @var Node $node */
402
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
403
404
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_DELETE, $node);
405
406
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
407
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
408
        $page = $nodeVersion->getRef($this->em);
409
410
        $this->get('event_dispatcher')->dispatch(
411
            Events::PRE_DELETE,
412
            new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
413
        );
414
415
        $node->setDeleted(true);
416
        $this->em->persist($node);
417
418
        $children = $node->getChildren();
419
        $this->deleteNodeChildren($this->em, $this->user, $this->locale, $children);
420
        $this->em->flush();
421
422
        $event = new NodeEvent($node, $nodeTranslation, $nodeVersion, $page);
423
        $this->get('event_dispatcher')->dispatch(Events::POST_DELETE, $event);
424
        if (null === $response = $event->getResponse()) {
425
            $nodeParent = $node->getParent();
426
            // Check if we have a parent. Otherwise redirect to pages overview.
427
            if ($nodeParent) {
428
                $url = $this->get('router')->generate(
429
                    'KunstmaanNodeBundle_nodes_edit',
430
                    array('id' => $nodeParent->getId())
431
                );
432
            } else {
433
                $url = $this->get('router')->generate(
434
                    'KunstmaanNodeBundle_nodes'
435
                );
436
            }
437
            $response = new RedirectResponse($url);
438
        }
439
440
        $this->addFlash(
441
            FlashTypes::SUCCESS,
442
            $this->get('translator')->trans('kuma_node.admin.delete.flash.success')
443
        );
444
445
        return $response;
446
    }
447
448
    /**
449
     * @Route(
450
     *      "/{id}/duplicate",
451
     *      requirements={"id" = "\d+"},
452
     *      name="KunstmaanNodeBundle_nodes_duplicate",
453
     *      methods={"POST"}
454
     * )
455
     *
456
     * @param Request $request
457
     * @param int     $id
458
     *
459
     * @return RedirectResponse
460
     *
461
     * @throws AccessDeniedException
462
     */
463
    public function duplicateAction(Request $request, $id)
464
    {
465
        $this->init($request);
466
        /* @var Node $parentNode */
467
        $originalNode = $this->em->getRepository('KunstmaanNodeBundle:Node')
468
            ->find($id);
469
470
        // Check with Acl
471
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $originalNode);
472
473
        $request = $this->get('request_stack')->getCurrentRequest();
474
475
        $originalNodeTranslations = $originalNode->getNodeTranslation($this->locale, true);
476
        $originalRef = $originalNodeTranslations->getPublicNodeVersion()->getRef($this->em);
477
        $newPage = $this->get('kunstmaan_admin.clone.helper')
478
            ->deepCloneAndSave($originalRef);
479
480
        //set the title
481
        $title = $request->get('title');
482
        if (\is_string($title) && !empty($title)) {
483
            $newPage->setTitle($title);
484
        } else {
485
            $newPage->setTitle('New page');
486
        }
487
488
        //set the parent
489
        $parentNodeTranslation = $originalNode->getParent()->getNodeTranslation($this->locale, true);
490
        $parent = $parentNodeTranslation->getPublicNodeVersion()->getRef($this->em);
491
        $newPage->setParent($parent);
492
        $this->em->persist($newPage);
493
        $this->em->flush();
494
495
        /* @var Node $nodeNewPage */
496
        $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node')->createNodeFor(
497
            $newPage,
498
            $this->locale,
499
            $this->user
500
        );
501
502
        $nodeTranslation = $nodeNewPage->getNodeTranslation($this->locale, true);
503
        if ($newPage->isStructureNode()) {
504
            $nodeTranslation->setSlug('');
505
            $this->em->persist($nodeTranslation);
506
        }
507
        $this->em->flush();
508
509
        $this->aclManager->updateNodeAcl($originalNode, $nodeNewPage);
510
511
        $this->addFlash(
512
            FlashTypes::SUCCESS,
513
            $this->get('translator')->trans('kuma_node.admin.duplicate.flash.success')
514
        );
515
516
        return $this->redirect(
517
            $this->generateUrl('KunstmaanNodeBundle_nodes_edit', array('id' => $nodeNewPage->getId()))
518
        );
519
    }
520
521
    /**
522
     * @Route(
523
     *      "/{id}/revert",
524
     *      requirements={"id" = "\d+"},
525
     *      defaults={"subaction" = "public"},
526
     *      name="KunstmaanNodeBundle_nodes_revert",
527
     *      methods={"GET"}
528
     * )
529
     *
530
     * @param Request $request
531
     * @param int     $id      The node id
532
     *
533
     * @return RedirectResponse
534
     *
535
     * @throws AccessDeniedException
536
     * @throws InvalidArgumentException
537
     */
538
    public function revertAction(Request $request, $id)
539
    {
540
        $this->init($request);
541
        /* @var Node $node */
542
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
543
544
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
545
546
        $version = $request->get('version');
547
548
        if (empty($version) || !is_numeric($version)) {
549
            throw new InvalidArgumentException('No version was specified');
550
        }
551
552
        /* @var NodeVersionRepository $nodeVersionRepo */
553
        $nodeVersionRepo = $this->em->getRepository('KunstmaanNodeBundle:NodeVersion');
554
        /* @var NodeVersion $nodeVersion */
555
        $nodeVersion = $nodeVersionRepo->find($version);
556
557
        if (\is_null($nodeVersion)) {
558
            throw new InvalidArgumentException('Version does not exist');
559
        }
560
561
        /* @var NodeTranslation $nodeTranslation */
562
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
563
        $page = $nodeVersion->getRef($this->em);
564
        /* @var HasNodeInterface $clonedPage */
565
        $clonedPage = $this->get('kunstmaan_admin.clone.helper')
566
            ->deepCloneAndSave($page);
567
        $newNodeVersion = $nodeVersionRepo->createNodeVersionFor(
568
            $clonedPage,
569
            $nodeTranslation,
570
            $this->user,
571
            $nodeVersion,
572
            'draft'
573
        );
574
575
        $nodeTranslation->setTitle($clonedPage->getTitle());
576
        $this->em->persist($nodeTranslation);
577
        $this->em->flush();
578
579
        $this->get('event_dispatcher')->dispatch(
580
            Events::REVERT,
581
            new RevertNodeAction(
582
                $node,
583
                $nodeTranslation,
584
                $newNodeVersion,
585
                $clonedPage,
586
                $nodeVersion,
587
                $page
588
            )
589
        );
590
591
        $this->addFlash(
592
            FlashTypes::SUCCESS,
593
            $this->get('translator')->trans('kuma_node.admin.revert.flash.success')
594
        );
595
596
        return $this->redirect(
597
            $this->generateUrl(
598
                'KunstmaanNodeBundle_nodes_edit',
599
                array(
600
                    'id' => $id,
601
                    'subaction' => 'draft',
602
                )
603
            )
604
        );
605
    }
606
607
    /**
608
     * @Route(
609
     *      "/{id}/add",
610
     *      requirements={"id" = "\d+"},
611
     *      name="KunstmaanNodeBundle_nodes_add",
612
     *      methods={"POST"}
613
     * )
614
     *
615
     * @param Request $request
616
     * @param int     $id
617
     *
618
     * @return RedirectResponse
619
     *
620
     * @throws AccessDeniedException
621
     * @throws InvalidArgumentException
622
     */
623
    public function addAction(Request $request, $id)
624
    {
625
        $this->init($request);
626
        /* @var Node $parentNode */
627
        $parentNode = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
628
629
        // Check with Acl
630
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $parentNode);
631
632
        $parentNodeTranslation = $parentNode->getNodeTranslation($this->locale, true);
633
        $parentNodeVersion = $parentNodeTranslation->getPublicNodeVersion();
634
        $parentPage = $parentNodeVersion->getRef($this->em);
635
636
        $type = $this->validatePageType($request);
637
        $newPage = $this->createNewPage($request, $type);
638
        $newPage->setParent($parentPage);
639
640
        /* @var Node $nodeNewPage */
641
        $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node')
642
            ->createNodeFor($newPage, $this->locale, $this->user);
643
        $nodeTranslation = $nodeNewPage->getNodeTranslation(
644
            $this->locale,
645
            true
646
        );
647
        $weight = $this->em->getRepository('KunstmaanNodeBundle:NodeTranslation')
648
                ->getMaxChildrenWeight($parentNode, $this->locale) + 1;
649
        $nodeTranslation->setWeight($weight);
650
651
        if ($newPage->isStructureNode()) {
652
            $nodeTranslation->setSlug('');
653
        }
654
655
        $this->em->persist($nodeTranslation);
656
        $this->em->flush();
657
658
        $this->aclManager->updateNodeAcl($parentNode, $nodeNewPage);
659
660
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
661
662
        $this->get('event_dispatcher')->dispatch(
663
            Events::ADD_NODE,
664
            new NodeEvent(
665
                $nodeNewPage, $nodeTranslation, $nodeVersion, $newPage
666
            )
667
        );
668
669
        return $this->redirect(
670
            $this->generateUrl(
671
                'KunstmaanNodeBundle_nodes_edit',
672
                array('id' => $nodeNewPage->getId())
673
            )
674
        );
675
    }
676
677
    /**
678
     * @Route("/add-homepage", name="KunstmaanNodeBundle_nodes_add_homepage", methods={"POST"})
679
     *
680
     * @return RedirectResponse
681
     *
682
     * @throws AccessDeniedException
683
     * @throws InvalidArgumentException
684
     */
685
    public function addHomepageAction(Request $request)
686
    {
687
        $this->init($request);
688
689
        // Check with Acl
690
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
691
692
        $type = $this->validatePageType($request);
693
694
        $newPage = $this->createNewPage($request, $type);
695
696
        /* @var Node $nodeNewPage */
697
        $nodeNewPage = $this->em->getRepository('KunstmaanNodeBundle:Node')
698
            ->createNodeFor($newPage, $this->locale, $this->user);
699
        $nodeTranslation = $nodeNewPage->getNodeTranslation(
700
            $this->locale,
701
            true
702
        );
703
        $this->em->flush();
704
705
        // Set default permissions
706
        $this->container->get('kunstmaan_node.acl_permission_creator_service')
707
            ->createPermission($nodeNewPage);
708
709
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
710
711
        $this->get('event_dispatcher')->dispatch(
712
            Events::ADD_NODE,
713
            new NodeEvent(
714
                $nodeNewPage, $nodeTranslation, $nodeVersion, $newPage
715
            )
716
        );
717
718
        return $this->redirect(
719
            $this->generateUrl(
720
                'KunstmaanNodeBundle_nodes_edit',
721
                array('id' => $nodeNewPage->getId())
722
            )
723
        );
724
    }
725
726
    /**
727
     * @Route("/reorder", name="KunstmaanNodeBundle_nodes_reorder", methods={"POST"})
728
     *
729
     * @param Request $request
730
     *
731
     * @return string
732
     *
733
     * @throws AccessDeniedException
734
     */
735
    public function reorderAction(Request $request)
736
    {
737
        $this->init($request);
738
        $nodes = array();
739
        $nodeIds = $request->get('nodes');
740
        $changeParents = $request->get('parent');
741
742
        foreach ($nodeIds as $id) {
743
            /* @var Node $node */
744
            $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
745
            $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
746
            $nodes[] = $node;
747
        }
748
749
        $weight = 1;
750
        foreach ($nodes as $node) {
751
            $newParentId = isset($changeParents[$node->getId()]) ? $changeParents[$node->getId()] : null;
752
            if ($newParentId) {
753
                $parent = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($newParentId);
754
                $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $parent);
755
                $node->setParent($parent);
756
                $this->em->persist($node);
757
                $this->em->flush($node);
758
            }
759
760
            /* @var NodeTranslation $nodeTranslation */
761
            $nodeTranslation = $node->getNodeTranslation($this->locale, true);
762
763
            if ($nodeTranslation) {
764
                $nodeVersion = $nodeTranslation->getPublicNodeVersion();
765
                $page = $nodeVersion->getRef($this->em);
766
767
                $this->get('event_dispatcher')->dispatch(
768
                    Events::PRE_PERSIST,
769
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
770
                );
771
772
                $nodeTranslation->setWeight($weight);
773
                $this->em->persist($nodeTranslation);
774
                $this->em->flush($nodeTranslation);
775
776
                $this->get('event_dispatcher')->dispatch(
777
                    Events::POST_PERSIST,
778
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
779
                );
780
781
                ++$weight;
782
            }
783
        }
784
785
        return new JsonResponse(
786
            array(
787
                'Success' => 'The node-translations for [' . $this->locale . '] have got new weight values',
788
            )
789
        );
790
    }
791
792
    /**
793
     * @Route(
794
     *      "/{id}/{subaction}",
795
     *      requirements={"id" = "\d+"},
796
     *      defaults={"subaction" = "public"},
797
     *      name="KunstmaanNodeBundle_nodes_edit",
798
     *      methods={"GET", "POST"}
799
     * )
800
     * @Template("@KunstmaanNode/NodeAdmin/edit.html.twig")
801
     *
802
     * @param Request $request
803
     * @param int     $id        The node id
804
     * @param string  $subaction The subaction (draft|public)
805
     *
806
     * @return RedirectResponse|array
807
     *
808
     * @throws AccessDeniedException
809
     */
810
    public function editAction(Request $request, $id, $subaction)
811
    {
812
        $this->init($request);
813
        /* @var Node $node */
814
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
815
816
        $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
817
818
        $tabPane = new TabPane(
819
            'todo',
820
            $request,
821
            $this->container->get('form.factory')
822
        );
823
824
        $nodeTranslation = $node->getNodeTranslation($this->locale, true);
825
        if (!$nodeTranslation) {
826
            return $this->renderNodeNotTranslatedPage($node);
827
        }
828
829
        $nodeVersion = $nodeTranslation->getPublicNodeVersion();
830
        $draftNodeVersion = $nodeTranslation->getDraftNodeVersion();
831
        $nodeVersionIsLocked = false;
832
833
        /* @var HasNodeInterface $page */
834
        $page = null;
835
        $draft = ($subaction == 'draft');
836
        $saveAsDraft = $request->get('saveasdraft');
837
        if ((!$draft && !empty($saveAsDraft)) || ($draft && \is_null($draftNodeVersion))) {
838
            // Create a new draft version
839
            $draft = true;
840
            $subaction = 'draft';
841
            $page = $nodeVersion->getRef($this->em);
842
            $nodeVersion = $this->createDraftVersion(
843
                $page,
844
                $nodeTranslation,
845
                $nodeVersion
846
            );
847
            $draftNodeVersion = $nodeVersion;
848
        } elseif ($draft) {
849
            $nodeVersion = $draftNodeVersion;
850
            $page = $nodeVersion->getRef($this->em);
851
        } else {
852
            if ($request->getMethod() == 'POST') {
853
                $nodeVersionIsLocked = $this->isNodeVersionLocked($nodeTranslation, true);
854
855
                //Check the version timeout and make a new nodeversion if the timeout is passed
856
                $thresholdDate = date(
857
                    'Y-m-d H:i:s',
858
                    time() - $this->getParameter(
859
                        'kunstmaan_node.version_timeout'
860
                    )
861
                );
862
                $updatedDate = date(
863
                    'Y-m-d H:i:s',
864
                    strtotime($nodeVersion->getUpdated()->format('Y-m-d H:i:s'))
865
                );
866 View Code Duplication
                if ($thresholdDate >= $updatedDate || $nodeVersionIsLocked) {
867
                    $page = $nodeVersion->getRef($this->em);
868
                    if ($nodeVersion === $nodeTranslation->getPublicNodeVersion()) {
869
                        $this->nodePublisher
870
                            ->createPublicVersion(
871
                                $page,
872
                                $nodeTranslation,
873
                                $nodeVersion,
874
                                $this->user
875
                            );
876
                    } else {
877
                        $this->createDraftVersion(
878
                            $page,
879
                            $nodeTranslation,
880
                            $nodeVersion
881
                        );
882
                    }
883
                }
884
            }
885
            $page = $nodeVersion->getRef($this->em);
886
        }
887
        $isStructureNode = $page->isStructureNode();
888
889
        $menubuilder = $this->get('kunstmaan_node.actions_menu_builder');
890
        $menubuilder->setActiveNodeVersion($nodeVersion);
891
        $menubuilder->setEditableNode(!$isStructureNode);
892
893
        // Building the form
894
        $propertiesWidget = new FormWidget();
895
        $propertiesWidget->addType('main', $page->getDefaultAdminType(), $page);
896
        $propertiesWidget->addType('node', $node->getDefaultAdminType(), $node);
897
        $tabPane->addTab(new Tab('kuma_node.tab.properties.title', $propertiesWidget));
898
899
        // Menu tab
900
        $menuWidget = new FormWidget();
901
        $menuWidget->addType(
902
            'menunodetranslation',
903
            NodeMenuTabTranslationAdminType::class,
904
            $nodeTranslation,
905
            ['slugable' => !$isStructureNode]
906
        );
907
        $menuWidget->addType('menunode', NodeMenuTabAdminType::class, $node, ['available_in_nav' => !$isStructureNode]);
908
        $tabPane->addTab(new Tab('kuma_node.tab.menu.title', $menuWidget));
909
910
        $this->get('event_dispatcher')->dispatch(
911
            Events::ADAPT_FORM,
912
            new AdaptFormEvent(
913
                $request,
914
                $tabPane,
915
                $page,
916
                $node,
917
                $nodeTranslation,
918
                $nodeVersion
919
            )
920
        );
921
922
        $tabPane->buildForm();
923
924
        if ($request->getMethod() == 'POST') {
925
            $tabPane->bindRequest($request);
926
927
            // Don't redirect to listing when coming from ajax request, needed for url chooser.
928
            if ($tabPane->isValid() && !$request->isXmlHttpRequest()) {
929
                $this->get('event_dispatcher')->dispatch(
930
                    Events::PRE_PERSIST,
931
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
932
                );
933
934
                $nodeTranslation->setTitle($page->getTitle());
935
                if ($isStructureNode) {
936
                    $nodeTranslation->setSlug('');
937
                }
938
                $nodeVersion->setUpdated(new DateTime());
939
                if ($nodeVersion->getType() == 'public') {
940
                    $nodeTranslation->setUpdated($nodeVersion->getUpdated());
941
                }
942
                $this->em->persist($nodeTranslation);
943
                $this->em->persist($nodeVersion);
0 ignored issues
show
It seems like $nodeVersion defined by $draftNodeVersion on line 849 can be null; however, Doctrine\ORM\EntityManager::persist() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
944
                $tabPane->persist($this->em);
945
                $this->em->flush();
946
947
                $this->get('event_dispatcher')->dispatch(
948
                    Events::POST_PERSIST,
949
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
950
                );
951
952
                if ($nodeVersionIsLocked) {
953
                    $this->addFlash(
954
                        FlashTypes::SUCCESS,
955
                        $this->get('translator')->trans('kuma_node.admin.edit.flash.locked_success')
956
                    );
957
                } elseif ($request->request->has('publishing') || $request->request->has('publish_later')) {
958
                    $this->nodePublisher->chooseHowToPublish($request, $nodeTranslation, $this->translator);
959
                } elseif ($request->request->has('unpublishing') || $request->request->has('unpublish_later')) {
960
                    $this->nodePublisher->chooseHowToUnpublish($request, $nodeTranslation, $this->translator);
961
                } else {
962
                    $this->addFlash(
963
                        FlashTypes::SUCCESS,
964
                        $this->get('translator')->trans('kuma_node.admin.edit.flash.success')
965
                    );
966
                }
967
968
                $params = [
969
                    'id' => $node->getId(),
970
                    'subaction' => $subaction,
971
                    'currenttab' => $tabPane->getActiveTab(),
972
                ];
973
                $params = array_merge(
974
                    $params,
975
                    $tabPane->getExtraParams($request)
976
                );
977
978
                return $this->redirect(
979
                    $this->generateUrl(
980
                        'KunstmaanNodeBundle_nodes_edit',
981
                        $params
982
                    )
983
                );
984
            }
985
        }
986
987
        $nodeVersions = $this->em->getRepository(
988
            'KunstmaanNodeBundle:NodeVersion'
989
        )->findBy(
990
            ['nodeTranslation' => $nodeTranslation],
991
            ['updated' => 'ASC']
992
        );
993
        $queuedNodeTranslationAction = $this->em->getRepository(
994
            'KunstmaanNodeBundle:QueuedNodeTranslationAction'
995
        )->findOneBy(['nodeTranslation' => $nodeTranslation]);
996
997
        return [
998
            'page' => $page,
999
            'entityname' => ClassLookup::getClass($page),
1000
            'nodeVersions' => $nodeVersions,
1001
            'node' => $node,
1002
            'nodeTranslation' => $nodeTranslation,
1003
            'draft' => $draft,
1004
            'draftNodeVersion' => $draftNodeVersion,
1005
            'nodeVersion' => $nodeVersion,
1006
            'subaction' => $subaction,
1007
            'tabPane' => $tabPane,
1008
            'editmode' => true,
1009
            'queuedNodeTranslationAction' => $queuedNodeTranslationAction,
1010
            'nodeVersionLockCheck' => $this->container->getParameter('kunstmaan_node.lock_enabled'),
1011
            'nodeVersionLockInterval' => $this->container->getParameter('kunstmaan_node.lock_check_interval'),
1012
        ];
1013
    }
1014
1015
    /**
1016
     * @Route(
1017
     *      "checkNodeVersionLock/{id}/{public}",
1018
     *      requirements={"id" = "\d+", "public" = "(0|1)"},
1019
     *      name="KunstmaanNodeBundle_nodes_versionlock_check"
1020
     * )
1021
     *
1022
     * @param Request $request
1023
     * @param $id
1024
     *
1025
     * @return JsonResponse
1026
     */
1027
    public function checkNodeVersionLockAction(Request $request, $id, $public)
1028
    {
1029
        $nodeVersionIsLocked = false;
1030
        $message = '';
1031
        $this->init($request);
1032
1033
        /* @var Node $node */
1034
        $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
1035
1036
        try {
1037
            $this->checkPermission($node, PermissionMap::PERMISSION_EDIT);
1038
1039
            /** @var NodeVersionLockHelper $nodeVersionLockHelper */
1040
            $nodeVersionLockHelper = $this->get('kunstmaan_node.admin_node.node_version_lock_helper');
1041
            $nodeTranslation = $node->getNodeTranslation($this->locale, true);
1042
1043
            if ($nodeTranslation) {
1044
                $nodeVersionIsLocked = $nodeVersionLockHelper->isNodeVersionLocked($this->getUser(), $nodeTranslation, $public);
1045
1046
                if ($nodeVersionIsLocked) {
1047
                    $users = $nodeVersionLockHelper->getUsersWithNodeVersionLock($nodeTranslation, $public, $this->getUser());
1048
                    $message = $this->get('translator')->trans('kuma_node.admin.edit.flash.locked', array('%users%' => implode(', ', $users)));
1049
                }
1050
            }
1051
        } catch (AccessDeniedException $ade) {
1052
        }
1053
1054
        return new JsonResponse(['lock' => $nodeVersionIsLocked, 'message' => $message]);
1055
    }
1056
1057
    /**
1058
     * @param NodeTranslation $nodeTranslation
1059
     * @param bool            $isPublic
1060
     *
1061
     * @return bool
1062
     */
1063
    private function isNodeVersionLocked(NodeTranslation $nodeTranslation, $isPublic)
1064
    {
1065
        if ($this->container->getParameter('kunstmaan_node.lock_enabled')) {
1066
            /** @var NodeVersionLockHelper $nodeVersionLockHelper */
1067
            $nodeVersionLockHelper = $this->get('kunstmaan_node.admin_node.node_version_lock_helper');
1068
            $nodeVersionIsLocked = $nodeVersionLockHelper->isNodeVersionLocked($this->getUser(), $nodeTranslation, $isPublic);
1069
1070
            return $nodeVersionIsLocked;
1071
        }
1072
1073
        return false;
1074
    }
1075
1076
    /**
1077
     * @param HasNodeInterface $page            The page
1078
     * @param NodeTranslation  $nodeTranslation The node translation
1079
     * @param NodeVersion      $nodeVersion     The node version
1080
     *
1081
     * @return NodeVersion
1082
     */
1083
    private function createDraftVersion(
1084
        HasNodeInterface $page,
1085
        NodeTranslation $nodeTranslation,
1086
        NodeVersion $nodeVersion
1087
    ) {
1088
        $publicPage = $this->get('kunstmaan_admin.clone.helper')
1089
            ->deepCloneAndSave($page);
1090
        /* @var NodeVersion $publicNodeVersion */
1091
1092
        $publicNodeVersion = $this->em->getRepository(
1093
            'KunstmaanNodeBundle:NodeVersion'
1094
        )->createNodeVersionFor(
1095
            $publicPage,
1096
            $nodeTranslation,
1097
            $this->user,
1098
            $nodeVersion->getOrigin(),
1099
            'public',
1100
            $nodeVersion->getCreated()
1101
        );
1102
1103
        $nodeTranslation->setPublicNodeVersion($publicNodeVersion);
1104
        $nodeVersion->setType('draft');
1105
        $nodeVersion->setOrigin($publicNodeVersion);
1106
        $nodeVersion->setCreated(new DateTime());
1107
1108
        $this->em->persist($nodeTranslation);
1109
        $this->em->persist($nodeVersion);
1110
        $this->em->flush();
1111
1112
        $this->get('event_dispatcher')->dispatch(
1113
            Events::CREATE_DRAFT_VERSION,
1114
            new NodeEvent(
1115
                $nodeTranslation->getNode(),
1116
                $nodeTranslation,
1117
                $nodeVersion,
1118
                $page
1119
            )
1120
        );
1121
1122
        return $nodeVersion;
1123
    }
1124
1125
    /**
1126
     * @param Node   $node       The node
1127
     * @param string $permission The permission to check for
1128
     *
1129
     * @throws AccessDeniedException
1130
     */
1131
    private function checkPermission(Node $node, $permission)
1132
    {
1133
        if (false === $this->authorizationChecker->isGranted($permission, $node)) {
1134
            throw new AccessDeniedException();
1135
        }
1136
    }
1137
1138
    /**
1139
     * @param EntityManager   $em       The Entity Manager
1140
     * @param BaseUser        $user     The user who deletes the children
1141
     * @param string          $locale   The locale that was used
1142
     * @param ArrayCollection $children The children array
1143
     */
1144
    private function deleteNodeChildren(
1145
        EntityManager $em,
1146
        BaseUser $user,
1147
        $locale,
1148
        ArrayCollection $children
1149
    ) {
1150
        /* @var Node $childNode */
1151
        foreach ($children as $childNode) {
1152
            $childNodeTranslation = $childNode->getNodeTranslation(
1153
                $this->locale,
1154
                true
1155
            );
1156
1157
            $childNodeVersion = $childNodeTranslation->getPublicNodeVersion();
1158
            $childNodePage = $childNodeVersion->getRef($this->em);
1159
1160
            $this->get('event_dispatcher')->dispatch(
1161
                Events::PRE_DELETE,
1162
                new NodeEvent(
1163
                    $childNode,
1164
                    $childNodeTranslation,
1165
                    $childNodeVersion,
1166
                    $childNodePage
1167
                )
1168
            );
1169
1170
            $childNode->setDeleted(true);
1171
            $this->em->persist($childNode);
1172
1173
            $children2 = $childNode->getChildren();
1174
            $this->deleteNodeChildren($em, $user, $locale, $children2);
1175
1176
            $this->get('event_dispatcher')->dispatch(
1177
                Events::POST_DELETE,
1178
                new NodeEvent(
1179
                    $childNode,
1180
                    $childNodeTranslation,
1181
                    $childNodeVersion,
1182
                    $childNodePage
1183
                )
1184
            );
1185
        }
1186
    }
1187
1188
    /**
1189
     * @param Request $request
1190
     * @param string  $type
1191
     *
1192
     * @return HasNodeInterface
1193
     */
1194
    private function createNewPage(Request $request, $type)
1195
    {
1196
        /* @var HasNodeInterface $newPage */
1197
        $newPage = new $type();
1198
1199
        $title = $request->get('title');
1200
        if (\is_string($title) && !empty($title)) {
1201
            $newPage->setTitle($title);
1202
        } else {
1203
            $newPage->setTitle($this->get('translator')->trans('kuma_node.admin.new_page.title.default'));
1204
        }
1205
        $this->em->persist($newPage);
1206
        $this->em->flush();
1207
1208
        return $newPage;
1209
    }
1210
1211
    /**
1212
     * @param Request $request
1213
     *
1214
     * @return string
1215
     * @throw InvalidArgumentException
1216
     */
1217
    private function validatePageType($request)
1218
    {
1219
        $type = $request->get('type');
1220
1221
        if (empty($type)) {
1222
            throw new InvalidArgumentException(
1223
                'Please specify a type of page you want to create'
1224
            );
1225
        }
1226
1227
        return $type;
1228
    }
1229
1230
    /**
1231
     * @param Node $node
1232
     *
1233
     * @return \Symfony\Component\HttpFoundation\Response
1234
     */
1235
    private function renderNodeNotTranslatedPage(Node $node)
1236
    {
1237
        //try to find a parent node with the correct translation, if there is none allow copy.
1238
        //if there is a parent but it doesn't have the language to copy to don't allow it
1239
        $parentNode = $node->getParent();
1240
        if ($parentNode) {
1241
            $parentNodeTranslation = $parentNode->getNodeTranslation(
1242
                $this->locale,
1243
                true
1244
            );
1245
            $parentsAreOk = false;
1246
1247
            if ($parentNodeTranslation) {
1248
                $parentsAreOk = $this->em->getRepository(
1249
                    'KunstmaanNodeBundle:NodeTranslation'
1250
                )->hasParentNodeTranslationsForLanguage(
1251
                    $node->getParent()->getNodeTranslation(
1252
                        $this->locale,
1253
                        true
1254
                    ),
1255
                    $this->locale
1256
                );
1257
            }
1258
        } else {
1259
            $parentsAreOk = true;
1260
        }
1261
1262
        return $this->render(
1263
            'KunstmaanNodeBundle:NodeAdmin:pagenottranslated.html.twig',
1264
            array(
1265
                'node' => $node,
1266
                'nodeTranslations' => $node->getNodeTranslations(
1267
                    true
1268
                ),
1269
                'copyfromotherlanguages' => $parentsAreOk,
1270
            )
1271
        );
1272
    }
1273
}
1274