BaseNodeEntityAdmin::configureMainFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Alpixel\Bundle\CMSBundle\Admin;
4
5
use Knp\Menu\ItemInterface as MenuItemInterface;
6
use Sonata\AdminBundle\Form\FormMapper;
7
use Sonata\AdminBundle\Route\RouteCollection;
8
use Ivory\CKEditorBundle\Form\Type\CKEditorType;
9
10
abstract class BaseNodeEntityAdmin extends BaseAdmin
11
{
12
    protected function configureRoutes(RouteCollection $collection)
13
    {
14
        $collection->clearExcept(['create', 'edit', 'delete', 'batch']);
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', CKEditorType::class, [
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
            ->end()
71
            ->with('Paramétrage')
72
                ->add('locale', 'choice', [
73
                    'label'    => 'Langue du contenu',
74
                    'choices'  => $this->getRealLocales(),
75
                    'required' => true,
76
                ])
77
                ->add('dateCreated', 'date', [
78
                    'label' => 'Date de création',
79
                ])
80
                ->add('published', 'checkbox', [
81
                    'label'    => 'Publié',
82
                    'required' => false,
83
                ])
84
            ->end();
85
86
        if ($this->subject->getId() !== null) {
87
            $baseUrl = $this->getConfigurationPool()->getContainer()->getParameter('url_production');
88
            $formMapper
89
                ->with('SEO')
90
                ->add('slug', null, [
91
                    'required' => true,
92
                    'label'    => 'Adresse de la page',
93
                ])
94
                ->setHelps([
95
                    'slug' => sprintf('Partie qui apparait après l\'adresse de votre site. Exemple : %s/fr/<b>%s</b>', $baseUrl, $this->subject->getSlug()),
96
                ])
97
            ->end();
98
        }
99
    }
100
101
    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...
102
    {
103
    }
104
}
105