PageListener::preRemove()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
nc 3
nop 1
dl 0
loc 6
rs 10
c 1
b 0
f 0
ccs 0
cts 0
cp 0
crap 12
1
<?php
2
3
namespace PiedWeb\CMSBundle\EventListener;
4
5
use PiedWeb\CMSBundle\Entity\PageInterface as Page;
6
use PiedWeb\CMSBundle\Service\App;
7
use PiedWeb\CMSBundle\Service\PageMainContentManager\PageMainContentManager;
8
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
9
10
class PageListener
11
{
12
    protected $params;
13
    protected $mainContentManager;
14
15
    public function __construct(ParameterBagInterface $params, PageMainContentManager $mainContentManager)
16
    {
17
        $this->params = $params;
18
        //$this->app = new App(null, $this->params);
19
        $this->mainContentManager = $mainContentManager;
20
    }
21
22
    public function postLoad(Page $page)
23
    {
24
        // todo
25
        //$this->switchCurrentApp($page->getHost());
26
        //$page->setApp(clone $this->app);
27
28
        if (false === $this->params->get('pwc.main_content_twig') || null === $page->getOtherProperty('twig')) {
29
            $page->setTwig($this->params->get('pwc.main_content_twig'));
30
        }
31
32
        if (null === $page->getMainContentType()) {
33
            $page->setMainContentType($this->params->get('pwc.main_content_type_default'));
34
        }
35
36
        $page->setContent($this->mainContentManager->manage($page));
37
    }
38
39
    public function preRemove(Page $page)
40
    {
41
        // method_exists($page, 'getChildrenPages') &&
42
        if (! $page->getChildrenPages()->isEmpty()) {
43
            foreach ($page->getChildrenPages() as $cPage) {
44
                $cPage->setParentPage(null);
45
            }
46
        }
47
    }
48
}
49