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\DoctrinePHPCRAdminBundle\Admin\Admin; |
20
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @author Maximilian Berghoff <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
class AssociationAdmin extends Admin |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var ManagerRegistry |
29
|
|
|
*/ |
30
|
|
|
private $managerRegistry; |
31
|
|
|
|
32
|
|
|
public function setManagerRegistry(ManagerRegistry $managerRegistry) |
33
|
|
|
{ |
34
|
|
|
$this->managerRegistry = $managerRegistry; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getExportFormats() |
38
|
|
|
{ |
39
|
|
|
return array(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function toString($object) |
43
|
|
|
{ |
44
|
|
|
return $object instanceof Content && $object->getTitle() |
45
|
|
|
? $object->getTitle() |
46
|
|
|
: $this->trans('link_add', array(), 'SonataAdminBundle') |
47
|
|
|
; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function configureListFields(ListMapper $listMapper) |
51
|
|
|
{ |
52
|
|
|
$listMapper |
53
|
|
|
->addIdentifier('id') |
54
|
|
|
->add('title') |
55
|
|
|
; |
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('parentDocument', 'Symfony\Cmf\Bundle\TreeBrowserBundle\Form\Type\TreeSelectType', array( |
65
|
|
|
'widget' => 'browser', |
66
|
|
|
'root_node' => $this->getRootPath(), |
67
|
|
|
)) |
68
|
|
|
->end() |
69
|
|
|
; |
70
|
|
|
|
71
|
|
|
$formMapper->getFormBuilder()->get('parentDocument')->addModelTransformer(new DocumentToPathTransformer( |
72
|
|
|
$this->managerRegistry->getManagerForClass($this->getClass()) |
73
|
|
|
)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
77
|
|
|
{ |
78
|
|
|
$datagridMapper |
79
|
|
|
->add('title', 'Sonata\DoctrinePHPCRAdminBundle\Filter\StringFilter') |
80
|
|
|
->add('name', 'Sonata\DoctrinePHPCRAdminBundle\Filter\NodeNameFilter') |
81
|
|
|
; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|