|
1
|
|
|
<?php |
|
2
|
|
|
namespace NVBooster\PHPCRAssetsBundle\Admin; |
|
3
|
|
|
|
|
4
|
|
|
use Sonata\DoctrinePHPCRAdminBundle\Admin\Admin; |
|
5
|
|
|
use Sonata\AdminBundle\Datagrid\DatagridMapper; |
|
6
|
|
|
use Sonata\AdminBundle\Datagrid\ListMapper; |
|
7
|
|
|
use Sonata\AdminBundle\Form\FormMapper; |
|
8
|
|
|
use NVBooster\PHPCRAssetsBundle\Asset\BaseAsset; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* AssetAdmin |
|
12
|
|
|
* |
|
13
|
|
|
* @author nvb <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class BaseAssetAdmin extends Admin |
|
16
|
|
|
{ |
|
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* {@inheritDoc} |
|
19
|
|
|
* |
|
20
|
|
|
* @var string |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $baseRouteName = 'admin_cmf_assets_baseasset'; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
* |
|
27
|
|
|
* @var string |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $baseRoutePattern = '/cms/assets/baseasset'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var boolean |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $codeMirrorEnabled = false; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritDoc} |
|
38
|
|
|
* |
|
39
|
|
|
* @see \Sonata\AdminBundle\Admin\Admin::configureListFields() |
|
40
|
|
|
*/ |
|
41
|
|
|
protected function configureListFields(ListMapper $listMapper) |
|
42
|
|
|
{ |
|
43
|
|
|
$listMapper |
|
44
|
|
|
->addIdentifier('id', 'text') |
|
45
|
|
|
->addIdentifier('name', 'text'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* {@inheritDoc} |
|
50
|
|
|
* |
|
51
|
|
|
* @see \Sonata\AdminBundle\Admin\Admin::configureFormFields() |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function configureFormFields(FormMapper $formMapper) |
|
54
|
|
|
{ |
|
55
|
|
|
$group = $formMapper |
|
56
|
|
|
->with('General') |
|
57
|
|
|
->add('name', 'text'); |
|
58
|
|
|
|
|
59
|
|
|
if ($this->codeMirrorEnabled) { |
|
60
|
|
|
$group->add('content', 'textasset', array( |
|
61
|
|
|
'required' => false, |
|
62
|
|
|
'codemirror' => $this->getCodeMirrorParams() |
|
63
|
|
|
)); |
|
64
|
|
|
} else { |
|
65
|
|
|
$group->add('content', 'textarea'); |
|
66
|
|
|
} |
|
67
|
|
|
$group->end(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* {@inheritDoc} |
|
72
|
|
|
* |
|
73
|
|
|
* @see \Sonata\AdminBundle\Admin\Admin::configureDatagridFilters() |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
|
76
|
|
|
{ |
|
77
|
|
|
$datagridMapper->add('name', 'doctrine_phpcr_string'); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* {@inheritDoc} |
|
82
|
|
|
* |
|
83
|
|
|
* @see \Sonata\AdminBundle\Admin\Admin::getExportFormats() |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getExportFormats() |
|
86
|
|
|
{ |
|
87
|
|
|
return array(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* {@inheritDoc} |
|
92
|
|
|
* |
|
93
|
|
|
* @see \Sonata\DoctrinePHPCRAdminBundle\Admin\Admin::toString() |
|
94
|
|
|
*/ |
|
95
|
|
|
public function toString($object) |
|
96
|
|
|
{ |
|
97
|
|
|
return $object instanceof BaseAsset && $object->getName() |
|
98
|
|
|
? $object->getName() |
|
99
|
|
|
: $this->trans('link_add', array(), 'SonataAdminBundle'); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Replaces textarea with code mirror input |
|
104
|
|
|
*/ |
|
105
|
|
|
public function enableCodeMirror() |
|
106
|
|
|
{ |
|
107
|
|
|
$this->codeMirrorEnabled = true; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Uses plain textarea |
|
112
|
|
|
*/ |
|
113
|
|
|
public function disableCodeMirror() |
|
114
|
|
|
{ |
|
115
|
|
|
$this->codeMirrorEnabled = false; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @return array |
|
120
|
|
|
*/ |
|
121
|
|
|
protected function getCodeMirrorParams() |
|
122
|
|
|
{ |
|
123
|
|
|
return array(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* {@inheritdoc} |
|
128
|
|
|
* @see \Sonata\AdminBundle\Admin\Admin::getNewInstance() |
|
129
|
|
|
*/ |
|
130
|
|
|
public function getNewInstance() |
|
131
|
|
|
{ |
|
132
|
|
|
/* @var $object BaseAsset */ |
|
133
|
|
|
$object = parent::getNewInstance(); |
|
134
|
|
|
$object->setParentDocument($this->getModelManager()->find(null, $this->getRootPath())); |
|
135
|
|
|
|
|
136
|
|
|
return $object; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
} |