Completed
Push — 2.x-dev-kit ( 681634...3c5f4d )
by Oskar
06:14 queued 04:22
created

ContentAdmin   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 9
dl 0
loc 129
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setManagerRegistry() 0 4 1
A getExportFormats() 0 4 1
A toString() 0 6 3
A configureShowFields() 0 37 1
A configureListFields() 0 6 1
A configureFormFields() 0 52 1
A configureDatagridFilters() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Admin;
15
16
use Doctrine\Bundle\PHPCRBundle\Form\DataTransformer\DocumentToPathTransformer;
17
use Doctrine\Common\Persistence\ManagerRegistry;
18
use Sonata\AdminBundle\Datagrid\DatagridMapper;
19
use Sonata\AdminBundle\Datagrid\ListMapper;
20
use Sonata\AdminBundle\Form\FormMapper;
21
use Sonata\AdminBundle\Show\ShowMapper;
22
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
23
use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content;
24
25
/**
26
 * @author Maximilian Berghoff <[email protected]>
27
 */
28
class ContentAdmin extends Admin
29
{
30
    /**
31
     * @var ManagerRegistry
32
     */
33
    private $managerRegistry;
34
35
    public function setManagerRegistry(ManagerRegistry $managerRegistry)
36
    {
37
        $this->managerRegistry = $managerRegistry;
38
    }
39
40
    public function getExportFormats()
41
    {
42
        return [];
43
    }
44
45
    public function toString($object)
46
    {
47
        return $object instanceof Content && $object->getTitle()
48
            ? $object->getTitle()
49
            : $this->trans('link_add', [], 'SonataAdminBundle');
50
    }
51
52
    public function configureShowFields(ShowMapper $showMapper)
53
    {
54
        $showMapper
55
            ->tab('General') // the tab call is optional
56
                ->with('Content', [
57
                    'class' => 'col-md-8',
58
                    'box_class' => 'box box-solid box-danger',
59
                    'description' => 'Main Content',
60
                ])
61
                    ->add('title')
62
                    ->add('name')
63
                ->end()
64
                ->with('References')
65
                    ->add('children', null, [
66
                        'route' => ['name' => 'edit', 'parameters' => []],
67
                        'associated_property' => 'id',
68
                        'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin',
69
                        ])
70
                    ->add('child', null, [
71
                        'route' => ['name' => 'edit', 'parameters' => []],
72
                        'associated_property' => 'id',
73
                        'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin',
74
                    ])
75
                    ->add(
76
                        'singleRoute',
77
                        null,
78
                        ['route' => ['name' => 'edit', 'parameters' => []], 'associated_property' => 'id']
79
                    )
80
                    ->add(
81
                        'routes',
82
                        null,
83
                        ['route' => ['name' => 'edit', 'parameters' => []], 'associated_property' => 'id']
84
                    )
85
                ->end()
86
            ->end()
87
        ;
88
    }
89
90
    protected function configureListFields(ListMapper $listMapper)
91
    {
92
        $listMapper
93
            ->addIdentifier('id')
94
            ->add('title');
95
    }
96
97
    protected function configureFormFields(FormMapper $formMapper)
98
    {
99
        $formMapper
100
            ->with('form.group_general')
101
            ->add('name', 'Symfony\Component\Form\Extension\Core\Type\TextType')
102
            ->add('title', 'Symfony\Component\Form\Extension\Core\Type\TextType')
103
            ->add(
104
                'children',
105
                'Sonata\CoreBundle\Form\Type\CollectionType',
106
                ['label' => false, 'type_options' => [
107
                    'delete' => true,
108
                    'delete_options' => [
109
                        'type' => 'Symfony\Component\Form\Extension\Core\Type\CheckboxType',
110
                        'type_options' => ['required' => false, 'mapped' => false],
111
                    ], ],
112
                ],
113
                ['edit' => 'inline', 'inline' => 'table', 'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin']
114
            )
115
            ->add(
116
                'routes',
117
                'Sonata\AdminBundle\Form\Type\ModelType',
118
                ['property' => 'title', 'multiple' => true, 'expanded' => false]
119
            )
120
            ->add('parentDocument', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', [
121
                'widget' => 'browser',
122
                'root_node' => $this->getRootPath(),
123
            ])
124
            ->add(
125
                'child',
126
                'Sonata\AdminBundle\Form\Type\ModelType',
127
                [
128
                    'property' => 'title',
129
                    'class' => 'Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content',
130
                    'btn_catalogue' => 'List',
131
                    'required' => false,
132
                ],
133
                ['admin_code' => 'sonata_admin_doctrine_phpcr.test.admin']
134
            )
135
            ->add('singleRoute', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', [
136
                'widget' => 'browser',
137
                'root_node' => $this->getRootPath(),
138
            ])
139
            ->end();
140
141
        $formMapper->getFormBuilder()->get('parentDocument')->addModelTransformer(new DocumentToPathTransformer(
142
            $this->managerRegistry->getManagerForClass($this->getClass())
143
        ));
144
145
        $formMapper->getFormBuilder()->get('singleRoute')->addModelTransformer(new DocumentToPathTransformer(
146
            $this->managerRegistry->getManagerForClass($this->getClass())
147
        ));
148
    }
149
150
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
151
    {
152
        $datagridMapper
153
            ->add('title', 'doctrine_phpcr_string')
154
            ->add('name', 'doctrine_phpcr_nodename');
155
    }
156
}
157