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