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
|
|
|
protected function configureListFields(ListMapper $listMapper) |
51
|
|
|
{ |
52
|
|
|
$listMapper |
53
|
|
|
->addIdentifier('id') |
54
|
|
|
->add('title'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
58
|
|
|
{ |
59
|
|
|
$formMapper |
60
|
|
|
->with('form.group_general') |
61
|
|
|
->add('name', 'Symfony\Component\Form\Extension\Core\Type\TextType') |
62
|
|
|
->add('title', 'Symfony\Component\Form\Extension\Core\Type\TextType') |
63
|
|
|
->add( |
64
|
|
|
'children', |
65
|
|
|
'Sonata\CoreBundle\Form\Type\CollectionType', |
66
|
|
|
array('label' => false, 'type_options' => array('delete' => true, 'delete_options' => array('type' => 'Symfony\Component\Form\Extension\Core\Type\CheckboxType', 'type_options' => array('required' => false, 'mapped' => false)))), |
67
|
|
|
array('edit' => 'inline', 'inline' => 'table', 'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin') |
68
|
|
|
) |
69
|
|
|
->add( |
70
|
|
|
'routes', |
71
|
|
|
'Sonata\AdminBundle\Form\Type\ModelType', |
72
|
|
|
array('property' => 'title', 'multiple' => true, 'expanded' => false) |
73
|
|
|
) |
74
|
|
|
->add('parentDocument', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
75
|
|
|
'widget' => 'browser', |
76
|
|
|
'root_node' => $this->getRootPath(), |
77
|
|
|
)) |
78
|
|
|
->add( |
79
|
|
|
'child', |
80
|
|
|
'Sonata\AdminBundle\Form\Type\ModelType', |
81
|
|
|
array('property' => 'title', 'class' => 'Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content', 'btn_catalogue' => 'List') |
82
|
|
|
) |
83
|
|
|
->add('singleRoute', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
84
|
|
|
'widget' => 'browser', |
85
|
|
|
'root_node' => $this->getRootPath(), |
86
|
|
|
)) |
87
|
|
|
->end(); |
88
|
|
|
|
89
|
|
|
$formMapper->getFormBuilder()->get('parentDocument')->addModelTransformer(new DocumentToPathTransformer( |
90
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
91
|
|
|
)); |
92
|
|
|
|
93
|
|
|
$formMapper->getFormBuilder()->get('singleRoute')->addModelTransformer(new DocumentToPathTransformer( |
94
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
95
|
|
|
)); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
99
|
|
|
{ |
100
|
|
|
$datagridMapper |
101
|
|
|
->add('title', 'Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter') |
102
|
|
|
->add('name', 'Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function configureShowFields(ShowMapper $showMapper) |
106
|
|
|
{ |
107
|
|
|
$showMapper |
108
|
|
|
->tab('General') // the tab call is optional |
109
|
|
|
->with('Content', array( |
110
|
|
|
'class' => 'col-md-8', |
111
|
|
|
'box_class' => 'box box-solid box-danger', |
112
|
|
|
'description' => 'Main Content', |
113
|
|
|
)) |
114
|
|
|
->add('title') |
115
|
|
|
->add('name') |
116
|
|
|
->end() |
117
|
|
|
->with('References') |
118
|
|
|
->add('parentDocument') |
119
|
|
|
->add('children') |
120
|
|
|
->add('child') |
121
|
|
|
->add('singleRoute') |
122
|
|
|
->end() |
123
|
|
|
->end() |
124
|
|
|
; |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|