Passed
Push — master ( 4017d9...9757db )
by Dev
10:15
created

PageAdminCRUDController::treeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PiedWeb\CMSBundle\Extension\Admin;
4
5
use PiedWeb\CMSBundle\Service\Repository;
6
use Sonata\AdminBundle\Controller\CRUDController;
7
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
8
9
class PageAdminCRUDController extends CRUDController
10
{
11
    protected $params;
12
13
    public function setParams(ParameterBagInterface $params)
14
    {
15
        $this->params = $params;
16
    }
17
18
    public function listAction()
19
    {
20
        $request = $this->getRequest();
21
        if ($listMode = $request->get('_list_mode')) {
22
            $this->admin->setListMode($listMode);
23
        }
24
25
        $listMode = $this->admin->getListMode();
26
        if ('tree' === $listMode) {
27
            return $this->treeAction();
28
        }
29
30
        return parent::listAction();
31
    }
32
33
    public function treeAction()
34
    {
35
        $pages = Repository::getPageRepository($this->getDoctrine(), $this->params->get('pwc.entity_page'))
36
            ->getPagesWithoutParent();
37
38
        return $this->renderWithExtraParams('@pwcAdmin/page_treeView.html.twig', [
39
            'pages' => $pages,
40
            'list' => $this->admin->getList(),
41
            'admin' => $this->admin,
42
            'base_template' => $this->getBaseTemplate(),
43
            'action' => 'list',
44
        ]);
45
    }
46
}
47