Completed
Pull Request — master (#33)
by Benjamin
02:22
created

BaseNodeEntityAdmin::configureFormFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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