1 | <?php |
||
19 | class BaseAssetAdmin extends Admin |
||
20 | { |
||
21 | /** |
||
22 | * {@inheritDoc} |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $baseRouteName = 'admin_cmf_assets_baseasset'; |
||
27 | |||
28 | /** |
||
29 | * {@inheritDoc} |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | protected $baseRoutePattern = '/cms/assets/baseasset'; |
||
34 | |||
35 | /** |
||
36 | * @var boolean |
||
37 | */ |
||
38 | protected $codeMirrorEnabled = false; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $codeMirrorParams = array(); |
||
44 | |||
45 | /** |
||
46 | * {@inheritDoc} |
||
47 | * |
||
48 | * @see \Sonata\AdminBundle\Admin\Admin::configureListFields() |
||
49 | */ |
||
50 | protected function configureListFields(ListMapper $listMapper) |
||
58 | |||
59 | /** |
||
60 | * {@inheritDoc} |
||
61 | * |
||
62 | * @see \Sonata\AdminBundle\Admin\Admin::configureFormFields() |
||
63 | */ |
||
64 | protected function configureFormFields(FormMapper $formMapper) |
||
65 | { |
||
66 | $group = $formMapper |
||
67 | ->with('General') |
||
68 | ->add('name', 'text'); |
||
69 | |||
70 | $asset = $this->getSubject(); |
||
71 | |||
72 | if ($this->codeMirrorEnabled) { |
||
73 | $codeMirrorParams = $this->getCodeMirrorParams(); |
||
74 | if ($asset instanceof JsAsset) { |
||
75 | $codeMirrorParams['lineNumbers'] = true; |
||
76 | $codeMirrorParams['mode'] = 'javascript'; |
||
77 | } elseif ($asset instanceof CssAsset) { |
||
78 | $codeMirrorParams['lineNumbers'] = true; |
||
79 | $codeMirrorParams['mode'] = 'css'; |
||
80 | } |
||
81 | |||
82 | $group->add('content', 'textasset', array( |
||
83 | 'required' => false, |
||
84 | 'codemirror' => $codeMirrorParams |
||
85 | )); |
||
86 | } else { |
||
87 | $group->add('content', 'textarea'); |
||
88 | } |
||
89 | $group->end(); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * {@inheritDoc} |
||
94 | * |
||
95 | * @see \Sonata\AdminBundle\Admin\Admin::configureDatagridFilters() |
||
96 | */ |
||
97 | protected function configureDatagridFilters(DatagridMapper $datagridMapper) |
||
101 | |||
102 | /** |
||
103 | * {@inheritDoc} |
||
104 | * |
||
105 | * @see \Sonata\AdminBundle\Admin\Admin::getExportFormats() |
||
106 | */ |
||
107 | public function getExportFormats() |
||
111 | |||
112 | /** |
||
113 | * {@inheritDoc} |
||
114 | * |
||
115 | * @see \Sonata\DoctrinePHPCRAdminBundle\Admin\Admin::toString() |
||
116 | */ |
||
117 | public function toString($object) |
||
123 | |||
124 | /** |
||
125 | * Replaces textarea with code mirror input |
||
126 | */ |
||
127 | public function enableCodeMirror() |
||
131 | |||
132 | /** |
||
133 | * Uses plain textarea |
||
134 | */ |
||
135 | public function disableCodeMirror() |
||
139 | |||
140 | /** |
||
141 | * @return array |
||
142 | */ |
||
143 | public function getCodeMirrorParams() |
||
147 | |||
148 | /** |
||
149 | * @param $params array |
||
150 | */ |
||
151 | public function setCodeMirrorParams(array $params) |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | * @see \Sonata\AdminBundle\Admin\Admin::getNewInstance() |
||
159 | */ |
||
160 | public function getNewInstance() |
||
168 | |||
169 | /** |
||
170 | * @{inheritdocs} |
||
171 | * |
||
172 | * @see https://github.com/sonata-project/SonataDoctrinePhpcrAdminBundle/issues/354 |
||
173 | */ |
||
174 | public function getSubject() |
||
190 | |||
191 | } |