Completed
Push — master ( fc6601...6ba42a )
by Benjamin
02:38
created

BaseNodeEntityAdmin::configureFormFields()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 35
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 12
Bugs 2 Features 3
Metric Value
c 12
b 2
f 3
dl 0
loc 35
rs 8.8571
cc 2
eloc 25
nc 2
nop 1
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\Form\Type\Filter\DateTimeType;
9
use Sonata\AdminBundle\Route\RouteCollection;
10
11
abstract class BaseNodeEntityAdmin extends BaseAdmin
12
{
13
    protected function configureRoutes(RouteCollection $collection)
14
    {
15
        $collection->clearExcept(['create', '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 getNewInstance()
35
    {
36
        $instance = parent::getNewInstance();
37
        $instance->setDateCreated(new \DateTime());
38
39
        return $instance;
40
    }
41
42
    public function buildBreadcrumbs($action, MenuItemInterface $menu = null)
43
    {
44
        if (isset($this->breadcrumbs[$action])) {
45
            return $this->breadcrumbs[$action];
46
        }
47
48
        $contentTypes = $this->getCMSTypes();
49
        $menu = $this->menuFactory->createItem('root');
50
51
        $menu = $menu->addChild('Dashboard',
52
            ['uri' => $this->routeGenerator->generate('sonata_admin_dashboard')]
53
        );
54
55
        $menu = $menu->addChild('Gestion des pages',
56
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
57
        );
58
59
        $menu = $menu->addChild(sprintf('Gestion des pages de type "%s"', $contentTypes[$this->getSubject()->getType()]['title']),
60
            ['uri' => $this->routeGenerator->generate('alpixel_admin_cms_node_list')]
61
        );
62
63
        return $this->breadcrumbs[$action] = $menu;
64
    }
65
66
    protected function configureFormFields(FormMapper $formMapper)
67
    {
68
        self::configureMainFields($formMapper);
69
70
        $formMapper
71
            ->end()
72
            ->with('Paramétrage')
73
                ->add('locale', 'choice', [
74
                    'label'    => 'Langue du contenu',
75
                    'choices'  => $this->getRealLocales(),
76
                    'required' => true,
77
                ])
78
                ->add('dateCreated', 'date', [
79
                    'label' => 'Date de création',
80
                ])
81
                ->add('published', 'checkbox', [
82
                    'label'    => 'Publié',
83
                    'required' => false,
84
                ])
85
            ->end();
86
87
        if($this->subject->getId() !== null) {
88
            $baseUrl = $this->getConfigurationPool()->getContainer()->getParameter('url_production');
89
            $formMapper
90
                ->with('SEO')
91
                ->add('slug', null, [
92
                    'required' => true,
93
                    'label' => 'Adresse de la page'
94
                ])
95
                ->setHelps([
96
                    'slug' => sprintf('Partie qui apparait après l\'adresse de votre site. Exemple : %s/fr/<b>%s</b>', $baseUrl, $this->subject->getSlug())
97
                ])
98
            ->end();
99
        }
100
    }
101
102
    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...
103
    {
104
    }
105
}
106