|
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\CoreBundle\Form\Type\CollectionType; |
|
20
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; |
|
21
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content; |
|
22
|
|
|
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @author Maximilian Berghoff <[email protected]> |
|
26
|
|
|
*/ |
|
27
|
|
|
class ContentAdmin extends Admin |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @var ManagerRegistry |
|
31
|
|
|
*/ |
|
32
|
|
|
private $managerRegistry; |
|
33
|
|
|
|
|
34
|
|
|
public function setManagerRegistry(ManagerRegistry $managerRegistry) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->managerRegistry = $managerRegistry; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function getExportFormats() |
|
40
|
|
|
{ |
|
41
|
|
|
return array(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function toString($object) |
|
45
|
|
|
{ |
|
46
|
|
|
return $object instanceof Content && $object->getTitle() |
|
47
|
|
|
? $object->getTitle() |
|
48
|
|
|
: $this->trans('link_add', array(), 'SonataAdminBundle'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function configureListFields(ListMapper $listMapper) |
|
52
|
|
|
{ |
|
53
|
|
|
$listMapper |
|
54
|
|
|
->addIdentifier('id') |
|
55
|
|
|
->add('title'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
|
59
|
|
|
{ |
|
60
|
|
|
$formMapper |
|
61
|
|
|
->with('form.group_general') |
|
62
|
|
|
->add('name', 'Symfony\Component\Form\Extension\Core\Type\TextType') |
|
63
|
|
|
->add('title', 'Symfony\Component\Form\Extension\Core\Type\TextType') |
|
64
|
|
|
->add( |
|
65
|
|
|
'children', |
|
66
|
|
|
CollectionType::class, |
|
67
|
|
|
array('label' => false, 'type_options' => array('delete' => true, 'delete_options' => array('type' => CheckboxType::class, 'type_options' => array('required' => false, 'mapped' => false)))), |
|
68
|
|
|
array('edit' => 'inline', 'inline' => 'table', 'admin_code' => 'sonata_admin_doctrine_phpcr.test.admin') |
|
69
|
|
|
) |
|
70
|
|
|
->add( |
|
71
|
|
|
'routes', |
|
72
|
|
|
CollectionType::class, |
|
73
|
|
|
array('label' => false, 'type_options' => array('delete' => true, 'delete_options' => array('type' => CheckboxType::class, 'type_options' => array('required' => false, 'mapped' => false)))), |
|
74
|
|
|
array('edit' => 'inline', 'inline' => 'table') |
|
75
|
|
|
) |
|
76
|
|
|
->add('parentDocument', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
|
77
|
|
|
'widget' => 'browser', |
|
78
|
|
|
'root_node' => $this->getRootPath(), |
|
79
|
|
|
)) |
|
80
|
|
|
->add('child', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
|
81
|
|
|
'widget' => 'browser', |
|
82
|
|
|
'root_node' => $this->getRootPath(), |
|
83
|
|
|
)) |
|
84
|
|
|
->add('singleRoute', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
|
85
|
|
|
'widget' => 'browser', |
|
86
|
|
|
'root_node' => $this->getRootPath(), |
|
87
|
|
|
)) |
|
88
|
|
|
->end(); |
|
89
|
|
|
|
|
90
|
|
|
$formMapper->getFormBuilder()->get('parentDocument')->addModelTransformer(new DocumentToPathTransformer( |
|
91
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
|
92
|
|
|
)); |
|
93
|
|
|
|
|
94
|
|
|
$formMapper->getFormBuilder()->get('child')->addModelTransformer(new DocumentToPathTransformer( |
|
95
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
|
96
|
|
|
)); |
|
97
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$formMapper->getFormBuilder()->get('singleRoute')->addModelTransformer(new DocumentToPathTransformer( |
|
100
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
|
101
|
|
|
)); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
|
105
|
|
|
{ |
|
106
|
|
|
$datagridMapper |
|
107
|
|
|
->add('title', 'Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter') |
|
108
|
|
|
->add('name', 'Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter'); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|