Completed
Push — master ( 660f95...b6c1ee )
by Benjamin
02:53
created

BaseNodeEntityAdmin::getNewInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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(['create', '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 getNewInstance()
34
    {
35
        $instance = parent::getNewInstance();
36
        $instance->setDateCreated(new \DateTime());
37
38
        return $instance;
39
    }
40
41
    public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
42
    {
43
        if (isset($this->breadcrumbs[$action])) {
44
            return $this->breadcrumbs[$action];
45
        }
46
47
        $contentTypes = $this->getCMSTypes();
48
        $menu = $this->menuFactory->createItem('root');
49
50
        $menu = $menu->addChild('Dashboard',
51
            ['uri' => $this->routeGenerator->generate('sonata_admin_dashboard')]
52
        );
53
54
        $menu = $menu->addChild('Gestion des pages',
55
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
56
        );
57
58
        $menu = $menu->addChild(sprintf('Gestion des pages de type "%s"', $contentTypes[$this->getSubject()->getType()]['title']),
59
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
60
        );
61
62
        return $this->breadcrumbs[$action] = $menu;
63
    }
64
65
    protected function configureFormFields(FormMapper $formMapper)
66
    {
67
        self::configureMainFields($formMapper);
68
69
        $formMapper
70
            ->add('locale', 'choice', [
71
                'label'    => 'Langue du contenu',
72
                'choices'  => $this->getRealLocales(),
73
                'required' => true,
74
            ])
75
            ->add('dateCreated', DateTimeSingleType::class, [
76
                'label' => 'Date de création',
77
            ])
78
            ->add('published', 'checkbox', [
79
                'label'    => 'Publié',
80
                'required' => false,
81
            ]);
82
    }
83
84
    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...
85
    {
86
    }
87
}
88