forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Admin.php
2113 lines (1782 loc) · 51.7 KB
/
Admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Admin;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Builder\FormContractorInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
use Sonata\AdminBundle\Builder\ViewBuilderInterface;
use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Model\ModelManagerInterface;
use Knp\Bundle\MenuBundle\Menu;
use Knp\Bundle\MenuBundle\MenuItem;
abstract class Admin implements AdminInterface, DomainObjectInterface
{
/**
* Regular Expression used to 'guess' what the route pattern and names should be
*
* @var string
*/
const BASE_ROUTE_REGEX = '@(?:([^\\\\]*)\\\\)?([^\\\\]*)Bundle\\\\(?:Entity|Document|Model)\\\\(.*)@';
/**
* The class name managed by the admin class
*
* @var string
*/
protected $class;
/**
* The list field definitions (quick property definition)
*
* @var array
*/
protected $list = array();
/**
* The list FieldDescription constructed from the $list property
* and the configureListField method
*
* @var array
*/
protected $listFieldDescriptions = array();
/**
* The view field definitions (quick property definition)
*
* @var array
*/
protected $view = array();
/**
* The view FieldDescription constructed from the $view property
* and the configureListField method
*
* @var array
*/
protected $viewFieldDescriptions = array();
/**
* The form field definition (quick property definition)
*
* @var array
*/
protected $form = array();
/**
* The list FieldDescription constructed from the $list property
* and the the configureFormField method
*
* @var array
*/
protected $formFieldDescriptions = array();
/**
* The filter field definition (quick property definition)
*
* @var array
*/
protected $filter = array();
/**
* The filter FieldDescription constructed from the $list property
* and the the configureFilterField method
*
* @var array
*/
protected $filterFieldDescriptions = array();
/**
* The number of result to display in the list
*
* @var integer
*/
protected $maxPerPage = 25;
/**
* The base route name used to generate the routing information
*
* @var string
*/
protected $baseRouteName;
/**
* The base route pattern used to generate the routing information
*
* @var string
*/
protected $baseRoutePattern;
/**
* The base name controller used to generate the routing information
*
* @var string
*/
protected $baseControllerName;
/**
* The form group disposition
*
* @var array|boolean
*/
protected $formGroups = false;
/**
* The view group disposition
*
* @var array|boolean
*/
protected $viewGroups = false;
/**
* The label class name (used in the title/breadcrumb ...)
*
* @var string
*/
protected $classnameLabel;
/**
* The translation domain to be used to translate messages
*
* @var string
*/
protected $translationDomain = 'messages';
/**
* Options to set to the form (ie, validation_groups)
*
* @var array
*/
protected $formOptions = array();
/**
* Default values to the datagrid
*
* @var array
*/
protected $datagridValues = array(
'_page' => 1,
);
/**
* The code related to the admin
*
* @var string
*/
protected $code;
/**
* The label
*
* @var string
*/
protected $label;
/**
* Array of routes related to this admin
*
* @var \Sonata\AdminBundle\Route\RouteCollection
*/
protected $routes;
/**
* The subject only set in edit/update/create mode
*
* @var object
*/
protected $subject;
/**
* Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}
*
* @var array
*/
protected $children = array();
/**
* Reference the parent collection
*
* @var Admin
*/
protected $parent = null;
/**
* The base code route refer to the prefix used to generate the route name
*
* @var string
*/
protected $baseCodeRoute = '';
/**
* The related field reflection, ie if OrderElement is linked to Order,
* then the $parentReflectionProperty must be the ReflectionProperty of
* the order (OrderElement::$order)
*
* @var \ReflectionProperty $parentReflectionProperty
*/
protected $parentAssociationMapping = null;
/**
* Reference the parent FieldDescription related to this admin
* only set for FieldDescription which is associated to an Sub Admin instance
*
* @var FieldDescription
*/
protected $parentFieldDescription;
/**
* If true then the current admin is part of the nested admin set (from the url)
*
* @var boolean
*/
protected $currentChild = false;
/**
* The uniqid is used to avoid clashing with 2 admin related to the code
* ie: a Block linked to a Block
*
* @var string
*/
protected $uniqid;
/**
* The Entity or Document manager
*
* @var \Sonata\AdminBundle\Model\ModelManagerInterface
*/
protected $modelManager;
/**
* The current request object
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The translator component
*
* @var \Symfony\Component\Translation\TranslatorInterface
*/
protected $translator;
/**
* The related form contractor
*
* @var \Sonata\AdminBundle\Builder\FormContractorInterface
*/
protected $formContractor;
/**
* The related list builder
*
* @var \Sonata\AdminBundle\Builder\ListBuilderInterface
*/
protected $listBuilder;
/**
* The related view builder
*
* @var \Sonata\AdminBundle\View\ViewBuilderInterface
*/
protected $viewBuilder;
/**
* The related datagrid builder
*
* @var \Sonata\AdminBundle\Builder\DatagridBuilderInterface
*/
protected $datagridBuilder;
/**
* The datagrid instance
*
* @var \Sonata\AdminBundle\Datagrid\DatagridInterface
*/
protected $datagrid;
/**
* The router intance
*
* @var \Symfony\Component\Routing\RouterInterface
*/
protected $router;
/**
* The generated breadcrumbs
*
* @var array
*/
protected $breadcrumbs = array();
protected $securityHandler = null;
/**
* The configuration pool
*
* @var Pool
*/
protected $configurationPool;
protected $menu;
protected $loaded = array(
'form_fields' => false,
'form_groups' => false,
'list_fields' => false,
'filter_fields' => false,
'view_fields' => false,
'view_groups' => false,
'routes' => false,
'side_menu' => false,
);
/**
* This method can be overwritten to tweak the form construction, by default the form
* is built by reading the FieldDescription
*
* @return void
*/
protected function configureFormFields(FormMapper $form)
{
}
/**
* overwrite this method to configure the list FormField definition
*
* @param ListMapper $list
*/
protected function configureListFields(ListMapper $list)
{
}
/**
*
* @param DatagridMapper
*/
protected function configureDatagridFilters(DatagridMapper $filter)
{
}
/**
*
* @param DatagridMapper
*/
protected function configureViewFields(DatagridMapper $filter)
{
}
/**
* configure the Admin routes
*
* @param RouteCollection
*/
public function configureRoutes(RouteCollection $collection)
{
}
public function configureSideMenu(MenuItem $menu, $action, Admin $childAdmin = null)
{
}
/**
* @param string $code
* @param string $class
* @param string $baseControllerName
*/
public function __construct($code, $class, $baseControllerName)
{
$this->code = $code;
$this->class = $class;
$this->baseControllerName = $baseControllerName;
}
public function configure()
{
$this->uniqid = uniqid();
if (!$this->classnameLabel) {
$this->classnameLabel = $this->urlize(substr($this->class, strrpos($this->class, '\\') + 1), '_');
}
$this->baseCodeRoute = $this->getCode();
}
public function update($object)
{
$this->preUpdate($object);
$this->modelManager->update($object);
$this->postUpdate($object);
}
public function create($object)
{
$this->prePersist($object);
$this->modelManager->create($object);
$this->postPersist($object);
}
public function delete($object)
{
$this->preRemove($object);
$this->modelManager->delete($object);
$this->postRemove($object);
}
public function preUpdate($object)
{
}
public function postUpdate($object)
{
}
public function prePersist($object)
{
}
public function postPersist($object)
{
}
public function preRemove($object)
{
}
public function postRemove($object)
{
}
/**
* build the view FieldDescription array
*
* @return void
*/
protected function buildViewFieldDescriptions()
{
if ($this->loaded['view_fields']) {
return;
}
$this->loaded['view_fields'] = true;
$this->viewFieldDescriptions = $this->getBaseFields($this->view);
// normalize field
foreach ($this->viewFieldDescriptions as $fieldDescription) {
$this->getViewBuilder()->fixFieldDescription($this, $fieldDescription);
}
return $this->viewFieldDescriptions;
}
/**
* build the list FieldDescription array
*
* @return void
*/
protected function buildListFieldDescriptions()
{
if ($this->loaded['list_fields']) {
return;
}
$this->loaded['list_fields'] = true;
$this->listFieldDescriptions = $this->getBaseFields($this->list);
// normalize field
foreach ($this->listFieldDescriptions as $fieldDescription) {
$this->getListBuilder()->fixFieldDescription($this, $fieldDescription);
}
if (!isset($this->listFieldDescriptions['_batch']) && count($this->getBatchActions()) > 0) {
$fieldDescription = $this->modelManager->getNewFieldDescriptionInstance($this->getClass(), 'batch', array(
'label' => 'batch',
'code' => '_batch',
'type' => 'batch',
'sortable' => false
));
$fieldDescription->setAdmin($this);
$fieldDescription->setTemplate('SonataAdminBundle:CRUD:list__batch.html.twig');
$this->listFieldDescriptions = array( '_batch' => $fieldDescription ) + $this->listFieldDescriptions;
}
return $this->listFieldDescriptions;
}
/**
* Get parameters that are currently bound to the filter.
*
* @return array
*/
public function getFilterParameters()
{
$parameters = array();
// build the values array
if ($this->hasRequest()) {
$parameters = array_merge(
$this->getModelManager()->getDefaultSortValues($this->getClass()),
$this->datagridValues,
$this->request->query->all()
);
// always force the parent value
if ($this->isChild() && $this->getParentAssociationMapping()) {
$parameters[$this->getParentAssociationMapping()] = $this->request->get($this->getParent()->getIdParameter());
}
}
return $parameters;
}
/**
* build the filter FieldDescription array
*
* @return void
*/
public function buildFilterFieldDescriptions()
{
if ($this->loaded['filter_fields']) {
return;
}
$this->loaded['filter_fields'] = true;
$this->filterFieldDescriptions = $this->getBaseFields($this->filter);
// ok, try to limit to add parent filter
if ($this->getParentAssociationMapping()) {
$fieldDescription = $this->getModelManager()->getParentFieldDescription($this->getParentAssociationMapping(), $this->getClass());
$this->filterFieldDescriptions[$this->getParentAssociationMapping()] = $fieldDescription;
}
foreach ($this->filterFieldDescriptions as $fieldDescription) {
$this->getDatagridBuilder()->fixFieldDescription($this, $fieldDescription);
}
$parameters = $this->getFilterParameters();
// initialize the datagrid
$this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $parameters);
$this->datagrid->getPager()->setMaxPerPage($this->maxPerPage);
$mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this);
// build the datagrid filter
$this->buildFilterFieldDescriptions();
$this->configureDatagridFilters($mapper);
foreach ($this->getFilterFieldDescriptions() as $fieldDescription) {
$mapper->add($fieldDescription);
}
}
/**
* Returns the name of the parent related field, so the field can be use to set the default
* value (ie the parent object) or to filter the object
*
* @return string the name of the parent related field
*/
public function getParentAssociationMapping()
{
return $this->parentAssociationMapping;
}
/**
* Build the form FieldDescription collection
*
* @return void
*/
protected function buildFormFieldDescriptions()
{
if ($this->loaded['form_fields']) {
return;
}
$this->loaded['form_fields'] = true;
$this->formFieldDescriptions = $this->getBaseFields($this->form);
foreach ($this->formFieldDescriptions as $name => &$fieldDescription) {
$this->getFormContractor()->fixFieldDescription($this, $fieldDescription);
// unset the identifier field as it is not required to update an object
if ($fieldDescription->isIdentifier()) {
unset($this->formFieldDescriptions[$name]);
}
}
}
/**
* make sure the base fields are set in the correct format
*
* @param array $selectedFields
* @return array
*/
private function getBaseFields(array $selectedFields)
{
$fields = array();
// make sure we works with array
foreach ($selectedFields as $name => $options) {
if (!is_array($options)) {
$name = $options;
$options = array();
}
$description = $this->modelManager->getNewFieldDescriptionInstance($this->getClass(), $name, $options);
$fields[$name] = $description;
}
return $fields;
}
/**
* Returns the baseRoutePattern used to generate the routing information
*
* @throws RuntimeException
* @return string the baseRoutePattern used to generate the routing information
*/
public function getBaseRoutePattern()
{
if (!$this->baseRoutePattern) {
preg_match(self::BASE_ROUTE_REGEX, $this->getClass(), $matches);
if (!$matches) {
throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', get_class($this)));
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
$this->baseRoutePattern = sprintf('%s/{id}/%s',
$this->getParent()->getBaseRoutePattern(),
$this->urlize($matches[3], '-')
);
} elseif ($matches[1]) {
$this->baseRoutePattern = sprintf('/%s/%s/%s',
$this->urlize($matches[1], '-'),
$this->urlize($matches[2], '-'),
$this->urlize($matches[3], '-')
);
} else {
$this->baseRoutePattern = sprintf('/%s/%s',
$this->urlize($matches[2], '-'),
$this->urlize($matches[3], '-')
);
}
}
return $this->baseRoutePattern;
}
/**
* Returns the baseRouteName used to generate the routing information
*
* @throws RuntimeException
* @return string the baseRouteName used to generate the routing information
*/
public function getBaseRouteName()
{
if (!$this->baseRouteName) {
preg_match(self::BASE_ROUTE_REGEX, $this->getClass(), $matches);
if (!$matches) {
var_dump($regex, $this->getClass(),$matches);die(__METHOD__);
throw new \RuntimeException(sprintf('Please define a default `baseRouteName` value for the admin class `%s`', get_class($this)));
}
if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
$this->baseRouteName = sprintf('%s_%s',
$this->getParent()->getBaseRouteName(),
$this->urlize($matches[3])
);
} elseif ($matches[1]) {
$this->baseRouteName = sprintf('admin_%s_%s_%s',
$this->urlize($matches[1]),
$this->urlize($matches[2]),
$this->urlize($matches[3])
);
} else {
$this->baseRouteName = sprintf('admin_%s_%s',
$this->urlize($matches[2]),
$this->urlize($matches[3])
);
}
}
return $this->baseRouteName;
}
/**
* urlize the given word
*
* @param string $word
* @param string $sep the separator
*
* @return string
*/
public function urlize($word, $sep = '_')
{
return strtolower(preg_replace('/[^a-z0-9_]/i', $sep.'$1', $word));
}
/**
* Returns the class name handled by the Admin instance
*
* @return string the class name handled by the Admin instance
*/
public function getClass()
{
return $this->class;
}
/**
* Returns the list of batchs actions
*
* @return array the list of batchs actions
*/
public function getBatchActions()
{
$actions = array();
if ($this->isGranted('DELETE')) {
$actions['delete'] = $this->trans('action_delete', array(), 'SonataAdminBundle');
}
return $actions;
}
/**
* Returns the list of available urls
*
* @return \Sonata\AdminBundle\Route\RouteCollection the list of available urls
*/
public function getRoutes()
{
$this->buildRoutes();
return $this->routes;
}
/**
* Returns the parameter representing router id, ie: {id} or {childId}
*
* @return string
*/
public function getRouterIdParameter()
{
return $this->isChild() ? '{childId}' : '{id}';
}
/**
* Returns the parameter representing request id, ie: id or childId
*
* @return string
*/
public function getIdParameter()
{
return $this->isChild() ? 'childId' : 'id';
}
/**
* Build all the related urls to the current admin
*
* @return void
*/
public function buildRoutes()
{
if ($this->loaded['routes']) {
return;
}
$this->loaded['routes'] = true;
$collection = new RouteCollection(
$this->getBaseCodeRoute(),
$this->getBaseRouteName(),
$this->getBaseRoutePattern(),
$this->getBaseControllerName()
);
$collection->add('list');
$collection->add('create');
$collection->add('batch');
$collection->add('edit', $this->getRouterIdParameter().'/edit');
$collection->add('delete', $this->getRouterIdParameter().'/delete');
$collection->add('view', $this->getRouterIdParameter().'/view');
// add children urls
foreach ($this->getChildren() as $children) {
$collection->addCollection($children->getRoutes());
}
$this->configureRoutes($collection);
$this->routes = $collection;
}
/**
* Returns the url defined by the $name
*
* @param strinf $name
* @return Route
*/
public function getRoute($name)
{
$this->buildRoutes();
if (!$this->routes->has($name)) {
return false;
}
return $this->routes->get($name);
}
/**
* generate the url with the given $name
*
* @throws RuntimeException
* @param $name
* @param array $parameters
*
* @return return a complete url
*/
public function generateUrl($name, array $parameters = array())
{
if (!$this->isChild()) {
if (strpos($name, '.')) {
$name = $this->getCode().'|'.$name;
} else {
$name = $this->getCode().'.'.$name;
}
}
// if the admin is a child we automatically append the parent's id
else if ($this->isChild()) {
$name = $this->baseCodeRoute.'.'.$name;
// twig template does not accept variable hash key ... so cannot use admin.idparameter ...
// switch value
if (isset($parameters['id'])) {
$parameters[$this->getIdParameter()] = $parameters['id'];
unset($parameters['id']);
}
$parameters[$this->getParent()->getIdParameter()] = $this->request->get($this->getParent()->getIdParameter());
}
// if the admin is linked to a parent FieldDescription (ie, embedded widget)
if ($this->hasParentFieldDescription()) {
// merge link parameter if any provided by the parent field
$parameters = array_merge($parameters, $this->getParentFieldDescription()->getOption('link_parameters', array()));
$parameters['uniqid'] = $this->getUniqid();
$parameters['code'] = $this->getCode();
$parameters['pcode'] = $this->getParentFieldDescription()->getAdmin()->getCode();
$parameters['puniqid'] = $this->getParentFieldDescription()->getAdmin()->getUniqid();
}
if ($name == 'update' || substr($name, -7) == '|update') {
$parameters['uniqid'] = $this->getUniqid();
$parameters['code'] = $this->getCode();
}
// allows to define persistent parameters
if ($this->hasRequest()) {
$parameters = array_merge($this->getPersistentParameters(), $parameters);
}
$route = $this->getRoute($name);
if (!$route) {
throw new \RuntimeException(sprintf('unable to find the route `%s`', $name));
}
return $this->router->generate($route->getDefault('_sonata_name'), $parameters);
}
/**
* Returns the list template
*
* @return string the list template
*/
public function getListTemplate()
{
return 'SonataAdminBundle:CRUD:list.html.twig';
}
/**
* Returns the edit template
*
* @return string the edit template
*/
public function getEditTemplate()
{
return 'SonataAdminBundle:CRUD:edit.html.twig';
}
/**
* Returns the view template
*
* @return string the view template
*/
public function getViewTemplate()
{
return 'SonataAdminBundle:CRUD:view.html.twig';
}
/**
* Returns an instance of the related classname
*
* @return Object An instance of the related classname
*/
public function getNewInstance()
{
return $this->modelManager->getModelInstance($this->getClass());
}
/**
* @param Object $object
* @param array $options
* @return \Symfony\Component\Form\FormBuilder the form builder
*/
public function getFormBuilder($object = null, $options = array())
{
if (!$object) {
$object = $this->getSubject();
}
if (!$object) {
$object = $this->getNewInstance();
}
$formBuilder = $this->getFormContractor()->getFormBuilder(
$this->getUniqid(),
array_merge($this->formOptions, $options)
);
$formBuilder->setData($object);
$this->defineFormBuilder($formBuilder);