Completed
Push — master ( f46174...77b1c2 )
by Grégoire
11s queued 10s
created

ContentAdmin   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 153
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 9
dl 0
loc 153
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 47 1
A configureListFields() 0 6 1
B configureFormFields() 0 66 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\Fixtures\App\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\Form\Type\ModelType;
22
use Sonata\AdminBundle\Show\ShowMapper;
23
use Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter;
24
use Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter;
25
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
26
use Sonata\CoreBundle\Form\Type\CollectionType;
27
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin;
28
use Sonata\DoctrinePHPCRAdminBundle\Tests\Fixtures\App\Document\Content;
29
use Symfony\Component\Form\Extension\Core\Type\TextType;
30
use Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType;
31
32
/**
33
 * @author Maximilian Berghoff <[email protected]>
34
 */
35
class ContentAdmin extends Admin
36
{
37
    /**
38
     * @var ManagerRegistry
39
     */
40
    private $managerRegistry;
41
42
    public function setManagerRegistry(ManagerRegistry $managerRegistry)
43
    {
44
        $this->managerRegistry = $managerRegistry;
45
    }
46
47
    public function getExportFormats()
48
    {
49
        return [];
50
    }
51
52
    public function toString($object)
53
    {
54
        return $object instanceof Content && $object->getTitle()
55
            ? $object->getTitle()
56
            : $this->trans('link_add', [], 'SonataAdminBundle');
57
    }
58
59
    public function configureShowFields(ShowMapper $showMapper)
60
    {
61
        $showMapper
62
            ->tab('General')// the tab call is optional
63
            ->with(
64
                'Content',
65
                [
66
                    'class' => 'col-md-8',
67
                    'box_class' => 'box box-solid box-danger',
68
                    'description' => 'Main Content',
69
                ]
70
            )
71
            ->add('title')
72
            ->add('name')
73
            ->end()
74
            ->with('References')
75
            ->add(
76
                'children',
77
                null,
78
                [
79
                    'route' => ['name' => 'edit', 'parameters' => []],
80
                    'associated_property' => 'id',
81
                    'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin',
82
                ]
83
            )
84
            ->add(
85
                'child',
86
                null,
87
                [
88
                    'route' => ['name' => 'edit', 'parameters' => []],
89
                    'associated_property' => 'id',
90
                    'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin',
91
                ]
92
            )
93
            ->add(
94
                'singleRoute',
95
                null,
96
                ['route' => ['name' => 'edit', 'parameters' => []], 'associated_property' => 'id']
97
            )
98
            ->add(
99
                'routes',
100
                null,
101
                ['route' => ['name' => 'edit', 'parameters' => []], 'associated_property' => 'id']
102
            )
103
            ->end()
104
            ->end();
105
    }
106
107
    protected function configureListFields(ListMapper $listMapper)
108
    {
109
        $listMapper
110
            ->addIdentifier('id')
111
            ->add('title');
112
    }
113
114
    protected function configureFormFields(FormMapper $formMapper)
115
    {
116
        $formMapper
117
            ->with('form.group_general')
118
            ->add('name', TextType::class)
119
            ->add('title', TextType::class)
120
            ->add(
121
                'children',
122
                CollectionType::class,
123
                [
124
                    'label' => false, 'type_options' => [
125
                    'delete' => true,
126
                    'delete_options' => [
127
                        'type' => CheckboxType::class,
128
                        'type_options' => ['required' => false, 'mapped' => false],
129
                    ],
130
                ],
131
                ],
132
                ['edit' => 'inline', 'inline' => 'table', 'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin']
133
            )
134
            ->add(
135
                'routes',
136
                ModelType::class,
137
                ['property' => 'title', 'multiple' => true, 'expanded' => false]
138
            )
139
            ->add(
140
                'parentDocument',
141
                TreeSelectType::class,
142
                [
143
                    'widget' => 'browser',
144
                    'root_node' => $this->getRootPath(),
145
                ]
146
            )
147
            ->add(
148
                'child',
149
                ModelType::class,
150
                [
151
                    'property' => 'title',
152
                    'class' => Content::class,
153
                    'btn_catalogue' => 'List',
154
                    'required' => false,
155
                ],
156
                ['admin_code' => 'sonata_admin_doctrine_phpcr.test.admin']
157
            )
158
            ->add(
159
                'singleRoute',
160
                TreeSelectType::class,
161
                [
162
                    'widget' => 'browser',
163
                    'root_node' => $this->getRootPath(),
164
                ]
165
            )
166
            ->end();
167
168
        $formMapper->getFormBuilder()->get('parentDocument')->addModelTransformer(
169
            new DocumentToPathTransformer(
170
                $this->managerRegistry->getManagerForClass($this->getClass())
171
            )
172
        );
173
174
        $formMapper->getFormBuilder()->get('singleRoute')->addModelTransformer(
175
            new DocumentToPathTransformer(
176
                $this->managerRegistry->getManagerForClass($this->getClass())
177
            )
178
        );
179
    }
180
181
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
182
    {
183
        $datagridMapper
184
            ->add('title', StringFilter::class)
185
            ->add('name', NodeNameFilter::class);
186
    }
187
}
188