Complex classes like AbstractAdmin often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractAdmin, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
60 | abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface |
||
61 | { |
||
62 | public const CONTEXT_MENU = 'menu'; |
||
63 | public const CONTEXT_DASHBOARD = 'dashboard'; |
||
64 | |||
65 | public const CLASS_REGEX = |
||
66 | '@ |
||
67 | (?:([A-Za-z0-9]*)\\\)? # vendor name / app name |
||
68 | (Bundle\\\)? # optional bundle directory |
||
69 | ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix |
||
70 | ( |
||
71 | Entity|Document|Model|PHPCR|CouchDocument|Phpcr| |
||
72 | Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB |
||
73 | )\\\(.*)@x'; |
||
74 | |||
75 | public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; |
||
76 | |||
77 | /** |
||
78 | * The list FieldDescription constructed from the configureListField method. |
||
79 | * |
||
80 | * @var FieldDescriptionInterface[] |
||
81 | */ |
||
82 | protected $listFieldDescriptions = []; |
||
83 | |||
84 | /** |
||
85 | * The show FieldDescription constructed from the configureShowFields method. |
||
86 | * |
||
87 | * @var FieldDescriptionInterface[] |
||
88 | */ |
||
89 | protected $showFieldDescriptions = []; |
||
90 | |||
91 | /** |
||
92 | * The list FieldDescription constructed from the configureFormField method. |
||
93 | * |
||
94 | * @var FieldDescriptionInterface[] |
||
95 | */ |
||
96 | protected $formFieldDescriptions = []; |
||
97 | |||
98 | /** |
||
99 | * The filter FieldDescription constructed from the configureFilterField method. |
||
100 | * |
||
101 | * @var FieldDescriptionInterface[] |
||
102 | */ |
||
103 | protected $filterFieldDescriptions = []; |
||
104 | |||
105 | /** |
||
106 | * NEXT_MAJOR: Remove this property. |
||
107 | * |
||
108 | * The number of result to display in the list. |
||
109 | * |
||
110 | * @deprecated since sonata-project/admin-bundle 3.67. |
||
111 | * |
||
112 | * @var int |
||
113 | */ |
||
114 | protected $maxPerPage = 32; |
||
115 | |||
116 | /** |
||
117 | * The maximum number of page numbers to display in the list. |
||
118 | * |
||
119 | * @var int |
||
120 | */ |
||
121 | protected $maxPageLinks = 25; |
||
122 | |||
123 | /** |
||
124 | * The base route name used to generate the routing information. |
||
125 | * |
||
126 | * @var string |
||
127 | */ |
||
128 | protected $baseRouteName; |
||
129 | |||
130 | /** |
||
131 | * The base route pattern used to generate the routing information. |
||
132 | * |
||
133 | * @var string |
||
134 | */ |
||
135 | protected $baseRoutePattern; |
||
136 | |||
137 | /** |
||
138 | * The base name controller used to generate the routing information. |
||
139 | * |
||
140 | * @var string |
||
141 | */ |
||
142 | protected $baseControllerName; |
||
143 | |||
144 | /** |
||
145 | * The label class name (used in the title/breadcrumb ...). |
||
146 | * |
||
147 | * @var string |
||
148 | */ |
||
149 | protected $classnameLabel; |
||
150 | |||
151 | /** |
||
152 | * The translation domain to be used to translate messages. |
||
153 | * |
||
154 | * @var string |
||
155 | */ |
||
156 | protected $translationDomain = 'messages'; |
||
157 | |||
158 | /** |
||
159 | * Options to set to the form (ie, validation_groups). |
||
160 | * |
||
161 | * @var array |
||
162 | */ |
||
163 | protected $formOptions = []; |
||
164 | |||
165 | /** |
||
166 | * NEXT_MAJOR: Remove this property. |
||
167 | * |
||
168 | * Default values to the datagrid. |
||
169 | * |
||
170 | * @deprecated since sonata-project/admin-bundle 3.67, use configureDefaultSortValues() instead. |
||
171 | * |
||
172 | * @var array |
||
173 | */ |
||
174 | protected $datagridValues = [ |
||
175 | '_page' => 1, |
||
176 | '_per_page' => 32, |
||
177 | ]; |
||
178 | |||
179 | /** |
||
180 | * NEXT_MAJOR: Remove this property. |
||
181 | * |
||
182 | * Predefined per page options. |
||
183 | * |
||
184 | * @deprecated since sonata-project/admin-bundle 3.67. |
||
185 | * |
||
186 | * @var array |
||
187 | */ |
||
188 | protected $perPageOptions = [16, 32, 64, 128, 256]; |
||
189 | |||
190 | /** |
||
191 | * Pager type. |
||
192 | * |
||
193 | * @var string |
||
194 | */ |
||
195 | protected $pagerType = Pager::TYPE_DEFAULT; |
||
196 | |||
197 | /** |
||
198 | * The code related to the admin. |
||
199 | * |
||
200 | * @var string |
||
201 | */ |
||
202 | protected $code; |
||
203 | |||
204 | /** |
||
205 | * The label. |
||
206 | * |
||
207 | * @var string |
||
208 | */ |
||
209 | protected $label; |
||
210 | |||
211 | /** |
||
212 | * Whether or not to persist the filters in the session. |
||
213 | * |
||
214 | * NEXT_MAJOR: remove this property |
||
215 | * |
||
216 | * @var bool |
||
217 | * |
||
218 | * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. |
||
219 | */ |
||
220 | protected $persistFilters = false; |
||
221 | |||
222 | /** |
||
223 | * Array of routes related to this admin. |
||
224 | * |
||
225 | * @var RouteCollection |
||
226 | */ |
||
227 | protected $routes; |
||
228 | |||
229 | /** |
||
230 | * The subject only set in edit/update/create mode. |
||
231 | * |
||
232 | * @var object|null |
||
233 | */ |
||
234 | protected $subject; |
||
235 | |||
236 | /** |
||
237 | * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}. |
||
238 | * |
||
239 | * @var array |
||
240 | */ |
||
241 | protected $children = []; |
||
242 | |||
243 | /** |
||
244 | * Reference the parent admin. |
||
245 | * |
||
246 | * @var AdminInterface|null |
||
247 | */ |
||
248 | protected $parent; |
||
249 | |||
250 | /** |
||
251 | * The base code route refer to the prefix used to generate the route name. |
||
252 | * |
||
253 | * NEXT_MAJOR: remove this attribute. |
||
254 | * |
||
255 | * @deprecated This attribute is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0 |
||
256 | * |
||
257 | * @var string |
||
258 | */ |
||
259 | protected $baseCodeRoute = ''; |
||
260 | |||
261 | /** |
||
262 | * NEXT_MAJOR: should be default array and private. |
||
263 | * |
||
264 | * @var string|array |
||
265 | */ |
||
266 | protected $parentAssociationMapping; |
||
267 | |||
268 | /** |
||
269 | * Reference the parent FieldDescription related to this admin |
||
270 | * only set for FieldDescription which is associated to an Sub Admin instance. |
||
271 | * |
||
272 | * @var FieldDescriptionInterface |
||
273 | */ |
||
274 | protected $parentFieldDescription; |
||
275 | |||
276 | /** |
||
277 | * If true then the current admin is part of the nested admin set (from the url). |
||
278 | * |
||
279 | * @var bool |
||
280 | */ |
||
281 | protected $currentChild = false; |
||
282 | |||
283 | /** |
||
284 | * The uniqid is used to avoid clashing with 2 admin related to the code |
||
285 | * ie: a Block linked to a Block. |
||
286 | * |
||
287 | * @var string |
||
288 | */ |
||
289 | protected $uniqid; |
||
290 | |||
291 | /** |
||
292 | * The Entity or Document manager. |
||
293 | * |
||
294 | * @var ModelManagerInterface |
||
295 | */ |
||
296 | protected $modelManager; |
||
297 | |||
298 | /** |
||
299 | * The current request object. |
||
300 | * |
||
301 | * @var Request|null |
||
302 | */ |
||
303 | protected $request; |
||
304 | |||
305 | /** |
||
306 | * The translator component. |
||
307 | * |
||
308 | * NEXT_MAJOR: remove this property |
||
309 | * |
||
310 | * @var \Symfony\Component\Translation\TranslatorInterface |
||
311 | * |
||
312 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
313 | */ |
||
314 | protected $translator; |
||
315 | |||
316 | /** |
||
317 | * The related form contractor. |
||
318 | * |
||
319 | * @var FormContractorInterface |
||
320 | */ |
||
321 | protected $formContractor; |
||
322 | |||
323 | /** |
||
324 | * The related list builder. |
||
325 | * |
||
326 | * @var ListBuilderInterface |
||
327 | */ |
||
328 | protected $listBuilder; |
||
329 | |||
330 | /** |
||
331 | * The related view builder. |
||
332 | * |
||
333 | * @var ShowBuilderInterface |
||
334 | */ |
||
335 | protected $showBuilder; |
||
336 | |||
337 | /** |
||
338 | * The related datagrid builder. |
||
339 | * |
||
340 | * @var DatagridBuilderInterface |
||
341 | */ |
||
342 | protected $datagridBuilder; |
||
343 | |||
344 | /** |
||
345 | * @var RouteBuilderInterface |
||
346 | */ |
||
347 | protected $routeBuilder; |
||
348 | |||
349 | /** |
||
350 | * The datagrid instance. |
||
351 | * |
||
352 | * @var DatagridInterface|null |
||
353 | */ |
||
354 | protected $datagrid; |
||
355 | |||
356 | /** |
||
357 | * The router instance. |
||
358 | * |
||
359 | * @var RouteGeneratorInterface|null |
||
360 | */ |
||
361 | protected $routeGenerator; |
||
362 | |||
363 | /** |
||
364 | * The generated breadcrumbs. |
||
365 | * |
||
366 | * NEXT_MAJOR : remove this property |
||
367 | * |
||
368 | * @var array |
||
369 | */ |
||
370 | protected $breadcrumbs = []; |
||
371 | |||
372 | /** |
||
373 | * @var SecurityHandlerInterface |
||
374 | */ |
||
375 | protected $securityHandler; |
||
376 | |||
377 | /** |
||
378 | * @var ValidatorInterface |
||
379 | */ |
||
380 | protected $validator; |
||
381 | |||
382 | /** |
||
383 | * The configuration pool. |
||
384 | * |
||
385 | * @var Pool |
||
386 | */ |
||
387 | protected $configurationPool; |
||
388 | |||
389 | /** |
||
390 | * @var ItemInterface |
||
391 | */ |
||
392 | protected $menu; |
||
393 | |||
394 | /** |
||
395 | * @var FactoryInterface |
||
396 | */ |
||
397 | protected $menuFactory; |
||
398 | |||
399 | /** |
||
400 | * @var array<string, bool> |
||
401 | */ |
||
402 | protected $loaded = [ |
||
403 | 'view_fields' => false, // NEXT_MAJOR: Remove this unused value. |
||
404 | 'view_groups' => false, // NEXT_MAJOR: Remove this unused value. |
||
405 | 'routes' => false, |
||
406 | 'tab_menu' => false, |
||
407 | 'show' => false, |
||
408 | 'list' => false, |
||
409 | 'form' => false, |
||
410 | 'datagrid' => false, |
||
411 | ]; |
||
412 | |||
413 | /** |
||
414 | * @var string[] |
||
415 | */ |
||
416 | protected $formTheme = []; |
||
417 | |||
418 | /** |
||
419 | * @var string[] |
||
420 | */ |
||
421 | protected $filterTheme = []; |
||
422 | |||
423 | /** |
||
424 | * @var array<string, string> |
||
425 | * |
||
426 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
427 | */ |
||
428 | protected $templates = []; |
||
429 | |||
430 | /** |
||
431 | * @var AdminExtensionInterface[] |
||
432 | */ |
||
433 | protected $extensions = []; |
||
434 | |||
435 | /** |
||
436 | * @var LabelTranslatorStrategyInterface |
||
437 | */ |
||
438 | protected $labelTranslatorStrategy; |
||
439 | |||
440 | /** |
||
441 | * Setting to true will enable preview mode for |
||
442 | * the entity and show a preview button in the |
||
443 | * edit/create forms. |
||
444 | * |
||
445 | * @var bool |
||
446 | */ |
||
447 | protected $supportsPreviewMode = false; |
||
448 | |||
449 | /** |
||
450 | * Roles and permissions per role. |
||
451 | * |
||
452 | * @var array 'role' => ['permission', 'permission'] |
||
453 | */ |
||
454 | protected $securityInformation = []; |
||
455 | |||
456 | protected $cacheIsGranted = []; |
||
457 | |||
458 | /** |
||
459 | * Action list for the search result. |
||
460 | * |
||
461 | * @var string[] |
||
462 | */ |
||
463 | protected $searchResultActions = ['edit', 'show']; |
||
464 | |||
465 | protected $listModes = [ |
||
466 | 'list' => [ |
||
467 | 'class' => 'fa fa-list fa-fw', |
||
468 | ], |
||
469 | 'mosaic' => [ |
||
470 | 'class' => self::MOSAIC_ICON_CLASS, |
||
471 | ], |
||
472 | ]; |
||
473 | |||
474 | /** |
||
475 | * The Access mapping. |
||
476 | * |
||
477 | * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]] |
||
478 | */ |
||
479 | protected $accessMapping = []; |
||
480 | |||
481 | /** |
||
482 | * @var MutableTemplateRegistryInterface |
||
483 | */ |
||
484 | private $templateRegistry; |
||
485 | |||
486 | /** |
||
487 | * The class name managed by the admin class. |
||
488 | * |
||
489 | * @var string |
||
490 | */ |
||
491 | private $class; |
||
492 | |||
493 | /** |
||
494 | * The subclasses supported by the admin class. |
||
495 | * |
||
496 | * @var array<string, string> |
||
497 | */ |
||
498 | private $subClasses = []; |
||
499 | |||
500 | /** |
||
501 | * The list collection. |
||
502 | * |
||
503 | * @var FieldDescriptionCollection|null |
||
504 | */ |
||
505 | private $list; |
||
506 | |||
507 | /** |
||
508 | * @var FieldDescriptionCollection|null |
||
509 | */ |
||
510 | private $show; |
||
511 | |||
512 | /** |
||
513 | * @var Form|null |
||
514 | */ |
||
515 | private $form; |
||
516 | |||
517 | /** |
||
518 | * The cached base route name. |
||
519 | * |
||
520 | * @var string |
||
521 | */ |
||
522 | private $cachedBaseRouteName; |
||
523 | |||
524 | /** |
||
525 | * The cached base route pattern. |
||
526 | * |
||
527 | * @var string |
||
528 | */ |
||
529 | private $cachedBaseRoutePattern; |
||
530 | |||
531 | /** |
||
532 | * The form group disposition. |
||
533 | * |
||
534 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
535 | * hold boolean values. |
||
536 | * |
||
537 | * @var array|bool |
||
538 | */ |
||
539 | private $formGroups = false; |
||
540 | |||
541 | /** |
||
542 | * The form tabs disposition. |
||
543 | * |
||
544 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
545 | * hold boolean values. |
||
546 | * |
||
547 | * @var array|bool |
||
548 | */ |
||
549 | private $formTabs = false; |
||
550 | |||
551 | /** |
||
552 | * The view group disposition. |
||
553 | * |
||
554 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
555 | * hold boolean values. |
||
556 | * |
||
557 | * @var array|bool |
||
558 | */ |
||
559 | private $showGroups = false; |
||
560 | |||
561 | /** |
||
562 | * The view tab disposition. |
||
563 | * |
||
564 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
565 | * hold boolean values. |
||
566 | * |
||
567 | * @var array|bool |
||
568 | */ |
||
569 | private $showTabs = false; |
||
570 | |||
571 | /** |
||
572 | * The manager type to use for the admin. |
||
573 | * |
||
574 | * @var string |
||
575 | */ |
||
576 | private $managerType; |
||
577 | |||
578 | /** |
||
579 | * The breadcrumbsBuilder component. |
||
580 | * |
||
581 | * @var BreadcrumbsBuilderInterface |
||
582 | */ |
||
583 | private $breadcrumbsBuilder; |
||
584 | |||
585 | /** |
||
586 | * Component responsible for persisting filters. |
||
587 | * |
||
588 | * @var FilterPersisterInterface|null |
||
589 | */ |
||
590 | private $filterPersister; |
||
591 | |||
592 | /** |
||
593 | * @param string $code |
||
594 | * @param string $class |
||
595 | * @param string|null $baseControllerName |
||
596 | */ |
||
597 | public function __construct($code, $class, $baseControllerName = null) |
||
598 | { |
||
599 | if (!\is_string($code)) { |
||
600 | @trigger_error(sprintf( |
||
|
|||
601 | 'Passing other type than string as argument 1 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string in version 4.0.', |
||
602 | __METHOD__ |
||
603 | ), E_USER_DEPRECATED); |
||
604 | } |
||
605 | $this->code = $code; |
||
606 | if (!\is_string($class)) { |
||
607 | @trigger_error(sprintf( |
||
608 | 'Passing other type than string as argument 2 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string in version 4.0.', |
||
609 | __METHOD__ |
||
610 | ), E_USER_DEPRECATED); |
||
611 | } |
||
612 | $this->class = $class; |
||
613 | if (null !== $baseControllerName && !\is_string($baseControllerName)) { |
||
614 | @trigger_error(sprintf( |
||
615 | 'Passing other type than string or null as argument 3 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string and null in version 4.0.', |
||
616 | __METHOD__ |
||
617 | ), E_USER_DEPRECATED); |
||
618 | } |
||
619 | $this->baseControllerName = $baseControllerName; |
||
620 | |||
621 | // NEXT_MAJOR: Remove this line. |
||
622 | $this->predefinePerPageOptions(); |
||
623 | |||
624 | // NEXT_MAJOR: Remove this line. |
||
625 | $this->datagridValues['_per_page'] = $this->maxPerPage; |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * {@inheritdoc} |
||
630 | */ |
||
631 | public function getExportFormats() |
||
632 | { |
||
633 | return [ |
||
634 | 'json', 'xml', 'csv', 'xls', |
||
635 | ]; |
||
636 | } |
||
637 | |||
638 | /** |
||
639 | * @return array |
||
640 | */ |
||
641 | public function getExportFields() |
||
642 | { |
||
643 | $fields = $this->getModelManager()->getExportFields($this->getClass()); |
||
644 | |||
645 | foreach ($this->getExtensions() as $extension) { |
||
646 | if (method_exists($extension, 'configureExportFields')) { |
||
647 | $fields = $extension->configureExportFields($this, $fields); |
||
648 | } |
||
649 | } |
||
650 | |||
651 | return $fields; |
||
652 | } |
||
653 | |||
654 | public function getDataSourceIterator() |
||
655 | { |
||
656 | $datagrid = $this->getDatagrid(); |
||
657 | $datagrid->buildPager(); |
||
658 | |||
659 | $fields = []; |
||
660 | |||
661 | foreach ($this->getExportFields() as $key => $field) { |
||
662 | $label = $this->getTranslationLabel($field, 'export', 'label'); |
||
663 | $transLabel = $this->trans($label); |
||
664 | |||
665 | // NEXT_MAJOR: Remove this hack, because all field labels will be translated with the major release |
||
666 | // No translation key exists |
||
667 | if ($transLabel === $label) { |
||
668 | $fields[$key] = $field; |
||
669 | } else { |
||
670 | $fields[$transLabel] = $field; |
||
671 | } |
||
672 | } |
||
673 | |||
674 | return $this->getModelManager()->getDataSourceIterator($datagrid, $fields); |
||
675 | } |
||
676 | |||
677 | public function validate(ErrorElement $errorElement, $object) |
||
678 | { |
||
679 | } |
||
680 | |||
681 | /** |
||
682 | * define custom variable. |
||
683 | */ |
||
684 | public function initialize() |
||
685 | { |
||
686 | if (!$this->classnameLabel) { |
||
687 | /* NEXT_MAJOR: remove cast to string, null is not supposed to be |
||
688 | supported but was documented as such */ |
||
689 | $this->classnameLabel = substr( |
||
690 | (string) $this->getClass(), |
||
691 | strrpos((string) $this->getClass(), '\\') + 1 |
||
692 | ); |
||
693 | } |
||
694 | |||
695 | // NEXT_MAJOR: Remove this line. |
||
696 | $this->baseCodeRoute = $this->getCode(); |
||
697 | |||
698 | $this->configure(); |
||
699 | } |
||
700 | |||
701 | public function configure() |
||
702 | { |
||
703 | } |
||
704 | |||
705 | public function update($object) |
||
706 | { |
||
707 | $this->preUpdate($object); |
||
708 | foreach ($this->extensions as $extension) { |
||
709 | $extension->preUpdate($this, $object); |
||
710 | } |
||
711 | |||
712 | $result = $this->getModelManager()->update($object); |
||
713 | // BC compatibility |
||
714 | if (null !== $result) { |
||
715 | $object = $result; |
||
716 | } |
||
717 | |||
718 | $this->postUpdate($object); |
||
719 | foreach ($this->extensions as $extension) { |
||
720 | $extension->postUpdate($this, $object); |
||
721 | } |
||
722 | |||
723 | return $object; |
||
724 | } |
||
725 | |||
726 | public function create($object) |
||
727 | { |
||
728 | $this->prePersist($object); |
||
729 | foreach ($this->extensions as $extension) { |
||
730 | $extension->prePersist($this, $object); |
||
731 | } |
||
732 | |||
733 | $result = $this->getModelManager()->create($object); |
||
734 | // BC compatibility |
||
735 | if (null !== $result) { |
||
736 | $object = $result; |
||
737 | } |
||
738 | |||
739 | $this->postPersist($object); |
||
740 | foreach ($this->extensions as $extension) { |
||
741 | $extension->postPersist($this, $object); |
||
742 | } |
||
743 | |||
744 | $this->createObjectSecurity($object); |
||
745 | |||
746 | return $object; |
||
747 | } |
||
748 | |||
749 | public function delete($object) |
||
750 | { |
||
751 | $this->preRemove($object); |
||
752 | foreach ($this->extensions as $extension) { |
||
753 | $extension->preRemove($this, $object); |
||
754 | } |
||
755 | |||
756 | $this->getSecurityHandler()->deleteObjectSecurity($this, $object); |
||
757 | $this->getModelManager()->delete($object); |
||
758 | |||
759 | $this->postRemove($object); |
||
760 | foreach ($this->extensions as $extension) { |
||
761 | $extension->postRemove($this, $object); |
||
762 | } |
||
763 | } |
||
764 | |||
765 | /** |
||
766 | * @param object $object |
||
767 | */ |
||
768 | public function preValidate($object) |
||
769 | { |
||
770 | } |
||
771 | |||
772 | public function preUpdate($object) |
||
773 | { |
||
774 | } |
||
775 | |||
776 | public function postUpdate($object) |
||
777 | { |
||
778 | } |
||
779 | |||
780 | public function prePersist($object) |
||
781 | { |
||
782 | } |
||
783 | |||
784 | public function postPersist($object) |
||
785 | { |
||
786 | } |
||
787 | |||
788 | public function preRemove($object) |
||
789 | { |
||
790 | } |
||
791 | |||
792 | public function postRemove($object) |
||
793 | { |
||
794 | } |
||
795 | |||
796 | public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements) |
||
797 | { |
||
798 | } |
||
799 | |||
800 | public function getFilterParameters() |
||
801 | { |
||
802 | $parameters = []; |
||
803 | |||
804 | // build the values array |
||
805 | if ($this->hasRequest()) { |
||
806 | $filters = $this->request->query->get('filter', []); |
||
807 | if (isset($filters['_page'])) { |
||
808 | $filters['_page'] = (int) $filters['_page']; |
||
809 | } |
||
810 | if (isset($filters['_per_page'])) { |
||
811 | $filters['_per_page'] = (int) $filters['_per_page']; |
||
812 | } |
||
813 | |||
814 | // if filter persistence is configured |
||
815 | // NEXT_MAJOR: remove `$this->persistFilters !== false` from the condition |
||
816 | if (false !== $this->persistFilters && null !== $this->filterPersister) { |
||
817 | // if reset filters is asked, remove from storage |
||
818 | if ('reset' === $this->request->query->get('filters')) { |
||
819 | $this->filterPersister->reset($this->getCode()); |
||
820 | } |
||
821 | |||
822 | // if no filters, fetch from storage |
||
823 | // otherwise save to storage |
||
824 | if (empty($filters)) { |
||
825 | $filters = $this->filterPersister->get($this->getCode()); |
||
826 | } else { |
||
827 | $this->filterPersister->set($this->getCode(), $filters); |
||
828 | } |
||
829 | } |
||
830 | |||
831 | $parameters = array_merge( |
||
832 | $this->getModelManager()->getDefaultSortValues($this->getClass()), |
||
833 | $this->datagridValues, // NEXT_MAJOR: Remove this line. |
||
834 | $this->getDefaultSortValues(), |
||
835 | $this->getDefaultFilterValues(), |
||
836 | $filters |
||
837 | ); |
||
838 | |||
839 | if (!$this->determinedPerPageValue($parameters['_per_page'])) { |
||
840 | $parameters['_per_page'] = $this->getMaxPerPage(); |
||
841 | } |
||
842 | |||
843 | // always force the parent value |
||
844 | if ($this->isChild() && $this->getParentAssociationMapping()) { |
||
845 | $name = str_replace('.', '__', $this->getParentAssociationMapping()); |
||
846 | $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())]; |
||
847 | } |
||
848 | } |
||
849 | |||
850 | return $parameters; |
||
851 | } |
||
852 | |||
853 | /** |
||
854 | * NEXT_MAJOR: Change the visibility to protected (similar to buildShow, buildForm, ...). |
||
855 | */ |
||
856 | public function buildDatagrid() |
||
857 | { |
||
858 | if ($this->loaded['datagrid']) { |
||
859 | return; |
||
860 | } |
||
861 | |||
862 | $this->loaded['datagrid'] = true; |
||
863 | |||
864 | $filterParameters = $this->getFilterParameters(); |
||
865 | |||
866 | // transform _sort_by from a string to a FieldDescriptionInterface for the datagrid. |
||
867 | if (isset($filterParameters['_sort_by']) && \is_string($filterParameters['_sort_by'])) { |
||
868 | if ($this->hasListFieldDescription($filterParameters['_sort_by'])) { |
||
869 | $filterParameters['_sort_by'] = $this->getListFieldDescription($filterParameters['_sort_by']); |
||
870 | } else { |
||
871 | $filterParameters['_sort_by'] = $this->getModelManager()->getNewFieldDescriptionInstance( |
||
872 | $this->getClass(), |
||
873 | $filterParameters['_sort_by'], |
||
874 | [] |
||
875 | ); |
||
876 | |||
877 | $this->getListBuilder()->buildField(null, $filterParameters['_sort_by'], $this); |
||
878 | } |
||
879 | } |
||
880 | |||
881 | // initialize the datagrid |
||
882 | $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $filterParameters); |
||
883 | |||
884 | $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks); |
||
885 | |||
886 | $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); |
||
887 | |||
888 | // build the datagrid filter |
||
889 | $this->configureDatagridFilters($mapper); |
||
890 | |||
891 | // ok, try to limit to add parent filter |
||
892 | if ($this->isChild() && $this->getParentAssociationMapping() && !$mapper->has($this->getParentAssociationMapping())) { |
||
893 | $mapper->add($this->getParentAssociationMapping(), null, [ |
||
894 | 'show_filter' => false, |
||
895 | 'label' => false, |
||
896 | 'field_type' => ModelHiddenType::class, |
||
897 | 'field_options' => [ |
||
898 | 'model_manager' => $this->getModelManager(), |
||
899 | ], |
||
900 | 'operator_type' => HiddenType::class, |
||
901 | ], null, null, [ |
||
902 | 'admin_code' => $this->getParent()->getCode(), |
||
903 | ]); |
||
904 | } |
||
905 | |||
906 | foreach ($this->getExtensions() as $extension) { |
||
907 | $extension->configureDatagridFilters($mapper); |
||
908 | } |
||
909 | } |
||
910 | |||
911 | /** |
||
912 | * Returns the name of the parent related field, so the field can be use to set the default |
||
913 | * value (ie the parent object) or to filter the object. |
||
914 | * |
||
915 | * @throws \InvalidArgumentException |
||
916 | * |
||
917 | * @return string|null |
||
918 | */ |
||
919 | public function getParentAssociationMapping() |
||
920 | { |
||
921 | // NEXT_MAJOR: remove array check |
||
922 | if (\is_array($this->parentAssociationMapping) && $this->isChild()) { |
||
923 | $parent = $this->getParent()->getCode(); |
||
924 | |||
925 | if (\array_key_exists($parent, $this->parentAssociationMapping)) { |
||
926 | return $this->parentAssociationMapping[$parent]; |
||
927 | } |
||
928 | |||
929 | throw new \InvalidArgumentException(sprintf( |
||
930 | "There's no association between %s and %s.", |
||
931 | $this->getCode(), |
||
932 | $this->getParent()->getCode() |
||
933 | )); |
||
934 | } |
||
935 | |||
936 | // NEXT_MAJOR: remove this line |
||
937 | return $this->parentAssociationMapping; |
||
938 | } |
||
939 | |||
940 | /** |
||
941 | * @param string $code |
||
942 | * @param string $value |
||
943 | */ |
||
944 | final public function addParentAssociationMapping($code, $value) |
||
945 | { |
||
946 | $this->parentAssociationMapping[$code] = $value; |
||
947 | } |
||
948 | |||
949 | /** |
||
950 | * Returns the baseRoutePattern used to generate the routing information. |
||
951 | * |
||
952 | * @throws \RuntimeException |
||
953 | * |
||
954 | * @return string the baseRoutePattern used to generate the routing information |
||
955 | */ |
||
956 | public function getBaseRoutePattern() |
||
957 | { |
||
958 | if (null !== $this->cachedBaseRoutePattern) { |
||
959 | return $this->cachedBaseRoutePattern; |
||
960 | } |
||
961 | |||
962 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern |
||
963 | $baseRoutePattern = $this->baseRoutePattern; |
||
964 | if (!$this->baseRoutePattern) { |
||
965 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
966 | |||
967 | if (!$matches) { |
||
968 | throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class)); |
||
969 | } |
||
970 | $baseRoutePattern = $this->urlize($matches[5], '-'); |
||
971 | } |
||
972 | |||
973 | $this->cachedBaseRoutePattern = sprintf( |
||
974 | '%s/%s/%s', |
||
975 | $this->getParent()->getBaseRoutePattern(), |
||
976 | $this->getParent()->getRouterIdParameter(), |
||
977 | $baseRoutePattern |
||
978 | ); |
||
979 | } elseif ($this->baseRoutePattern) { |
||
980 | $this->cachedBaseRoutePattern = $this->baseRoutePattern; |
||
981 | } else { |
||
982 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
983 | |||
984 | if (!$matches) { |
||
985 | throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class)); |
||
986 | } |
||
987 | |||
988 | $this->cachedBaseRoutePattern = sprintf( |
||
989 | '/%s%s/%s', |
||
990 | empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/', |
||
991 | $this->urlize($matches[3], '-'), |
||
992 | $this->urlize($matches[5], '-') |
||
993 | ); |
||
994 | } |
||
995 | |||
996 | return $this->cachedBaseRoutePattern; |
||
997 | } |
||
998 | |||
999 | /** |
||
1000 | * Returns the baseRouteName used to generate the routing information. |
||
1001 | * |
||
1002 | * @throws \RuntimeException |
||
1003 | * |
||
1004 | * @return string the baseRouteName used to generate the routing information |
||
1005 | */ |
||
1006 | public function getBaseRouteName() |
||
1007 | { |
||
1008 | if (null !== $this->cachedBaseRouteName) { |
||
1009 | return $this->cachedBaseRouteName; |
||
1010 | } |
||
1011 | |||
1012 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name |
||
1013 | $baseRouteName = $this->baseRouteName; |
||
1014 | if (!$this->baseRouteName) { |
||
1015 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
1016 | |||
1017 | if (!$matches) { |
||
1018 | throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class)); |
||
1019 | } |
||
1020 | $baseRouteName = $this->urlize($matches[5]); |
||
1021 | } |
||
1022 | |||
1023 | $this->cachedBaseRouteName = sprintf( |
||
1024 | '%s_%s', |
||
1025 | $this->getParent()->getBaseRouteName(), |
||
1026 | $baseRouteName |
||
1027 | ); |
||
1028 | } elseif ($this->baseRouteName) { |
||
1029 | $this->cachedBaseRouteName = $this->baseRouteName; |
||
1030 | } else { |
||
1031 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
1032 | |||
1033 | if (!$matches) { |
||
1034 | throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class)); |
||
1035 | } |
||
1036 | |||
1037 | $this->cachedBaseRouteName = sprintf( |
||
1038 | 'admin_%s%s_%s', |
||
1039 | empty($matches[1]) ? '' : $this->urlize($matches[1]).'_', |
||
1040 | $this->urlize($matches[3]), |
||
1041 | $this->urlize($matches[5]) |
||
1042 | ); |
||
1043 | } |
||
1044 | |||
1045 | return $this->cachedBaseRouteName; |
||
1046 | } |
||
1047 | |||
1048 | /** |
||
1049 | * urlize the given word. |
||
1050 | * |
||
1051 | * @param string $word |
||
1052 | * @param string $sep the separator |
||
1053 | * |
||
1054 | * @return string |
||
1055 | */ |
||
1056 | public function urlize($word, $sep = '_') |
||
1057 | { |
||
1058 | return strtolower(preg_replace('/[^a-z0-9_]/i', $sep.'$1', $word)); |
||
1059 | } |
||
1060 | |||
1061 | public function getClass() |
||
1062 | { |
||
1063 | if ($this->hasActiveSubClass()) { |
||
1064 | if ($this->hasParentFieldDescription()) { |
||
1065 | throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass'); |
||
1066 | } |
||
1067 | |||
1068 | $subClass = $this->getRequest()->query->get('subclass'); |
||
1069 | |||
1070 | if (!$this->hasSubClass($subClass)) { |
||
1071 | throw new \RuntimeException(sprintf('Subclass "%s" is not defined.', $subClass)); |
||
1072 | } |
||
1073 | |||
1074 | return $this->getSubClass($subClass); |
||
1075 | } |
||
1076 | |||
1077 | // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 |
||
1078 | if ($this->subject && \is_object($this->subject)) { |
||
1079 | return ClassUtils::getClass($this->subject); |
||
1080 | } |
||
1081 | |||
1082 | return $this->class; |
||
1083 | } |
||
1084 | |||
1085 | public function getSubClasses() |
||
1086 | { |
||
1087 | return $this->subClasses; |
||
1088 | } |
||
1089 | |||
1090 | /** |
||
1091 | * NEXT_MAJOR: remove this method. |
||
1092 | */ |
||
1093 | public function addSubClass($subClass) |
||
1094 | { |
||
1095 | @trigger_error(sprintf( |
||
1096 | 'Method "%s" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0.', |
||
1097 | __METHOD__ |
||
1098 | ), E_USER_DEPRECATED); |
||
1099 | |||
1100 | if (!\in_array($subClass, $this->subClasses, true)) { |
||
1101 | $this->subClasses[] = $subClass; |
||
1102 | } |
||
1103 | } |
||
1104 | |||
1105 | public function setSubClasses(array $subClasses) |
||
1106 | { |
||
1107 | $this->subClasses = $subClasses; |
||
1108 | } |
||
1109 | |||
1110 | public function hasSubClass($name) |
||
1111 | { |
||
1112 | return isset($this->subClasses[$name]); |
||
1113 | } |
||
1114 | |||
1115 | public function hasActiveSubClass() |
||
1116 | { |
||
1117 | if (\count($this->subClasses) > 0 && $this->request) { |
||
1118 | return null !== $this->getRequest()->query->get('subclass'); |
||
1119 | } |
||
1120 | |||
1121 | return false; |
||
1122 | } |
||
1123 | |||
1124 | public function getActiveSubClass() |
||
1125 | { |
||
1126 | if (!$this->hasActiveSubClass()) { |
||
1127 | @trigger_error(sprintf( |
||
1128 | 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '. |
||
1129 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1130 | __METHOD__, |
||
1131 | __CLASS__ |
||
1132 | ), E_USER_DEPRECATED); |
||
1133 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1134 | // throw new \LogicException(sprintf( |
||
1135 | // 'Admin "%s" has no active subclass.', |
||
1136 | // static::class |
||
1137 | // )); |
||
1138 | |||
1139 | return null; |
||
1140 | } |
||
1141 | |||
1142 | return $this->getSubClass($this->getActiveSubclassCode()); |
||
1143 | } |
||
1144 | |||
1145 | public function getActiveSubclassCode() |
||
1146 | { |
||
1147 | if (!$this->hasActiveSubClass()) { |
||
1148 | @trigger_error(sprintf( |
||
1149 | 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '. |
||
1150 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1151 | __METHOD__, |
||
1152 | __CLASS__ |
||
1153 | ), E_USER_DEPRECATED); |
||
1154 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1155 | // throw new \LogicException(sprintf( |
||
1156 | // 'Admin "%s" has no active subclass.', |
||
1157 | // static::class |
||
1158 | // )); |
||
1159 | |||
1160 | return null; |
||
1161 | } |
||
1162 | |||
1163 | $subClass = $this->getRequest()->query->get('subclass'); |
||
1164 | |||
1165 | if (!$this->hasSubClass($subClass)) { |
||
1166 | @trigger_error(sprintf( |
||
1167 | 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '. |
||
1168 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1169 | __METHOD__, |
||
1170 | __CLASS__ |
||
1171 | ), E_USER_DEPRECATED); |
||
1172 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1173 | // throw new \LogicException(sprintf( |
||
1174 | // 'Admin "%s" has no active subclass.', |
||
1175 | // static::class |
||
1176 | // )); |
||
1177 | |||
1178 | return null; |
||
1179 | } |
||
1180 | |||
1181 | return $subClass; |
||
1182 | } |
||
1183 | |||
1184 | public function getBatchActions() |
||
1185 | { |
||
1186 | $actions = []; |
||
1187 | |||
1188 | if ($this->hasRoute('delete') && $this->hasAccess('delete')) { |
||
1189 | $actions['delete'] = [ |
||
1190 | 'label' => 'action_delete', |
||
1191 | 'translation_domain' => 'SonataAdminBundle', |
||
1192 | 'ask_confirmation' => true, // by default always true |
||
1193 | ]; |
||
1194 | } |
||
1195 | |||
1196 | $actions = $this->configureBatchActions($actions); |
||
1197 | |||
1198 | foreach ($this->getExtensions() as $extension) { |
||
1199 | // NEXT_MAJOR: remove method check |
||
1200 | if (method_exists($extension, 'configureBatchActions')) { |
||
1201 | $actions = $extension->configureBatchActions($this, $actions); |
||
1202 | } |
||
1203 | } |
||
1204 | |||
1205 | foreach ($actions as $name => &$action) { |
||
1206 | if (!\array_key_exists('label', $action)) { |
||
1207 | $action['label'] = $this->getTranslationLabel($name, 'batch', 'label'); |
||
1208 | } |
||
1209 | |||
1210 | if (!\array_key_exists('translation_domain', $action)) { |
||
1211 | $action['translation_domain'] = $this->getTranslationDomain(); |
||
1212 | } |
||
1213 | } |
||
1214 | |||
1215 | return $actions; |
||
1216 | } |
||
1217 | |||
1218 | public function getRoutes() |
||
1219 | { |
||
1220 | $this->buildRoutes(); |
||
1221 | |||
1222 | return $this->routes; |
||
1223 | } |
||
1224 | |||
1225 | public function getRouterIdParameter() |
||
1226 | { |
||
1227 | return '{'.$this->getIdParameter().'}'; |
||
1228 | } |
||
1229 | |||
1230 | public function getIdParameter() |
||
1231 | { |
||
1232 | $parameter = 'id'; |
||
1233 | |||
1234 | for ($i = 0; $i < $this->getChildDepth(); ++$i) { |
||
1235 | $parameter = 'child'.ucfirst($parameter); |
||
1236 | } |
||
1237 | |||
1238 | return $parameter; |
||
1239 | } |
||
1240 | |||
1241 | public function hasRoute($name) |
||
1242 | { |
||
1243 | if (!$this->routeGenerator) { |
||
1244 | throw new \RuntimeException('RouteGenerator cannot be null'); |
||
1245 | } |
||
1246 | |||
1247 | return $this->routeGenerator->hasAdminRoute($this, $name); |
||
1248 | } |
||
1249 | |||
1250 | /** |
||
1251 | * @param string $name |
||
1252 | * @param string|null $adminCode |
||
1253 | * |
||
1254 | * @return bool |
||
1255 | */ |
||
1256 | public function isCurrentRoute($name, $adminCode = null) |
||
1257 | { |
||
1258 | if (!$this->hasRequest()) { |
||
1259 | return false; |
||
1260 | } |
||
1261 | |||
1262 | $request = $this->getRequest(); |
||
1263 | $route = $request->get('_route'); |
||
1264 | |||
1265 | if ($adminCode) { |
||
1266 | $admin = $this->getConfigurationPool()->getAdminByAdminCode($adminCode); |
||
1267 | } else { |
||
1268 | $admin = $this; |
||
1269 | } |
||
1270 | |||
1271 | if (!$admin) { |
||
1272 | return false; |
||
1273 | } |
||
1274 | |||
1275 | return ($admin->getBaseRouteName().'_'.$name) === $route; |
||
1276 | } |
||
1277 | |||
1278 | public function generateObjectUrl($name, $object, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1279 | { |
||
1280 | $parameters['id'] = $this->getUrlSafeIdentifier($object); |
||
1281 | |||
1282 | return $this->generateUrl($name, $parameters, $referenceType); |
||
1283 | } |
||
1284 | |||
1285 | public function generateUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1286 | { |
||
1287 | return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); |
||
1288 | } |
||
1289 | |||
1290 | public function generateMenuUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1291 | { |
||
1292 | return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); |
||
1293 | } |
||
1294 | |||
1295 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry) |
||
1296 | { |
||
1297 | $this->templateRegistry = $templateRegistry; |
||
1298 | } |
||
1299 | |||
1300 | /** |
||
1301 | * @param array<string, string> $templates |
||
1302 | */ |
||
1303 | public function setTemplates(array $templates) |
||
1304 | { |
||
1305 | // NEXT_MAJOR: Remove this line |
||
1306 | $this->templates = $templates; |
||
1307 | |||
1308 | $this->getTemplateRegistry()->setTemplates($templates); |
||
1309 | } |
||
1310 | |||
1311 | /** |
||
1312 | * @param string $name |
||
1313 | * @param string $template |
||
1314 | */ |
||
1315 | public function setTemplate($name, $template) |
||
1316 | { |
||
1317 | // NEXT_MAJOR: Remove this line |
||
1318 | $this->templates[$name] = $template; |
||
1319 | |||
1320 | $this->getTemplateRegistry()->setTemplate($name, $template); |
||
1321 | } |
||
1322 | |||
1323 | /** |
||
1324 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
1325 | * |
||
1326 | * @return array<string, string> |
||
1327 | */ |
||
1328 | public function getTemplates() |
||
1329 | { |
||
1330 | return $this->getTemplateRegistry()->getTemplates(); |
||
1331 | } |
||
1332 | |||
1333 | /** |
||
1334 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
1335 | * |
||
1336 | * @param string $name |
||
1337 | * |
||
1338 | * @return string|null |
||
1339 | */ |
||
1340 | public function getTemplate($name) |
||
1341 | { |
||
1342 | return $this->getTemplateRegistry()->getTemplate($name); |
||
1343 | } |
||
1344 | |||
1345 | public function getNewInstance() |
||
1346 | { |
||
1347 | $object = $this->getModelManager()->getModelInstance($this->getClass()); |
||
1348 | foreach ($this->getExtensions() as $extension) { |
||
1349 | $extension->alterNewInstance($this, $object); |
||
1350 | } |
||
1351 | |||
1352 | return $object; |
||
1353 | } |
||
1354 | |||
1355 | public function getFormBuilder() |
||
1356 | { |
||
1357 | $this->formOptions['data_class'] = $this->getClass(); |
||
1358 | |||
1359 | $formBuilder = $this->getFormContractor()->getFormBuilder( |
||
1360 | $this->getUniqid(), |
||
1361 | $this->formOptions |
||
1362 | ); |
||
1363 | |||
1364 | $this->defineFormBuilder($formBuilder); |
||
1365 | |||
1366 | return $formBuilder; |
||
1367 | } |
||
1368 | |||
1369 | /** |
||
1370 | * This method is being called by the main admin class and the child class, |
||
1371 | * the getFormBuilder is only call by the main admin class. |
||
1372 | */ |
||
1373 | public function defineFormBuilder(FormBuilderInterface $formBuilder) |
||
1374 | { |
||
1375 | if (!$this->hasSubject()) { |
||
1376 | @trigger_error(sprintf( |
||
1377 | 'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.65 and will throw an exception in 4.0. '. |
||
1378 | 'Use %s::setSubject() to set the subject.', |
||
1379 | __METHOD__, |
||
1380 | __CLASS__ |
||
1381 | ), E_USER_DEPRECATED); |
||
1382 | // NEXT_MAJOR : remove the previous `trigger_error()` call and uncomment the following exception |
||
1383 | // throw new \LogicException(sprintf( |
||
1384 | // 'Admin "%s" has no subject.', |
||
1385 | // static::class |
||
1386 | // )); |
||
1387 | } |
||
1388 | |||
1389 | $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this); |
||
1390 | |||
1391 | $this->configureFormFields($mapper); |
||
1392 | |||
1393 | foreach ($this->getExtensions() as $extension) { |
||
1394 | $extension->configureFormFields($mapper); |
||
1395 | } |
||
1396 | |||
1397 | $this->attachInlineValidator(); |
||
1398 | } |
||
1399 | |||
1400 | public function attachAdminClass(FieldDescriptionInterface $fieldDescription) |
||
1401 | { |
||
1402 | $pool = $this->getConfigurationPool(); |
||
1403 | |||
1404 | $adminCode = $fieldDescription->getOption('admin_code'); |
||
1405 | |||
1406 | if (null !== $adminCode) { |
||
1407 | if (!$pool->hasAdminByAdminCode($adminCode)) { |
||
1408 | return; |
||
1409 | } |
||
1410 | |||
1411 | $admin = $pool->getAdminByAdminCode($adminCode); |
||
1412 | } else { |
||
1413 | if (!$pool->hasAdminByClass($fieldDescription->getTargetEntity())) { |
||
1414 | return; |
||
1415 | } |
||
1416 | |||
1417 | $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity()); |
||
1418 | } |
||
1419 | |||
1420 | if ($this->hasRequest()) { |
||
1421 | $admin->setRequest($this->getRequest()); |
||
1422 | } |
||
1423 | |||
1424 | $fieldDescription->setAssociationAdmin($admin); |
||
1425 | } |
||
1426 | |||
1427 | public function getObject($id) |
||
1428 | { |
||
1429 | $object = $this->getModelManager()->find($this->getClass(), $id); |
||
1430 | foreach ($this->getExtensions() as $extension) { |
||
1431 | $extension->alterObject($this, $object); |
||
1432 | } |
||
1433 | |||
1434 | return $object; |
||
1435 | } |
||
1436 | |||
1437 | public function getForm() |
||
1438 | { |
||
1439 | $this->buildForm(); |
||
1440 | |||
1441 | return $this->form; |
||
1442 | } |
||
1443 | |||
1444 | public function getList() |
||
1445 | { |
||
1446 | $this->buildList(); |
||
1447 | |||
1448 | return $this->list; |
||
1449 | } |
||
1450 | |||
1451 | /** |
||
1452 | * @final since sonata-project/admin-bundle 3.63.0 |
||
1453 | */ |
||
1454 | public function createQuery($context = 'list') |
||
1455 | { |
||
1456 | if (\func_num_args() > 0) { |
||
1457 | @trigger_error( |
||
1458 | 'The $context argument of '.__METHOD__.' is deprecated since 3.3, to be removed in 4.0.', |
||
1459 | E_USER_DEPRECATED |
||
1460 | ); |
||
1461 | } |
||
1462 | |||
1463 | $query = $this->getModelManager()->createQuery($this->getClass()); |
||
1464 | |||
1465 | $query = $this->configureQuery($query); |
||
1466 | foreach ($this->extensions as $extension) { |
||
1467 | $extension->configureQuery($this, $query, $context); |
||
1468 | } |
||
1469 | |||
1470 | return $query; |
||
1471 | } |
||
1472 | |||
1473 | public function getDatagrid() |
||
1474 | { |
||
1475 | $this->buildDatagrid(); |
||
1476 | |||
1477 | return $this->datagrid; |
||
1478 | } |
||
1479 | |||
1480 | public function buildTabMenu($action, ?AdminInterface $childAdmin = null) |
||
1481 | { |
||
1482 | if ($this->loaded['tab_menu']) { |
||
1483 | return $this->menu; |
||
1484 | } |
||
1485 | |||
1486 | $this->loaded['tab_menu'] = true; |
||
1487 | |||
1488 | $menu = $this->menuFactory->createItem('root'); |
||
1489 | $menu->setChildrenAttribute('class', 'nav navbar-nav'); |
||
1490 | $menu->setExtra('translation_domain', $this->translationDomain); |
||
1491 | |||
1492 | // Prevents BC break with KnpMenuBundle v1.x |
||
1493 | if (method_exists($menu, 'setCurrentUri')) { |
||
1494 | $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo()); |
||
1495 | } |
||
1496 | |||
1497 | $this->configureTabMenu($menu, $action, $childAdmin); |
||
1498 | |||
1499 | foreach ($this->getExtensions() as $extension) { |
||
1500 | $extension->configureTabMenu($this, $menu, $action, $childAdmin); |
||
1501 | } |
||
1502 | |||
1503 | $this->menu = $menu; |
||
1504 | |||
1505 | return $this->menu; |
||
1506 | } |
||
1507 | |||
1508 | public function buildSideMenu($action, ?AdminInterface $childAdmin = null) |
||
1509 | { |
||
1510 | return $this->buildTabMenu($action, $childAdmin); |
||
1511 | } |
||
1512 | |||
1513 | /** |
||
1514 | * @param string $action |
||
1515 | * |
||
1516 | * @return ItemInterface |
||
1517 | */ |
||
1518 | public function getSideMenu($action, ?AdminInterface $childAdmin = null) |
||
1519 | { |
||
1520 | if ($this->isChild()) { |
||
1521 | return $this->getParent()->getSideMenu($action, $this); |
||
1522 | } |
||
1523 | |||
1524 | $this->buildSideMenu($action, $childAdmin); |
||
1525 | |||
1526 | return $this->menu; |
||
1527 | } |
||
1528 | |||
1529 | /** |
||
1530 | * Returns the root code. |
||
1531 | * |
||
1532 | * @return string the root code |
||
1533 | */ |
||
1534 | public function getRootCode() |
||
1535 | { |
||
1536 | return $this->getRoot()->getCode(); |
||
1537 | } |
||
1538 | |||
1539 | /** |
||
1540 | * Returns the master admin. |
||
1541 | * |
||
1542 | * @return AbstractAdmin the root admin class |
||
1543 | */ |
||
1544 | public function getRoot() |
||
1545 | { |
||
1546 | if (!$this->hasParentFieldDescription()) { |
||
1547 | return $this; |
||
1548 | } |
||
1549 | |||
1550 | return $this->getParentFieldDescription()->getAdmin()->getRoot(); |
||
1551 | } |
||
1552 | |||
1553 | public function setBaseControllerName($baseControllerName) |
||
1557 | |||
1558 | public function getBaseControllerName() |
||
1562 | |||
1563 | /** |
||
1564 | * @param string $label |
||
1565 | */ |
||
1566 | public function setLabel($label) |
||
1570 | |||
1571 | public function getLabel() |
||
1575 | |||
1576 | /** |
||
1577 | * @param bool $persist |
||
1578 | * |
||
1579 | * NEXT_MAJOR: remove this method |
||
1580 | * |
||
1581 | * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. |
||
1582 | */ |
||
1583 | public function setPersistFilters($persist) |
||
1592 | |||
1593 | public function setFilterPersister(?FilterPersisterInterface $filterPersister = null) |
||
1594 | { |
||
1595 | $this->filterPersister = $filterPersister; |
||
1596 | // NEXT_MAJOR remove the deprecated property will be removed. Needed for persisted filter condition. |
||
1597 | $this->persistFilters = true; |
||
1598 | } |
||
1599 | |||
1600 | /** |
||
1601 | * NEXT_MAJOR: Remove this method. |
||
1602 | * |
||
1603 | * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0. |
||
1604 | * |
||
1605 | * @param int $maxPerPage |
||
1606 | */ |
||
1607 | public function setMaxPerPage($maxPerPage) |
||
1608 | { |
||
1609 | @trigger_error(sprintf( |
||
1610 | 'The method %s is deprecated since sonata-project/admin-bundle 3.67 and will be removed in 4.0.', |
||
1611 | __METHOD__ |
||
1612 | ), E_USER_DEPRECATED); |
||
1613 | |||
1614 | $this->maxPerPage = $maxPerPage; |
||
1615 | } |
||
1616 | |||
1617 | /** |
||
1618 | * @return int |
||
1619 | */ |
||
1620 | public function getMaxPerPage() |
||
1621 | { |
||
1622 | // NEXT_MAJOR: Remove this line and uncomment the following. |
||
1623 | return $this->maxPerPage; |
||
1624 | // $sortValues = $this->getModelManager()->getDefaultSortValues($this->class); |
||
1625 | |||
1626 | // return $sortValues['_per_page'] ?? 25; |
||
1627 | } |
||
1628 | |||
1629 | /** |
||
1630 | * @param int $maxPageLinks |
||
1631 | */ |
||
1632 | public function setMaxPageLinks($maxPageLinks) |
||
1633 | { |
||
1634 | $this->maxPageLinks = $maxPageLinks; |
||
1635 | } |
||
1636 | |||
1637 | /** |
||
1638 | * @return int |
||
1639 | */ |
||
1640 | public function getMaxPageLinks() |
||
1641 | { |
||
1642 | return $this->maxPageLinks; |
||
1643 | } |
||
1644 | |||
1645 | public function getFormGroups() |
||
1646 | { |
||
1647 | if (!\is_array($this->formGroups) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { |
||
1648 | @trigger_error(sprintf( |
||
1649 | 'Returning other type than array in method %s() is deprecated since sonata-project/admin-bundle 3.65. It will return only array in version 4.0.', |
||
1650 | __METHOD__ |
||
1651 | ), E_USER_DEPRECATED); |
||
1652 | } |
||
1653 | |||
1654 | return $this->formGroups; |
||
1655 | } |
||
1656 | |||
1657 | public function setFormGroups(array $formGroups) |
||
1658 | { |
||
1659 | $this->formGroups = $formGroups; |
||
1661 | |||
1662 | public function removeFieldFromFormGroup($key) |
||
1672 | |||
1673 | /** |
||
1674 | * @param string $group |
||
1675 | */ |
||
1676 | public function reorderFormGroup($group, array $keys) |
||
1683 | |||
1684 | public function getFormTabs() |
||
1695 | |||
1696 | public function setFormTabs(array $formTabs) |
||
1700 | |||
1701 | public function getShowTabs() |
||
1712 | |||
1713 | public function setShowTabs(array $showTabs) |
||
1717 | |||
1718 | public function getShowGroups() |
||
1729 | |||
1730 | public function setShowGroups(array $showGroups) |
||
1734 | |||
1735 | public function reorderShowGroup($group, array $keys) |
||
1742 | |||
1743 | public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription) |
||
1747 | |||
1748 | public function getParentFieldDescription() |
||
1768 | |||
1769 | public function hasParentFieldDescription() |
||
1773 | |||
1774 | public function setSubject($subject) |
||
1791 | |||
1792 | public function getSubject() |
||
1812 | |||
1813 | public function hasSubject() |
||
1825 | |||
1826 | public function getFormFieldDescriptions() |
||
1832 | |||
1833 | public function getFormFieldDescription($name) |
||
1856 | |||
1857 | /** |
||
1858 | * Returns true if the admin has a FieldDescription with the given $name. |
||
1859 | * |
||
1860 | * @param string $name |
||
1861 | * |
||
1862 | * @return bool |
||
1863 | */ |
||
1864 | public function hasFormFieldDescription($name) |
||
1870 | |||
1871 | public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1875 | |||
1876 | /** |
||
1877 | * remove a FieldDescription. |
||
1878 | * |
||
1879 | * @param string $name |
||
1880 | */ |
||
1881 | public function removeFormFieldDescription($name) |
||
1885 | |||
1886 | /** |
||
1887 | * build and return the collection of form FieldDescription. |
||
1888 | * |
||
1889 | * @return FieldDescriptionInterface[] collection of form FieldDescription |
||
1890 | */ |
||
1891 | public function getShowFieldDescriptions() |
||
1897 | |||
1898 | /** |
||
1899 | * Returns the form FieldDescription with the given $name. |
||
1900 | * |
||
1901 | * @param string $name |
||
1902 | * |
||
1903 | * @return FieldDescriptionInterface |
||
1904 | */ |
||
1905 | public function getShowFieldDescription($name) |
||
1928 | |||
1929 | public function hasShowFieldDescription($name) |
||
1935 | |||
1936 | public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1940 | |||
1941 | public function removeShowFieldDescription($name) |
||
1945 | |||
1946 | public function getListFieldDescriptions() |
||
1952 | |||
1953 | public function getListFieldDescription($name) |
||
1977 | |||
1978 | public function hasListFieldDescription($name) |
||
1984 | |||
1985 | public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1989 | |||
1990 | public function removeListFieldDescription($name) |
||
1994 | |||
1995 | public function getFilterFieldDescription($name) |
||
2018 | |||
2019 | public function hasFilterFieldDescription($name) |
||
2025 | |||
2026 | public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
2030 | |||
2031 | public function removeFilterFieldDescription($name) |
||
2035 | |||
2036 | public function getFilterFieldDescriptions() |
||
2042 | |||
2043 | public function addChild(AdminInterface $child) |
||
2076 | |||
2077 | public function hasChild($code) |
||
2081 | |||
2082 | public function getChildren() |
||
2086 | |||
2087 | public function getChild($code) |
||
2108 | |||
2109 | public function setParent(AdminInterface $parent) |
||
2113 | |||
2114 | public function getParent() |
||
2134 | |||
2135 | final public function getRootAncestor() |
||
2145 | |||
2146 | final public function getChildDepth() |
||
2158 | |||
2159 | final public function getCurrentLeafChildAdmin() |
||
2173 | |||
2174 | public function isChild() |
||
2178 | |||
2179 | /** |
||
2180 | * Returns true if the admin has children, false otherwise. |
||
2181 | * |
||
2182 | * @return bool if the admin has children |
||
2183 | */ |
||
2184 | public function hasChildren() |
||
2188 | |||
2189 | public function setUniqid($uniqid) |
||
2193 | |||
2194 | public function getUniqid() |
||
2202 | |||
2203 | /** |
||
2204 | * Returns the classname label. |
||
2205 | * |
||
2206 | * @return string the classname label |
||
2207 | */ |
||
2208 | public function getClassnameLabel() |
||
2212 | |||
2213 | public function getPersistentParameters() |
||
2229 | |||
2230 | /** |
||
2231 | * @param string $name |
||
2232 | * |
||
2233 | * @return mixed|null |
||
2234 | */ |
||
2235 | public function getPersistentParameter($name) |
||
2241 | |||
2242 | public function getBreadcrumbs($action) |
||
2252 | |||
2253 | /** |
||
2254 | * Generates the breadcrumbs array. |
||
2255 | * |
||
2256 | * Note: the method will be called by the top admin instance (parent => child) |
||
2257 | * |
||
2258 | * @param string $action |
||
2259 | * |
||
2260 | * @return array |
||
2261 | */ |
||
2262 | public function buildBreadcrumbs($action, ?ItemInterface $menu = null) |
||
2276 | |||
2277 | /** |
||
2278 | * NEXT_MAJOR : remove this method. |
||
2279 | * |
||
2280 | * @return BreadcrumbsBuilderInterface |
||
2281 | */ |
||
2282 | final public function getBreadcrumbsBuilder() |
||
2297 | |||
2298 | /** |
||
2299 | * NEXT_MAJOR : remove this method. |
||
2300 | * |
||
2301 | * @return AbstractAdmin |
||
2302 | */ |
||
2303 | final public function setBreadcrumbsBuilder(BreadcrumbsBuilderInterface $value) |
||
2314 | |||
2315 | public function setCurrentChild($currentChild) |
||
2319 | |||
2320 | /** |
||
2321 | * NEXT_MAJOR: Remove this method. |
||
2322 | * |
||
2323 | * @deprecated since sonata-project/admin-bundle 3.65, to be removed in 4.0 |
||
2324 | */ |
||
2325 | public function getCurrentChild() |
||
2338 | |||
2339 | public function isCurrentChild(): bool |
||
2343 | |||
2344 | /** |
||
2345 | * Returns the current child admin instance. |
||
2346 | * |
||
2347 | * @return AdminInterface|null the current child admin instance |
||
2348 | */ |
||
2349 | public function getCurrentChildAdmin() |
||
2359 | |||
2360 | public function trans($id, array $parameters = [], $domain = null, $locale = null) |
||
2371 | |||
2372 | /** |
||
2373 | * Translate a message id. |
||
2374 | * |
||
2375 | * NEXT_MAJOR: remove this method |
||
2376 | * |
||
2377 | * @param string $id |
||
2378 | * @param int $count |
||
2379 | * @param string|null $domain |
||
2380 | * @param string|null $locale |
||
2381 | * |
||
2382 | * @return string the translated string |
||
2383 | * |
||
2384 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2385 | */ |
||
2386 | public function transChoice($id, $count, array $parameters = [], $domain = null, $locale = null) |
||
2397 | |||
2398 | public function setTranslationDomain($translationDomain) |
||
2402 | |||
2403 | public function getTranslationDomain() |
||
2407 | |||
2408 | /** |
||
2409 | * {@inheritdoc} |
||
2410 | * |
||
2411 | * NEXT_MAJOR: remove this method |
||
2412 | * |
||
2413 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2414 | */ |
||
2415 | public function setTranslator(TranslatorInterface $translator) |
||
2427 | |||
2428 | /** |
||
2429 | * {@inheritdoc} |
||
2430 | * |
||
2431 | * NEXT_MAJOR: remove this method |
||
2432 | * |
||
2433 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2434 | */ |
||
2435 | public function getTranslator() |
||
2444 | |||
2445 | public function getTranslationLabel($label, $context = '', $type = '') |
||
2449 | |||
2450 | public function setRequest(Request $request) |
||
2458 | |||
2459 | public function getRequest() |
||
2468 | |||
2469 | public function hasRequest() |
||
2473 | |||
2474 | public function setFormContractor(FormContractorInterface $formBuilder) |
||
2478 | |||
2479 | /** |
||
2480 | * @return FormContractorInterface |
||
2481 | */ |
||
2482 | public function getFormContractor() |
||
2486 | |||
2487 | public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) |
||
2491 | |||
2492 | public function getDatagridBuilder() |
||
2496 | |||
2497 | public function setListBuilder(ListBuilderInterface $listBuilder) |
||
2501 | |||
2502 | public function getListBuilder() |
||
2506 | |||
2507 | public function setShowBuilder(ShowBuilderInterface $showBuilder) |
||
2511 | |||
2512 | /** |
||
2513 | * @return ShowBuilderInterface |
||
2514 | */ |
||
2515 | public function getShowBuilder() |
||
2519 | |||
2520 | public function setConfigurationPool(Pool $configurationPool) |
||
2524 | |||
2525 | /** |
||
2526 | * @return Pool |
||
2527 | */ |
||
2528 | public function getConfigurationPool() |
||
2532 | |||
2533 | public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) |
||
2537 | |||
2538 | /** |
||
2539 | * @return RouteGeneratorInterface |
||
2540 | */ |
||
2541 | public function getRouteGenerator() |
||
2545 | |||
2546 | public function getCode() |
||
2550 | |||
2551 | /** |
||
2552 | * NEXT_MAJOR: Remove this function. |
||
2553 | * |
||
2554 | * @deprecated This method is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0 |
||
2555 | * |
||
2556 | * @param string $baseCodeRoute |
||
2557 | */ |
||
2558 | public function setBaseCodeRoute($baseCodeRoute) |
||
2567 | |||
2568 | public function getBaseCodeRoute() |
||
2590 | |||
2591 | public function getModelManager() |
||
2595 | |||
2596 | public function setModelManager(ModelManagerInterface $modelManager) |
||
2600 | |||
2601 | public function getManagerType() |
||
2605 | |||
2606 | /** |
||
2607 | * @param string $type |
||
2608 | */ |
||
2609 | public function setManagerType($type) |
||
2613 | |||
2614 | public function getObjectIdentifier() |
||
2618 | |||
2619 | /** |
||
2620 | * Set the roles and permissions per role. |
||
2621 | */ |
||
2622 | public function setSecurityInformation(array $information) |
||
2626 | |||
2627 | public function getSecurityInformation() |
||
2631 | |||
2632 | /** |
||
2633 | * Return the list of permissions the user should have in order to display the admin. |
||
2634 | * |
||
2635 | * @param string $context |
||
2636 | * |
||
2637 | * @return array |
||
2638 | */ |
||
2639 | public function getPermissionsShow($context) |
||
2648 | |||
2649 | public function showIn($context) |
||
2658 | |||
2659 | public function createObjectSecurity($object) |
||
2663 | |||
2664 | public function setSecurityHandler(SecurityHandlerInterface $securityHandler) |
||
2668 | |||
2669 | public function getSecurityHandler() |
||
2673 | |||
2674 | public function isGranted($name, $object = null) |
||
2685 | |||
2686 | public function getUrlSafeIdentifier($model) |
||
2690 | |||
2691 | public function getNormalizedIdentifier($model) |
||
2695 | |||
2696 | public function id($model) |
||
2700 | |||
2701 | public function setValidator($validator) |
||
2712 | |||
2713 | public function getValidator() |
||
2717 | |||
2718 | public function getShow() |
||
2724 | |||
2725 | public function setFormTheme(array $formTheme) |
||
2729 | |||
2730 | public function getFormTheme() |
||
2734 | |||
2735 | public function setFilterTheme(array $filterTheme) |
||
2739 | |||
2740 | public function getFilterTheme() |
||
2744 | |||
2745 | public function addExtension(AdminExtensionInterface $extension) |
||
2749 | |||
2750 | public function getExtensions() |
||
2754 | |||
2755 | public function setMenuFactory(FactoryInterface $menuFactory) |
||
2759 | |||
2760 | public function getMenuFactory() |
||
2764 | |||
2765 | public function setRouteBuilder(RouteBuilderInterface $routeBuilder) |
||
2769 | |||
2770 | public function getRouteBuilder() |
||
2774 | |||
2775 | public function toString($object) |
||
2787 | |||
2788 | public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy) |
||
2792 | |||
2793 | public function getLabelTranslatorStrategy() |
||
2797 | |||
2798 | public function supportsPreviewMode() |
||
2802 | |||
2803 | /** |
||
2804 | * NEXT_MAJOR: Remove this. |
||
2805 | * |
||
2806 | * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0. |
||
2807 | * |
||
2808 | * Set custom per page options. |
||
2809 | */ |
||
2810 | public function setPerPageOptions(array $options) |
||
2819 | |||
2820 | /** |
||
2821 | * Returns predefined per page options. |
||
2822 | * |
||
2823 | * @return array |
||
2824 | */ |
||
2825 | public function getPerPageOptions() |
||
2837 | |||
2838 | /** |
||
2839 | * Set pager type. |
||
2840 | * |
||
2841 | * @param string $pagerType |
||
2842 | */ |
||
2843 | public function setPagerType($pagerType) |
||
2847 | |||
2848 | /** |
||
2849 | * Get pager type. |
||
2850 | * |
||
2851 | * @return string |
||
2852 | */ |
||
2853 | public function getPagerType() |
||
2857 | |||
2858 | /** |
||
2859 | * Returns true if the per page value is allowed, false otherwise. |
||
2860 | * |
||
2861 | * @param int $perPage |
||
2862 | * |
||
2863 | * @return bool |
||
2864 | */ |
||
2865 | public function determinedPerPageValue($perPage) |
||
2869 | |||
2870 | public function isAclEnabled() |
||
2874 | |||
2875 | public function getObjectMetadata($object) |
||
2879 | |||
2880 | public function getListModes() |
||
2884 | |||
2885 | public function setListMode($mode) |
||
2893 | |||
2894 | public function getListMode() |
||
2902 | |||
2903 | public function getAccessMapping() |
||
2907 | |||
2908 | public function checkAccess($action, $object = null) |
||
2930 | |||
2931 | /** |
||
2932 | * Hook to handle access authorization, without throw Exception. |
||
2933 | * |
||
2934 | * @param string $action |
||
2935 | * @param object $object |
||
2936 | * |
||
2937 | * @return bool |
||
2938 | */ |
||
2939 | public function hasAccess($action, $object = null) |
||
2959 | |||
2960 | /** |
||
2961 | * @param string $action |
||
2962 | * @param object|null $object |
||
2963 | * |
||
2964 | * @return array |
||
2965 | */ |
||
2966 | public function configureActionButtons($action, $object = null) |
||
3040 | |||
3041 | /** |
||
3042 | * @param string $action |
||
3043 | * @param object $object |
||
3044 | * |
||
3045 | * @return array |
||
3046 | */ |
||
3047 | public function getActionButtons($action, $object = null) |
||
3060 | |||
3061 | /** |
||
3062 | * Get the list of actions that can be accessed directly from the dashboard. |
||
3063 | * |
||
3064 | * @return array |
||
3065 | */ |
||
3066 | public function getDashboardActions() |
||
3093 | |||
3094 | /** |
||
3095 | * Setting to true will enable mosaic button for the admin screen. |
||
3096 | * Setting to false will hide mosaic button for the admin screen. |
||
3097 | * |
||
3098 | * @param bool $isShown |
||
3099 | */ |
||
3100 | final public function showMosaicButton($isShown) |
||
3108 | |||
3109 | /** |
||
3110 | * @param object $object |
||
3111 | */ |
||
3112 | final public function getSearchResultLink($object) |
||
3122 | |||
3123 | /** |
||
3124 | * Checks if a filter type is set to a default value. |
||
3125 | * |
||
3126 | * @param string $name |
||
3127 | * |
||
3128 | * @return bool |
||
3129 | */ |
||
3130 | final public function isDefaultFilter($name) |
||
3141 | |||
3142 | /** |
||
3143 | * Check object existence and access, without throw Exception. |
||
3144 | * |
||
3145 | * @param string $action |
||
3146 | * @param object $object |
||
3147 | * |
||
3148 | * @return bool |
||
3149 | */ |
||
3150 | public function canAccessObject($action, $object) |
||
3154 | |||
3155 | protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
||
3159 | |||
3160 | /** |
||
3161 | * @return MutableTemplateRegistryInterface |
||
3162 | */ |
||
3163 | final protected function getTemplateRegistry() |
||
3167 | |||
3168 | /** |
||
3169 | * Returns a list of default sort values. |
||
3170 | * |
||
3171 | * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string} |
||
3172 | */ |
||
3173 | final protected function getDefaultSortValues(): array |
||
3188 | |||
3189 | /** |
||
3190 | * Returns a list of default filters. |
||
3191 | * |
||
3192 | * @return array |
||
3193 | */ |
||
3194 | final protected function getDefaultFilterValues() |
||
3209 | |||
3210 | protected function configureFormFields(FormMapper $form) |
||
3213 | |||
3214 | protected function configureListFields(ListMapper $list) |
||
3217 | |||
3218 | protected function configureDatagridFilters(DatagridMapper $filter) |
||
3221 | |||
3222 | protected function configureShowFields(ShowMapper $show) |
||
3225 | |||
3226 | protected function configureRoutes(RouteCollection $collection) |
||
3229 | |||
3230 | /** |
||
3231 | * Allows you to customize batch actions. |
||
3232 | * |
||
3233 | * @param array $actions List of actions |
||
3234 | * |
||
3235 | * @return array |
||
3236 | */ |
||
3237 | protected function configureBatchActions($actions) |
||
3241 | |||
3242 | /** |
||
3243 | * NEXT_MAJOR: remove this method. |
||
3244 | * |
||
3245 | * @deprecated Use configureTabMenu instead |
||
3246 | */ |
||
3247 | protected function configureSideMenu(ItemInterface $menu, $action, ?AdminInterface $childAdmin = null) |
||
3250 | |||
3251 | /** |
||
3252 | * Configures the tab menu in your admin. |
||
3253 | * |
||
3254 | * @param string $action |
||
3255 | */ |
||
3256 | protected function configureTabMenu(ItemInterface $menu, $action, ?AdminInterface $childAdmin = null) |
||
3262 | |||
3263 | /** |
||
3264 | * build the view FieldDescription array. |
||
3265 | */ |
||
3266 | protected function buildShow() |
||
3283 | |||
3284 | /** |
||
3285 | * build the list FieldDescription array. |
||
3286 | */ |
||
3287 | protected function buildList() |
||
3344 | |||
3345 | /** |
||
3346 | * Build the form FieldDescription collection. |
||
3347 | */ |
||
3348 | protected function buildForm() |
||
3383 | |||
3384 | /** |
||
3385 | * Gets the subclass corresponding to the given name. |
||
3386 | * |
||
3387 | * @param string $name The name of the sub class |
||
3388 | * |
||
3389 | * @return string the subclass |
||
3390 | */ |
||
3391 | protected function getSubClass($name) |
||
3404 | |||
3405 | /** |
||
3406 | * Attach the inline validator to the model metadata, this must be done once per admin. |
||
3407 | */ |
||
3408 | protected function attachInlineValidator() |
||
3445 | |||
3446 | /** |
||
3447 | * NEXT_MAJOR: Remove this function. |
||
3448 | * |
||
3449 | * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0. |
||
3450 | * |
||
3451 | * Predefine per page options. |
||
3452 | */ |
||
3453 | protected function predefinePerPageOptions() |
||
3459 | |||
3460 | /** |
||
3461 | * Return list routes with permissions name. |
||
3462 | * |
||
3463 | * @return array<string, string> |
||
3464 | */ |
||
3465 | protected function getAccess() |
||
3490 | |||
3491 | /** |
||
3492 | * Configures a list of default filters. |
||
3493 | */ |
||
3494 | protected function configureDefaultFilterValues(array &$filterValues) |
||
3497 | |||
3498 | /** |
||
3499 | * Configures a list of default sort values. |
||
3500 | * |
||
3501 | * Example: |
||
3502 | * $sortValues['_sort_by'] = 'foo' |
||
3503 | * $sortValues['_sort_order'] = 'DESC' |
||
3504 | */ |
||
3505 | protected function configureDefaultSortValues(array &$sortValues) |
||
3508 | |||
3509 | /** |
||
3510 | * Build all the related urls to the current admin. |
||
3511 | */ |
||
3512 | private function buildRoutes(): void |
||
3535 | } |
||
3536 | |||
3538 |
If you suppress an error, we recommend checking for the error condition explicitly: