Completed
Push — master ( dc1345...98f380 )
by Benjamin
02:22
created

BaseNodeEntityAdmin::buildBreadcrumbs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 2
eloc 12
nc 2
nop 2
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Admin;
4
5
use Alpixel\Bundle\CMSBundle\Form\DateTimeSingleType;
6
use Knp\Menu\ItemInterface as MenuItemInterface;
7
use Sonata\AdminBundle\Form\FormMapper;
8
use Sonata\AdminBundle\Route\RouteCollection;
9
10
abstract class BaseNodeEntityAdmin extends BaseAdmin
11
{
12
    protected function configureRoutes(RouteCollection $collection)
13
    {
14
        $collection->clearExcept(['add', 'edit', 'delete']);
15
        $collection->add('see', $this->getRouterIdParameter().'/see');
16
        $collection->add('createTranslation', $this->getRouterIdParameter().'/translate');
17
    }
18
19
    protected function configureMainFields(FormMapper $formMapper)
20
    {
21
        $formMapper
22
            ->add('title', null, [
23
                'label'    => 'Titre',
24
                'required' => true,
25
            ])
26
            ->add('content', 'ckeditor', [
27
                'label'       => 'Contenu',
28
                'required'    => false,
29
                'config_name' => 'admin',
30
            ]);
31
    }
32
33
    public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
34
    {
35
        if (isset($this->breadcrumbs[$action])) {
36
            return $this->breadcrumbs[$action];
37
        }
38
39
        $contentTypes = $this->getCMSTypes();
40
        $menu = $this->menuFactory->createItem('root');
41
42
        $menu = $menu->addChild('Dashboard',
43
            ['uri' => $this->routeGenerator->generate('sonata_admin_dashboard')]
44
        );
45
46
        $menu = $menu->addChild('Gestion des pages',
47
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
48
        );
49
50
        $menu = $menu->addChild(sprintf('Gestion des pages de type "%s"', $contentTypes[$this->getSubject()->getType()]['title']),
51
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
52
        );
53
54
        return $this->breadcrumbs[$action] = $menu;
55
    }
56
57
    protected function configureFormFields(FormMapper $formMapper)
58
    {
59
        self::configureMainFields($formMapper);
60
61
        $formMapper
62
            ->add('locale', 'choice', [
63
                'label'    => 'Langue du contenu',
64
                'choices'  => $this->getRealLocales(),
65
                'required' => true,
66
            ])
67
            ->add('dateCreated', DateTimeSingleType::class, [
68
                'label' => 'Date de création',
69
            ])
70
            ->add('published', 'checkbox', [
71
                'label'    => 'Publié',
72
                'required' => false,
73
            ]);
74
    }
75
76
    public function showCustomURL($object = null)
0 ignored issues
show
Unused Code introduced by
The parameter $object is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
    {
78
    }
79
}
80