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 |
||
59 | abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface |
||
60 | { |
||
61 | public const CONTEXT_MENU = 'menu'; |
||
62 | public const CONTEXT_DASHBOARD = 'dashboard'; |
||
63 | |||
64 | public const CLASS_REGEX = |
||
65 | '@ |
||
66 | (?:([A-Za-z0-9]*)\\\)? # vendor name / app name |
||
67 | (Bundle\\\)? # optional bundle directory |
||
68 | ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix |
||
69 | ( |
||
70 | Entity|Document|Model|PHPCR|CouchDocument|Phpcr| |
||
71 | Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB |
||
72 | )\\\(.*)@x'; |
||
73 | |||
74 | public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; |
||
75 | |||
76 | /** |
||
77 | * The list FieldDescription constructed from the configureListField method. |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | protected $listFieldDescriptions = []; |
||
82 | |||
83 | /** |
||
84 | * The show FieldDescription constructed from the configureShowFields method. |
||
85 | * |
||
86 | * @var array |
||
87 | */ |
||
88 | protected $showFieldDescriptions = []; |
||
89 | |||
90 | /** |
||
91 | * The list FieldDescription constructed from the configureFormField method. |
||
92 | * |
||
93 | * @var array |
||
94 | */ |
||
95 | protected $formFieldDescriptions = []; |
||
96 | |||
97 | /** |
||
98 | * The filter FieldDescription constructed from the configureFilterField method. |
||
99 | * |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $filterFieldDescriptions = []; |
||
103 | |||
104 | /** |
||
105 | * NEXT_MAJOR: Remove this property. |
||
106 | * |
||
107 | * The number of result to display in the list. |
||
108 | * |
||
109 | * @deprecated since sonata-project/admin-bundle 3.x. |
||
110 | * |
||
111 | * @var int |
||
112 | */ |
||
113 | protected $maxPerPage = 32; |
||
114 | |||
115 | /** |
||
116 | * The maximum number of page numbers to display in the list. |
||
117 | * |
||
118 | * @var int |
||
119 | */ |
||
120 | protected $maxPageLinks = 25; |
||
121 | |||
122 | /** |
||
123 | * The base route name used to generate the routing information. |
||
124 | * |
||
125 | * @var string |
||
126 | */ |
||
127 | protected $baseRouteName; |
||
128 | |||
129 | /** |
||
130 | * The base route pattern used to generate the routing information. |
||
131 | * |
||
132 | * @var string |
||
133 | */ |
||
134 | protected $baseRoutePattern; |
||
135 | |||
136 | /** |
||
137 | * The base name controller used to generate the routing information. |
||
138 | * |
||
139 | * @var string |
||
140 | */ |
||
141 | protected $baseControllerName; |
||
142 | |||
143 | /** |
||
144 | * The label class name (used in the title/breadcrumb ...). |
||
145 | * |
||
146 | * @var string |
||
147 | */ |
||
148 | protected $classnameLabel; |
||
149 | |||
150 | /** |
||
151 | * The translation domain to be used to translate messages. |
||
152 | * |
||
153 | * @var string |
||
154 | */ |
||
155 | protected $translationDomain = 'messages'; |
||
156 | |||
157 | /** |
||
158 | * Options to set to the form (ie, validation_groups). |
||
159 | * |
||
160 | * @var array |
||
161 | */ |
||
162 | protected $formOptions = []; |
||
163 | |||
164 | /** |
||
165 | * NEXT_MAJOR: Remove this property. |
||
166 | * |
||
167 | * Default values to the datagrid. |
||
168 | * |
||
169 | * @deprecated since sonata-project/admin-bundle 3.x, use configureDefaultSortValues() instead. |
||
170 | * |
||
171 | * @var array |
||
172 | */ |
||
173 | protected $datagridValues = [ |
||
174 | '_page' => 1, |
||
175 | '_per_page' => 32, |
||
176 | ]; |
||
177 | |||
178 | /** |
||
179 | * NEXT_MAJOR: Remove this property. |
||
180 | * |
||
181 | * Predefined per page options. |
||
182 | * |
||
183 | * @deprecated since sonata-project/admin-bundle 3.x. |
||
184 | * |
||
185 | * @var array |
||
186 | */ |
||
187 | protected $perPageOptions = [16, 32, 64, 128, 256]; |
||
188 | |||
189 | /** |
||
190 | * Pager type. |
||
191 | * |
||
192 | * @var string |
||
193 | */ |
||
194 | protected $pagerType = Pager::TYPE_DEFAULT; |
||
195 | |||
196 | /** |
||
197 | * The code related to the admin. |
||
198 | * |
||
199 | * @var string |
||
200 | */ |
||
201 | protected $code; |
||
202 | |||
203 | /** |
||
204 | * The label. |
||
205 | * |
||
206 | * @var string |
||
207 | */ |
||
208 | protected $label; |
||
209 | |||
210 | /** |
||
211 | * Whether or not to persist the filters in the session. |
||
212 | * |
||
213 | * NEXT_MAJOR: remove this property |
||
214 | * |
||
215 | * @var bool |
||
216 | * |
||
217 | * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. |
||
218 | */ |
||
219 | protected $persistFilters = false; |
||
220 | |||
221 | /** |
||
222 | * Array of routes related to this admin. |
||
223 | * |
||
224 | * @var RouteCollection |
||
225 | */ |
||
226 | protected $routes; |
||
227 | |||
228 | /** |
||
229 | * The subject only set in edit/update/create mode. |
||
230 | * |
||
231 | * @var object|null |
||
232 | */ |
||
233 | protected $subject; |
||
234 | |||
235 | /** |
||
236 | * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}. |
||
237 | * |
||
238 | * @var array |
||
239 | */ |
||
240 | protected $children = []; |
||
241 | |||
242 | /** |
||
243 | * Reference the parent admin. |
||
244 | * |
||
245 | * @var AdminInterface|null |
||
246 | */ |
||
247 | protected $parent; |
||
248 | |||
249 | /** |
||
250 | * The base code route refer to the prefix used to generate the route name. |
||
251 | * |
||
252 | * NEXT_MAJOR: remove this attribute. |
||
253 | * |
||
254 | * @deprecated This attribute is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0 |
||
255 | * |
||
256 | * @var string |
||
257 | */ |
||
258 | protected $baseCodeRoute = ''; |
||
259 | |||
260 | /** |
||
261 | * NEXT_MAJOR: should be default array and private. |
||
262 | * |
||
263 | * @var string|array |
||
264 | */ |
||
265 | protected $parentAssociationMapping; |
||
266 | |||
267 | /** |
||
268 | * Reference the parent FieldDescription related to this admin |
||
269 | * only set for FieldDescription which is associated to an Sub Admin instance. |
||
270 | * |
||
271 | * @var FieldDescriptionInterface |
||
272 | */ |
||
273 | protected $parentFieldDescription; |
||
274 | |||
275 | /** |
||
276 | * If true then the current admin is part of the nested admin set (from the url). |
||
277 | * |
||
278 | * @var bool |
||
279 | */ |
||
280 | protected $currentChild = false; |
||
281 | |||
282 | /** |
||
283 | * The uniqid is used to avoid clashing with 2 admin related to the code |
||
284 | * ie: a Block linked to a Block. |
||
285 | * |
||
286 | * @var string |
||
287 | */ |
||
288 | protected $uniqid; |
||
289 | |||
290 | /** |
||
291 | * The Entity or Document manager. |
||
292 | * |
||
293 | * @var ModelManagerInterface |
||
294 | */ |
||
295 | protected $modelManager; |
||
296 | |||
297 | /** |
||
298 | * The current request object. |
||
299 | * |
||
300 | * @var Request|null |
||
301 | */ |
||
302 | protected $request; |
||
303 | |||
304 | /** |
||
305 | * The translator component. |
||
306 | * |
||
307 | * NEXT_MAJOR: remove this property |
||
308 | * |
||
309 | * @var \Symfony\Component\Translation\TranslatorInterface |
||
310 | * |
||
311 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
312 | */ |
||
313 | protected $translator; |
||
314 | |||
315 | /** |
||
316 | * The related form contractor. |
||
317 | * |
||
318 | * @var FormContractorInterface |
||
319 | */ |
||
320 | protected $formContractor; |
||
321 | |||
322 | /** |
||
323 | * The related list builder. |
||
324 | * |
||
325 | * @var ListBuilderInterface |
||
326 | */ |
||
327 | protected $listBuilder; |
||
328 | |||
329 | /** |
||
330 | * The related view builder. |
||
331 | * |
||
332 | * @var ShowBuilderInterface |
||
333 | */ |
||
334 | protected $showBuilder; |
||
335 | |||
336 | /** |
||
337 | * The related datagrid builder. |
||
338 | * |
||
339 | * @var DatagridBuilderInterface |
||
340 | */ |
||
341 | protected $datagridBuilder; |
||
342 | |||
343 | /** |
||
344 | * @var RouteBuilderInterface |
||
345 | */ |
||
346 | protected $routeBuilder; |
||
347 | |||
348 | /** |
||
349 | * The datagrid instance. |
||
350 | * |
||
351 | * @var DatagridInterface|null |
||
352 | */ |
||
353 | protected $datagrid; |
||
354 | |||
355 | /** |
||
356 | * The router instance. |
||
357 | * |
||
358 | * @var RouteGeneratorInterface|null |
||
359 | */ |
||
360 | protected $routeGenerator; |
||
361 | |||
362 | /** |
||
363 | * The generated breadcrumbs. |
||
364 | * |
||
365 | * NEXT_MAJOR : remove this property |
||
366 | * |
||
367 | * @var array |
||
368 | */ |
||
369 | protected $breadcrumbs = []; |
||
370 | |||
371 | /** |
||
372 | * @var SecurityHandlerInterface |
||
373 | */ |
||
374 | protected $securityHandler; |
||
375 | |||
376 | /** |
||
377 | * @var ValidatorInterface |
||
378 | */ |
||
379 | protected $validator; |
||
380 | |||
381 | /** |
||
382 | * The configuration pool. |
||
383 | * |
||
384 | * @var Pool |
||
385 | */ |
||
386 | protected $configurationPool; |
||
387 | |||
388 | /** |
||
389 | * @var ItemInterface |
||
390 | */ |
||
391 | protected $menu; |
||
392 | |||
393 | /** |
||
394 | * @var FactoryInterface |
||
395 | */ |
||
396 | protected $menuFactory; |
||
397 | |||
398 | /** |
||
399 | * @var array<string, bool> |
||
400 | */ |
||
401 | protected $loaded = [ |
||
402 | 'view_fields' => false, |
||
403 | 'view_groups' => false, |
||
404 | 'routes' => false, |
||
405 | 'tab_menu' => false, |
||
406 | ]; |
||
407 | |||
408 | /** |
||
409 | * @var string[] |
||
410 | */ |
||
411 | protected $formTheme = []; |
||
412 | |||
413 | /** |
||
414 | * @var string[] |
||
415 | */ |
||
416 | protected $filterTheme = []; |
||
417 | |||
418 | /** |
||
419 | * @var array<string, string> |
||
420 | * |
||
421 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
422 | */ |
||
423 | protected $templates = []; |
||
424 | |||
425 | /** |
||
426 | * @var AdminExtensionInterface[] |
||
427 | */ |
||
428 | protected $extensions = []; |
||
429 | |||
430 | /** |
||
431 | * @var LabelTranslatorStrategyInterface |
||
432 | */ |
||
433 | protected $labelTranslatorStrategy; |
||
434 | |||
435 | /** |
||
436 | * Setting to true will enable preview mode for |
||
437 | * the entity and show a preview button in the |
||
438 | * edit/create forms. |
||
439 | * |
||
440 | * @var bool |
||
441 | */ |
||
442 | protected $supportsPreviewMode = false; |
||
443 | |||
444 | /** |
||
445 | * Roles and permissions per role. |
||
446 | * |
||
447 | * @var array 'role' => ['permission', 'permission'] |
||
448 | */ |
||
449 | protected $securityInformation = []; |
||
450 | |||
451 | protected $cacheIsGranted = []; |
||
452 | |||
453 | /** |
||
454 | * Action list for the search result. |
||
455 | * |
||
456 | * @var string[] |
||
457 | */ |
||
458 | protected $searchResultActions = ['edit', 'show']; |
||
459 | |||
460 | protected $listModes = [ |
||
461 | 'list' => [ |
||
462 | 'class' => 'fa fa-list fa-fw', |
||
463 | ], |
||
464 | 'mosaic' => [ |
||
465 | 'class' => self::MOSAIC_ICON_CLASS, |
||
466 | ], |
||
467 | ]; |
||
468 | |||
469 | /** |
||
470 | * The Access mapping. |
||
471 | * |
||
472 | * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]] |
||
473 | */ |
||
474 | protected $accessMapping = []; |
||
475 | |||
476 | /** |
||
477 | * @var MutableTemplateRegistryInterface |
||
478 | */ |
||
479 | private $templateRegistry; |
||
480 | |||
481 | /** |
||
482 | * The class name managed by the admin class. |
||
483 | * |
||
484 | * @var string |
||
485 | */ |
||
486 | private $class; |
||
487 | |||
488 | /** |
||
489 | * The subclasses supported by the admin class. |
||
490 | * |
||
491 | * @var array<string, string> |
||
492 | */ |
||
493 | private $subClasses = []; |
||
494 | |||
495 | /** |
||
496 | * The list collection. |
||
497 | * |
||
498 | * @var FieldDescriptionCollection |
||
499 | */ |
||
500 | private $list; |
||
501 | |||
502 | /** |
||
503 | * @var FieldDescriptionCollection|null |
||
504 | */ |
||
505 | private $show; |
||
506 | |||
507 | /** |
||
508 | * @var Form|null |
||
509 | */ |
||
510 | private $form; |
||
511 | |||
512 | /** |
||
513 | * The cached base route name. |
||
514 | * |
||
515 | * @var string |
||
516 | */ |
||
517 | private $cachedBaseRouteName; |
||
518 | |||
519 | /** |
||
520 | * The cached base route pattern. |
||
521 | * |
||
522 | * @var string |
||
523 | */ |
||
524 | private $cachedBaseRoutePattern; |
||
525 | |||
526 | /** |
||
527 | * The form group disposition. |
||
528 | * |
||
529 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
530 | * hold boolean values. |
||
531 | * |
||
532 | * @var array|bool |
||
533 | */ |
||
534 | private $formGroups = false; |
||
535 | |||
536 | /** |
||
537 | * The form tabs disposition. |
||
538 | * |
||
539 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
540 | * hold boolean values. |
||
541 | * |
||
542 | * @var array|bool |
||
543 | */ |
||
544 | private $formTabs = false; |
||
545 | |||
546 | /** |
||
547 | * The view group disposition. |
||
548 | * |
||
549 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
550 | * hold boolean values. |
||
551 | * |
||
552 | * @var array|bool |
||
553 | */ |
||
554 | private $showGroups = false; |
||
555 | |||
556 | /** |
||
557 | * The view tab disposition. |
||
558 | * |
||
559 | * NEXT_MAJOR: must have `[]` as default value and remove the possibility to |
||
560 | * hold boolean values. |
||
561 | * |
||
562 | * @var array|bool |
||
563 | */ |
||
564 | private $showTabs = false; |
||
565 | |||
566 | /** |
||
567 | * The manager type to use for the admin. |
||
568 | * |
||
569 | * @var string |
||
570 | */ |
||
571 | private $managerType; |
||
572 | |||
573 | /** |
||
574 | * The breadcrumbsBuilder component. |
||
575 | * |
||
576 | * @var BreadcrumbsBuilderInterface |
||
577 | */ |
||
578 | private $breadcrumbsBuilder; |
||
579 | |||
580 | /** |
||
581 | * Component responsible for persisting filters. |
||
582 | * |
||
583 | * @var FilterPersisterInterface|null |
||
584 | */ |
||
585 | private $filterPersister; |
||
586 | |||
587 | /** |
||
588 | * @param string $code |
||
589 | * @param string $class |
||
590 | * @param string|null $baseControllerName |
||
591 | */ |
||
592 | public function __construct($code, $class, $baseControllerName = null) |
||
593 | { |
||
594 | if (!\is_string($code)) { |
||
595 | @trigger_error(sprintf( |
||
|
|||
596 | '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.', |
||
597 | __METHOD__ |
||
598 | ), E_USER_DEPRECATED); |
||
599 | } |
||
600 | $this->code = $code; |
||
601 | if (!\is_string($class)) { |
||
602 | @trigger_error(sprintf( |
||
603 | '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.', |
||
604 | __METHOD__ |
||
605 | ), E_USER_DEPRECATED); |
||
606 | } |
||
607 | $this->class = $class; |
||
608 | if (null !== $baseControllerName && !\is_string($baseControllerName)) { |
||
609 | @trigger_error(sprintf( |
||
610 | '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.', |
||
611 | __METHOD__ |
||
612 | ), E_USER_DEPRECATED); |
||
613 | } |
||
614 | $this->baseControllerName = $baseControllerName; |
||
615 | |||
616 | // NEXT_MAJOR: Remove this line. |
||
617 | $this->predefinePerPageOptions(); |
||
618 | |||
619 | // NEXT_MAJOR: Remove this line. |
||
620 | $this->datagridValues['_per_page'] = $this->maxPerPage; |
||
621 | } |
||
622 | |||
623 | /** |
||
624 | * {@inheritdoc} |
||
625 | */ |
||
626 | public function getExportFormats() |
||
627 | { |
||
628 | return [ |
||
629 | 'json', 'xml', 'csv', 'xls', |
||
630 | ]; |
||
631 | } |
||
632 | |||
633 | /** |
||
634 | * @return array |
||
635 | */ |
||
636 | public function getExportFields() |
||
637 | { |
||
638 | $fields = $this->getModelManager()->getExportFields($this->getClass()); |
||
639 | |||
640 | foreach ($this->getExtensions() as $extension) { |
||
641 | if (method_exists($extension, 'configureExportFields')) { |
||
642 | $fields = $extension->configureExportFields($this, $fields); |
||
643 | } |
||
644 | } |
||
645 | |||
646 | return $fields; |
||
647 | } |
||
648 | |||
649 | public function getDataSourceIterator() |
||
650 | { |
||
651 | $datagrid = $this->getDatagrid(); |
||
652 | $datagrid->buildPager(); |
||
653 | |||
654 | $fields = []; |
||
655 | |||
656 | foreach ($this->getExportFields() as $key => $field) { |
||
657 | $label = $this->getTranslationLabel($field, 'export', 'label'); |
||
658 | $transLabel = $this->trans($label); |
||
659 | |||
660 | // NEXT_MAJOR: Remove this hack, because all field labels will be translated with the major release |
||
661 | // No translation key exists |
||
662 | if ($transLabel === $label) { |
||
663 | $fields[$key] = $field; |
||
664 | } else { |
||
665 | $fields[$transLabel] = $field; |
||
666 | } |
||
667 | } |
||
668 | |||
669 | return $this->getModelManager()->getDataSourceIterator($datagrid, $fields); |
||
670 | } |
||
671 | |||
672 | public function validate(ErrorElement $errorElement, $object) |
||
673 | { |
||
674 | } |
||
675 | |||
676 | /** |
||
677 | * define custom variable. |
||
678 | */ |
||
679 | public function initialize() |
||
680 | { |
||
681 | if (!$this->classnameLabel) { |
||
682 | /* NEXT_MAJOR: remove cast to string, null is not supposed to be |
||
683 | supported but was documented as such */ |
||
684 | $this->classnameLabel = substr( |
||
685 | (string) $this->getClass(), |
||
686 | strrpos((string) $this->getClass(), '\\') + 1 |
||
687 | ); |
||
688 | } |
||
689 | |||
690 | // NEXT_MAJOR: Remove this line. |
||
691 | $this->baseCodeRoute = $this->getCode(); |
||
692 | |||
693 | $this->configure(); |
||
694 | } |
||
695 | |||
696 | public function configure() |
||
697 | { |
||
698 | } |
||
699 | |||
700 | public function update($object) |
||
701 | { |
||
702 | $this->preUpdate($object); |
||
703 | foreach ($this->extensions as $extension) { |
||
704 | $extension->preUpdate($this, $object); |
||
705 | } |
||
706 | |||
707 | $result = $this->getModelManager()->update($object); |
||
708 | // BC compatibility |
||
709 | if (null !== $result) { |
||
710 | $object = $result; |
||
711 | } |
||
712 | |||
713 | $this->postUpdate($object); |
||
714 | foreach ($this->extensions as $extension) { |
||
715 | $extension->postUpdate($this, $object); |
||
716 | } |
||
717 | |||
718 | return $object; |
||
719 | } |
||
720 | |||
721 | public function create($object) |
||
722 | { |
||
723 | $this->prePersist($object); |
||
724 | foreach ($this->extensions as $extension) { |
||
725 | $extension->prePersist($this, $object); |
||
726 | } |
||
727 | |||
728 | $result = $this->getModelManager()->create($object); |
||
729 | // BC compatibility |
||
730 | if (null !== $result) { |
||
731 | $object = $result; |
||
732 | } |
||
733 | |||
734 | $this->postPersist($object); |
||
735 | foreach ($this->extensions as $extension) { |
||
736 | $extension->postPersist($this, $object); |
||
737 | } |
||
738 | |||
739 | $this->createObjectSecurity($object); |
||
740 | |||
741 | return $object; |
||
742 | } |
||
743 | |||
744 | public function delete($object) |
||
745 | { |
||
746 | $this->preRemove($object); |
||
747 | foreach ($this->extensions as $extension) { |
||
748 | $extension->preRemove($this, $object); |
||
749 | } |
||
750 | |||
751 | $this->getSecurityHandler()->deleteObjectSecurity($this, $object); |
||
752 | $this->getModelManager()->delete($object); |
||
753 | |||
754 | $this->postRemove($object); |
||
755 | foreach ($this->extensions as $extension) { |
||
756 | $extension->postRemove($this, $object); |
||
757 | } |
||
758 | } |
||
759 | |||
760 | /** |
||
761 | * @param object $object |
||
762 | */ |
||
763 | public function preValidate($object) |
||
764 | { |
||
765 | } |
||
766 | |||
767 | public function preUpdate($object) |
||
768 | { |
||
769 | } |
||
770 | |||
771 | public function postUpdate($object) |
||
772 | { |
||
773 | } |
||
774 | |||
775 | public function prePersist($object) |
||
776 | { |
||
777 | } |
||
778 | |||
779 | public function postPersist($object) |
||
780 | { |
||
781 | } |
||
782 | |||
783 | public function preRemove($object) |
||
784 | { |
||
785 | } |
||
786 | |||
787 | public function postRemove($object) |
||
788 | { |
||
789 | } |
||
790 | |||
791 | public function preBatchAction($actionName, ProxyQueryInterface $query, array &$idx, $allElements) |
||
792 | { |
||
793 | } |
||
794 | |||
795 | public function getFilterParameters() |
||
796 | { |
||
797 | $parameters = []; |
||
798 | |||
799 | // build the values array |
||
800 | if ($this->hasRequest()) { |
||
801 | $filters = $this->request->query->get('filter', []); |
||
802 | if (isset($filters['_page'])) { |
||
803 | $filters['_page'] = (int) $filters['_page']; |
||
804 | } |
||
805 | if (isset($filters['_per_page'])) { |
||
806 | $filters['_per_page'] = (int) $filters['_per_page']; |
||
807 | } |
||
808 | |||
809 | // if filter persistence is configured |
||
810 | // NEXT_MAJOR: remove `$this->persistFilters !== false` from the condition |
||
811 | if (false !== $this->persistFilters && null !== $this->filterPersister) { |
||
812 | // if reset filters is asked, remove from storage |
||
813 | if ('reset' === $this->request->query->get('filters')) { |
||
814 | $this->filterPersister->reset($this->getCode()); |
||
815 | } |
||
816 | |||
817 | // if no filters, fetch from storage |
||
818 | // otherwise save to storage |
||
819 | if (empty($filters)) { |
||
820 | $filters = $this->filterPersister->get($this->getCode()); |
||
821 | } else { |
||
822 | $this->filterPersister->set($this->getCode(), $filters); |
||
823 | } |
||
824 | } |
||
825 | |||
826 | $parameters = array_merge( |
||
827 | $this->getModelManager()->getDefaultSortValues($this->getClass()), |
||
828 | $this->datagridValues, // NEXT_MAJOR: Remove this line. |
||
829 | $this->getDefaultSortValues(), |
||
830 | $this->getDefaultFilterValues(), |
||
831 | $filters |
||
832 | ); |
||
833 | |||
834 | if (!$this->determinedPerPageValue($parameters['_per_page'])) { |
||
835 | $parameters['_per_page'] = $this->getMaxPerPage(); |
||
836 | } |
||
837 | |||
838 | // always force the parent value |
||
839 | if ($this->isChild() && $this->getParentAssociationMapping()) { |
||
840 | $name = str_replace('.', '__', $this->getParentAssociationMapping()); |
||
841 | $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())]; |
||
842 | } |
||
843 | } |
||
844 | |||
845 | return $parameters; |
||
846 | } |
||
847 | |||
848 | public function buildDatagrid() |
||
849 | { |
||
850 | if ($this->datagrid) { |
||
851 | return; |
||
852 | } |
||
853 | |||
854 | $filterParameters = $this->getFilterParameters(); |
||
855 | |||
856 | // transform _sort_by from a string to a FieldDescriptionInterface for the datagrid. |
||
857 | if (isset($filterParameters['_sort_by']) && \is_string($filterParameters['_sort_by'])) { |
||
858 | if ($this->hasListFieldDescription($filterParameters['_sort_by'])) { |
||
859 | $filterParameters['_sort_by'] = $this->getListFieldDescription($filterParameters['_sort_by']); |
||
860 | } else { |
||
861 | $filterParameters['_sort_by'] = $this->getModelManager()->getNewFieldDescriptionInstance( |
||
862 | $this->getClass(), |
||
863 | $filterParameters['_sort_by'], |
||
864 | [] |
||
865 | ); |
||
866 | |||
867 | $this->getListBuilder()->buildField(null, $filterParameters['_sort_by'], $this); |
||
868 | } |
||
869 | } |
||
870 | |||
871 | // initialize the datagrid |
||
872 | $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $filterParameters); |
||
873 | |||
874 | $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks); |
||
875 | |||
876 | $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); |
||
877 | |||
878 | // build the datagrid filter |
||
879 | $this->configureDatagridFilters($mapper); |
||
880 | |||
881 | // ok, try to limit to add parent filter |
||
882 | if ($this->isChild() && $this->getParentAssociationMapping() && !$mapper->has($this->getParentAssociationMapping())) { |
||
883 | $mapper->add($this->getParentAssociationMapping(), null, [ |
||
884 | 'show_filter' => false, |
||
885 | 'label' => false, |
||
886 | 'field_type' => ModelHiddenType::class, |
||
887 | 'field_options' => [ |
||
888 | 'model_manager' => $this->getModelManager(), |
||
889 | ], |
||
890 | 'operator_type' => HiddenType::class, |
||
891 | ], null, null, [ |
||
892 | 'admin_code' => $this->getParent()->getCode(), |
||
893 | ]); |
||
894 | } |
||
895 | |||
896 | foreach ($this->getExtensions() as $extension) { |
||
897 | $extension->configureDatagridFilters($mapper); |
||
898 | } |
||
899 | } |
||
900 | |||
901 | /** |
||
902 | * Returns the name of the parent related field, so the field can be use to set the default |
||
903 | * value (ie the parent object) or to filter the object. |
||
904 | * |
||
905 | * @throws \InvalidArgumentException |
||
906 | * |
||
907 | * @return string|null |
||
908 | */ |
||
909 | public function getParentAssociationMapping() |
||
910 | { |
||
911 | // NEXT_MAJOR: remove array check |
||
912 | if (\is_array($this->parentAssociationMapping) && $this->isChild()) { |
||
913 | $parent = $this->getParent()->getCode(); |
||
914 | |||
915 | if (\array_key_exists($parent, $this->parentAssociationMapping)) { |
||
916 | return $this->parentAssociationMapping[$parent]; |
||
917 | } |
||
918 | |||
919 | throw new \InvalidArgumentException(sprintf( |
||
920 | "There's no association between %s and %s.", |
||
921 | $this->getCode(), |
||
922 | $this->getParent()->getCode() |
||
923 | )); |
||
924 | } |
||
925 | |||
926 | // NEXT_MAJOR: remove this line |
||
927 | return $this->parentAssociationMapping; |
||
928 | } |
||
929 | |||
930 | /** |
||
931 | * @param string $code |
||
932 | * @param string $value |
||
933 | */ |
||
934 | final public function addParentAssociationMapping($code, $value) |
||
935 | { |
||
936 | $this->parentAssociationMapping[$code] = $value; |
||
937 | } |
||
938 | |||
939 | /** |
||
940 | * Returns the baseRoutePattern used to generate the routing information. |
||
941 | * |
||
942 | * @throws \RuntimeException |
||
943 | * |
||
944 | * @return string the baseRoutePattern used to generate the routing information |
||
945 | */ |
||
946 | public function getBaseRoutePattern() |
||
947 | { |
||
948 | if (null !== $this->cachedBaseRoutePattern) { |
||
949 | return $this->cachedBaseRoutePattern; |
||
950 | } |
||
951 | |||
952 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern |
||
953 | $baseRoutePattern = $this->baseRoutePattern; |
||
954 | if (!$this->baseRoutePattern) { |
||
955 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
956 | |||
957 | if (!$matches) { |
||
958 | throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class)); |
||
959 | } |
||
960 | $baseRoutePattern = $this->urlize($matches[5], '-'); |
||
961 | } |
||
962 | |||
963 | $this->cachedBaseRoutePattern = sprintf( |
||
964 | '%s/%s/%s', |
||
965 | $this->getParent()->getBaseRoutePattern(), |
||
966 | $this->getParent()->getRouterIdParameter(), |
||
967 | $baseRoutePattern |
||
968 | ); |
||
969 | } elseif ($this->baseRoutePattern) { |
||
970 | $this->cachedBaseRoutePattern = $this->baseRoutePattern; |
||
971 | } else { |
||
972 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
973 | |||
974 | if (!$matches) { |
||
975 | throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class)); |
||
976 | } |
||
977 | |||
978 | $this->cachedBaseRoutePattern = sprintf( |
||
979 | '/%s%s/%s', |
||
980 | empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/', |
||
981 | $this->urlize($matches[3], '-'), |
||
982 | $this->urlize($matches[5], '-') |
||
983 | ); |
||
984 | } |
||
985 | |||
986 | return $this->cachedBaseRoutePattern; |
||
987 | } |
||
988 | |||
989 | /** |
||
990 | * Returns the baseRouteName used to generate the routing information. |
||
991 | * |
||
992 | * @throws \RuntimeException |
||
993 | * |
||
994 | * @return string the baseRouteName used to generate the routing information |
||
995 | */ |
||
996 | public function getBaseRouteName() |
||
997 | { |
||
998 | if (null !== $this->cachedBaseRouteName) { |
||
999 | return $this->cachedBaseRouteName; |
||
1000 | } |
||
1001 | |||
1002 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name |
||
1003 | $baseRouteName = $this->baseRouteName; |
||
1004 | if (!$this->baseRouteName) { |
||
1005 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
1006 | |||
1007 | if (!$matches) { |
||
1008 | throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class)); |
||
1009 | } |
||
1010 | $baseRouteName = $this->urlize($matches[5]); |
||
1011 | } |
||
1012 | |||
1013 | $this->cachedBaseRouteName = sprintf( |
||
1014 | '%s_%s', |
||
1015 | $this->getParent()->getBaseRouteName(), |
||
1016 | $baseRouteName |
||
1017 | ); |
||
1018 | } elseif ($this->baseRouteName) { |
||
1019 | $this->cachedBaseRouteName = $this->baseRouteName; |
||
1020 | } else { |
||
1021 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
1022 | |||
1023 | if (!$matches) { |
||
1024 | throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class)); |
||
1025 | } |
||
1026 | |||
1027 | $this->cachedBaseRouteName = sprintf( |
||
1028 | 'admin_%s%s_%s', |
||
1029 | empty($matches[1]) ? '' : $this->urlize($matches[1]).'_', |
||
1030 | $this->urlize($matches[3]), |
||
1031 | $this->urlize($matches[5]) |
||
1032 | ); |
||
1033 | } |
||
1034 | |||
1035 | return $this->cachedBaseRouteName; |
||
1036 | } |
||
1037 | |||
1038 | /** |
||
1039 | * urlize the given word. |
||
1040 | * |
||
1041 | * @param string $word |
||
1042 | * @param string $sep the separator |
||
1043 | * |
||
1044 | * @return string |
||
1045 | */ |
||
1046 | public function urlize($word, $sep = '_') |
||
1047 | { |
||
1048 | return strtolower(preg_replace('/[^a-z0-9_]/i', $sep.'$1', $word)); |
||
1049 | } |
||
1050 | |||
1051 | public function getClass() |
||
1052 | { |
||
1053 | if ($this->hasActiveSubClass()) { |
||
1054 | if ($this->hasParentFieldDescription()) { |
||
1055 | throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass'); |
||
1056 | } |
||
1057 | |||
1058 | $subClass = $this->getRequest()->query->get('subclass'); |
||
1059 | |||
1060 | if (!$this->hasSubClass($subClass)) { |
||
1061 | throw new \RuntimeException(sprintf('Subclass "%s" is not defined.', $subClass)); |
||
1062 | } |
||
1063 | |||
1064 | return $this->getSubClass($subClass); |
||
1065 | } |
||
1066 | |||
1067 | // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 |
||
1068 | if ($this->subject && \is_object($this->subject)) { |
||
1069 | return ClassUtils::getClass($this->subject); |
||
1070 | } |
||
1071 | |||
1072 | return $this->class; |
||
1073 | } |
||
1074 | |||
1075 | public function getSubClasses() |
||
1076 | { |
||
1077 | return $this->subClasses; |
||
1078 | } |
||
1079 | |||
1080 | /** |
||
1081 | * NEXT_MAJOR: remove this method. |
||
1082 | */ |
||
1083 | public function addSubClass($subClass) |
||
1084 | { |
||
1085 | @trigger_error(sprintf( |
||
1086 | 'Method "%s" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0.', |
||
1087 | __METHOD__ |
||
1088 | ), E_USER_DEPRECATED); |
||
1089 | |||
1090 | if (!\in_array($subClass, $this->subClasses, true)) { |
||
1091 | $this->subClasses[] = $subClass; |
||
1092 | } |
||
1093 | } |
||
1094 | |||
1095 | public function setSubClasses(array $subClasses) |
||
1096 | { |
||
1097 | $this->subClasses = $subClasses; |
||
1098 | } |
||
1099 | |||
1100 | public function hasSubClass($name) |
||
1101 | { |
||
1102 | return isset($this->subClasses[$name]); |
||
1103 | } |
||
1104 | |||
1105 | public function hasActiveSubClass() |
||
1106 | { |
||
1107 | if (\count($this->subClasses) > 0 && $this->request) { |
||
1108 | return null !== $this->getRequest()->query->get('subclass'); |
||
1109 | } |
||
1110 | |||
1111 | return false; |
||
1112 | } |
||
1113 | |||
1114 | public function getActiveSubClass() |
||
1115 | { |
||
1116 | if (!$this->hasActiveSubClass()) { |
||
1117 | @trigger_error(sprintf( |
||
1118 | '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. '. |
||
1119 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1120 | __METHOD__, |
||
1121 | __CLASS__ |
||
1122 | ), E_USER_DEPRECATED); |
||
1123 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1124 | // throw new \LogicException(sprintf( |
||
1125 | // 'Admin "%s" has no active subclass.', |
||
1126 | // static::class |
||
1127 | // )); |
||
1128 | |||
1129 | return null; |
||
1130 | } |
||
1131 | |||
1132 | return $this->getSubClass($this->getActiveSubclassCode()); |
||
1133 | } |
||
1134 | |||
1135 | public function getActiveSubclassCode() |
||
1136 | { |
||
1137 | if (!$this->hasActiveSubClass()) { |
||
1138 | @trigger_error(sprintf( |
||
1139 | '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. '. |
||
1140 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1141 | __METHOD__, |
||
1142 | __CLASS__ |
||
1143 | ), E_USER_DEPRECATED); |
||
1144 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1145 | // throw new \LogicException(sprintf( |
||
1146 | // 'Admin "%s" has no active subclass.', |
||
1147 | // static::class |
||
1148 | // )); |
||
1149 | |||
1150 | return null; |
||
1151 | } |
||
1152 | |||
1153 | $subClass = $this->getRequest()->query->get('subclass'); |
||
1154 | |||
1155 | if (!$this->hasSubClass($subClass)) { |
||
1156 | @trigger_error(sprintf( |
||
1157 | '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. '. |
||
1158 | 'Use %s::hasActiveSubClass() to know if there is an active subclass.', |
||
1159 | __METHOD__, |
||
1160 | __CLASS__ |
||
1161 | ), E_USER_DEPRECATED); |
||
1162 | // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type |
||
1163 | // throw new \LogicException(sprintf( |
||
1164 | // 'Admin "%s" has no active subclass.', |
||
1165 | // static::class |
||
1166 | // )); |
||
1167 | |||
1168 | return null; |
||
1169 | } |
||
1170 | |||
1171 | return $subClass; |
||
1172 | } |
||
1173 | |||
1174 | public function getBatchActions() |
||
1175 | { |
||
1176 | $actions = []; |
||
1177 | |||
1178 | if ($this->hasRoute('delete') && $this->hasAccess('delete')) { |
||
1179 | $actions['delete'] = [ |
||
1180 | 'label' => 'action_delete', |
||
1181 | 'translation_domain' => 'SonataAdminBundle', |
||
1182 | 'ask_confirmation' => true, // by default always true |
||
1183 | ]; |
||
1184 | } |
||
1185 | |||
1186 | $actions = $this->configureBatchActions($actions); |
||
1187 | |||
1188 | foreach ($this->getExtensions() as $extension) { |
||
1189 | // NEXT_MAJOR: remove method check |
||
1190 | if (method_exists($extension, 'configureBatchActions')) { |
||
1191 | $actions = $extension->configureBatchActions($this, $actions); |
||
1192 | } |
||
1193 | } |
||
1194 | |||
1195 | foreach ($actions as $name => &$action) { |
||
1196 | if (!\array_key_exists('label', $action)) { |
||
1197 | $action['label'] = $this->getTranslationLabel($name, 'batch', 'label'); |
||
1198 | } |
||
1199 | |||
1200 | if (!\array_key_exists('translation_domain', $action)) { |
||
1201 | $action['translation_domain'] = $this->getTranslationDomain(); |
||
1202 | } |
||
1203 | } |
||
1204 | |||
1205 | return $actions; |
||
1206 | } |
||
1207 | |||
1208 | public function getRoutes() |
||
1209 | { |
||
1210 | $this->buildRoutes(); |
||
1211 | |||
1212 | return $this->routes; |
||
1213 | } |
||
1214 | |||
1215 | public function getRouterIdParameter() |
||
1216 | { |
||
1217 | return '{'.$this->getIdParameter().'}'; |
||
1218 | } |
||
1219 | |||
1220 | public function getIdParameter() |
||
1221 | { |
||
1222 | $parameter = 'id'; |
||
1223 | |||
1224 | for ($i = 0; $i < $this->getChildDepth(); ++$i) { |
||
1225 | $parameter = 'child'.ucfirst($parameter); |
||
1226 | } |
||
1227 | |||
1228 | return $parameter; |
||
1229 | } |
||
1230 | |||
1231 | public function hasRoute($name) |
||
1232 | { |
||
1233 | if (!$this->routeGenerator) { |
||
1234 | throw new \RuntimeException('RouteGenerator cannot be null'); |
||
1235 | } |
||
1236 | |||
1237 | return $this->routeGenerator->hasAdminRoute($this, $name); |
||
1238 | } |
||
1239 | |||
1240 | /** |
||
1241 | * @param string $name |
||
1242 | * @param string|null $adminCode |
||
1243 | * |
||
1244 | * @return bool |
||
1245 | */ |
||
1246 | public function isCurrentRoute($name, $adminCode = null) |
||
1247 | { |
||
1248 | if (!$this->hasRequest()) { |
||
1249 | return false; |
||
1250 | } |
||
1251 | |||
1252 | $request = $this->getRequest(); |
||
1253 | $route = $request->get('_route'); |
||
1254 | |||
1255 | if ($adminCode) { |
||
1256 | $admin = $this->getConfigurationPool()->getAdminByAdminCode($adminCode); |
||
1257 | } else { |
||
1258 | $admin = $this; |
||
1259 | } |
||
1260 | |||
1261 | if (!$admin) { |
||
1262 | return false; |
||
1263 | } |
||
1264 | |||
1265 | return ($admin->getBaseRouteName().'_'.$name) === $route; |
||
1266 | } |
||
1267 | |||
1268 | public function generateObjectUrl($name, $object, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1269 | { |
||
1270 | $parameters['id'] = $this->getUrlSafeIdentifier($object); |
||
1271 | |||
1272 | return $this->generateUrl($name, $parameters, $referenceType); |
||
1273 | } |
||
1274 | |||
1275 | public function generateUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1276 | { |
||
1277 | return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); |
||
1278 | } |
||
1279 | |||
1280 | public function generateMenuUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) |
||
1281 | { |
||
1282 | return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); |
||
1283 | } |
||
1284 | |||
1285 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry) |
||
1286 | { |
||
1287 | $this->templateRegistry = $templateRegistry; |
||
1288 | } |
||
1289 | |||
1290 | /** |
||
1291 | * @param array<string, string> $templates |
||
1292 | */ |
||
1293 | public function setTemplates(array $templates) |
||
1294 | { |
||
1295 | // NEXT_MAJOR: Remove this line |
||
1296 | $this->templates = $templates; |
||
1297 | |||
1298 | $this->getTemplateRegistry()->setTemplates($templates); |
||
1299 | } |
||
1300 | |||
1301 | /** |
||
1302 | * @param string $name |
||
1303 | * @param string $template |
||
1304 | */ |
||
1305 | public function setTemplate($name, $template) |
||
1306 | { |
||
1307 | // NEXT_MAJOR: Remove this line |
||
1308 | $this->templates[$name] = $template; |
||
1309 | |||
1310 | $this->getTemplateRegistry()->setTemplate($name, $template); |
||
1311 | } |
||
1312 | |||
1313 | /** |
||
1314 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
1315 | * |
||
1316 | * @return array<string, string> |
||
1317 | */ |
||
1318 | public function getTemplates() |
||
1319 | { |
||
1320 | return $this->getTemplateRegistry()->getTemplates(); |
||
1321 | } |
||
1322 | |||
1323 | /** |
||
1324 | * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead |
||
1325 | * |
||
1326 | * @param string $name |
||
1327 | * |
||
1328 | * @return string|null |
||
1329 | */ |
||
1330 | public function getTemplate($name) |
||
1331 | { |
||
1332 | return $this->getTemplateRegistry()->getTemplate($name); |
||
1333 | } |
||
1334 | |||
1335 | public function getNewInstance() |
||
1336 | { |
||
1337 | $object = $this->getModelManager()->getModelInstance($this->getClass()); |
||
1338 | foreach ($this->getExtensions() as $extension) { |
||
1339 | $extension->alterNewInstance($this, $object); |
||
1340 | } |
||
1341 | |||
1342 | return $object; |
||
1343 | } |
||
1344 | |||
1345 | public function getFormBuilder() |
||
1346 | { |
||
1347 | $this->formOptions['data_class'] = $this->getClass(); |
||
1348 | |||
1349 | $formBuilder = $this->getFormContractor()->getFormBuilder( |
||
1350 | $this->getUniqid(), |
||
1351 | $this->formOptions |
||
1352 | ); |
||
1353 | |||
1354 | $this->defineFormBuilder($formBuilder); |
||
1355 | |||
1356 | return $formBuilder; |
||
1357 | } |
||
1358 | |||
1359 | /** |
||
1360 | * This method is being called by the main admin class and the child class, |
||
1361 | * the getFormBuilder is only call by the main admin class. |
||
1362 | */ |
||
1363 | public function defineFormBuilder(FormBuilderInterface $formBuilder) |
||
1364 | { |
||
1365 | if (!$this->hasSubject()) { |
||
1366 | @trigger_error(sprintf( |
||
1367 | 'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.65 and will throw an exception in 4.0. '. |
||
1368 | 'Use %s::setSubject() to set the subject.', |
||
1369 | __METHOD__, |
||
1370 | __CLASS__ |
||
1371 | ), E_USER_DEPRECATED); |
||
1372 | // NEXT_MAJOR : remove the previous `trigger_error()` call and uncomment the following exception |
||
1373 | // throw new \LogicException(sprintf( |
||
1374 | // 'Admin "%s" has no subject.', |
||
1375 | // static::class |
||
1376 | // )); |
||
1377 | } |
||
1378 | |||
1379 | $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this); |
||
1380 | |||
1381 | $this->configureFormFields($mapper); |
||
1382 | |||
1383 | foreach ($this->getExtensions() as $extension) { |
||
1384 | $extension->configureFormFields($mapper); |
||
1385 | } |
||
1386 | |||
1387 | $this->attachInlineValidator(); |
||
1388 | } |
||
1389 | |||
1390 | public function attachAdminClass(FieldDescriptionInterface $fieldDescription) |
||
1391 | { |
||
1392 | $pool = $this->getConfigurationPool(); |
||
1393 | |||
1394 | $adminCode = $fieldDescription->getOption('admin_code'); |
||
1395 | |||
1396 | if (null !== $adminCode) { |
||
1397 | $admin = $pool->getAdminByAdminCode($adminCode); |
||
1398 | } else { |
||
1399 | $admin = $pool->getAdminByClass($fieldDescription->getTargetEntity()); |
||
1400 | } |
||
1401 | |||
1402 | if (!$admin) { |
||
1403 | return; |
||
1404 | } |
||
1405 | |||
1406 | if ($this->hasRequest()) { |
||
1407 | $admin->setRequest($this->getRequest()); |
||
1408 | } |
||
1409 | |||
1410 | $fieldDescription->setAssociationAdmin($admin); |
||
1411 | } |
||
1412 | |||
1413 | public function getObject($id) |
||
1414 | { |
||
1415 | $object = $this->getModelManager()->find($this->getClass(), $id); |
||
1416 | foreach ($this->getExtensions() as $extension) { |
||
1417 | $extension->alterObject($this, $object); |
||
1418 | } |
||
1419 | |||
1420 | return $object; |
||
1421 | } |
||
1422 | |||
1423 | public function getForm() |
||
1424 | { |
||
1425 | $this->buildForm(); |
||
1426 | |||
1427 | return $this->form; |
||
1428 | } |
||
1429 | |||
1430 | public function getList() |
||
1431 | { |
||
1432 | $this->buildList(); |
||
1433 | |||
1434 | return $this->list; |
||
1435 | } |
||
1436 | |||
1437 | /** |
||
1438 | * @final since sonata-project/admin-bundle 3.63.0 |
||
1439 | */ |
||
1440 | public function createQuery($context = 'list') |
||
1441 | { |
||
1442 | if (\func_num_args() > 0) { |
||
1443 | @trigger_error( |
||
1444 | 'The $context argument of '.__METHOD__.' is deprecated since 3.3, to be removed in 4.0.', |
||
1445 | E_USER_DEPRECATED |
||
1446 | ); |
||
1447 | } |
||
1448 | |||
1449 | $query = $this->getModelManager()->createQuery($this->getClass()); |
||
1450 | |||
1451 | $query = $this->configureQuery($query); |
||
1452 | foreach ($this->extensions as $extension) { |
||
1453 | $extension->configureQuery($this, $query, $context); |
||
1454 | } |
||
1455 | |||
1456 | return $query; |
||
1457 | } |
||
1458 | |||
1459 | public function getDatagrid() |
||
1460 | { |
||
1461 | $this->buildDatagrid(); |
||
1462 | |||
1463 | return $this->datagrid; |
||
1464 | } |
||
1465 | |||
1466 | public function buildTabMenu($action, ?AdminInterface $childAdmin = null) |
||
1467 | { |
||
1468 | if ($this->loaded['tab_menu']) { |
||
1469 | return $this->menu; |
||
1470 | } |
||
1471 | |||
1472 | $this->loaded['tab_menu'] = true; |
||
1473 | |||
1474 | $menu = $this->menuFactory->createItem('root'); |
||
1475 | $menu->setChildrenAttribute('class', 'nav navbar-nav'); |
||
1476 | $menu->setExtra('translation_domain', $this->translationDomain); |
||
1477 | |||
1478 | // Prevents BC break with KnpMenuBundle v1.x |
||
1479 | if (method_exists($menu, 'setCurrentUri')) { |
||
1480 | $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo()); |
||
1481 | } |
||
1482 | |||
1483 | $this->configureTabMenu($menu, $action, $childAdmin); |
||
1484 | |||
1485 | foreach ($this->getExtensions() as $extension) { |
||
1486 | $extension->configureTabMenu($this, $menu, $action, $childAdmin); |
||
1487 | } |
||
1488 | |||
1489 | $this->menu = $menu; |
||
1490 | |||
1491 | return $this->menu; |
||
1492 | } |
||
1493 | |||
1494 | public function buildSideMenu($action, ?AdminInterface $childAdmin = null) |
||
1495 | { |
||
1496 | return $this->buildTabMenu($action, $childAdmin); |
||
1497 | } |
||
1498 | |||
1499 | /** |
||
1500 | * @param string $action |
||
1501 | * |
||
1502 | * @return ItemInterface |
||
1503 | */ |
||
1504 | public function getSideMenu($action, ?AdminInterface $childAdmin = null) |
||
1505 | { |
||
1506 | if ($this->isChild()) { |
||
1507 | return $this->getParent()->getSideMenu($action, $this); |
||
1508 | } |
||
1509 | |||
1510 | $this->buildSideMenu($action, $childAdmin); |
||
1511 | |||
1512 | return $this->menu; |
||
1513 | } |
||
1514 | |||
1515 | /** |
||
1516 | * Returns the root code. |
||
1517 | * |
||
1518 | * @return string the root code |
||
1519 | */ |
||
1520 | public function getRootCode() |
||
1521 | { |
||
1522 | return $this->getRoot()->getCode(); |
||
1523 | } |
||
1524 | |||
1525 | /** |
||
1526 | * Returns the master admin. |
||
1527 | * |
||
1528 | * @return AbstractAdmin the root admin class |
||
1529 | */ |
||
1530 | public function getRoot() |
||
1531 | { |
||
1532 | if (!$this->hasParentFieldDescription()) { |
||
1533 | return $this; |
||
1534 | } |
||
1535 | |||
1536 | return $this->getParentFieldDescription()->getAdmin()->getRoot(); |
||
1537 | } |
||
1538 | |||
1539 | public function setBaseControllerName($baseControllerName) |
||
1543 | |||
1544 | public function getBaseControllerName() |
||
1548 | |||
1549 | /** |
||
1550 | * @param string $label |
||
1551 | */ |
||
1552 | public function setLabel($label) |
||
1556 | |||
1557 | public function getLabel() |
||
1561 | |||
1562 | /** |
||
1563 | * @param bool $persist |
||
1564 | * |
||
1565 | * NEXT_MAJOR: remove this method |
||
1566 | * |
||
1567 | * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. |
||
1568 | */ |
||
1569 | public function setPersistFilters($persist) |
||
1578 | |||
1579 | public function setFilterPersister(?FilterPersisterInterface $filterPersister = null) |
||
1580 | { |
||
1581 | $this->filterPersister = $filterPersister; |
||
1582 | // NEXT_MAJOR remove the deprecated property will be removed. Needed for persisted filter condition. |
||
1583 | $this->persistFilters = true; |
||
1584 | } |
||
1585 | |||
1586 | /** |
||
1587 | * NEXT_MAJOR: Remove this method. |
||
1588 | * |
||
1589 | * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. |
||
1590 | * |
||
1591 | * @param int $maxPerPage |
||
1592 | */ |
||
1593 | public function setMaxPerPage($maxPerPage) |
||
1594 | { |
||
1595 | @trigger_error(sprintf( |
||
1596 | 'The method %s is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', |
||
1597 | __METHOD__ |
||
1598 | ), E_USER_DEPRECATED); |
||
1599 | |||
1600 | $this->maxPerPage = $maxPerPage; |
||
1601 | } |
||
1602 | |||
1603 | /** |
||
1604 | * @return int |
||
1605 | */ |
||
1606 | public function getMaxPerPage() |
||
1607 | { |
||
1608 | // NEXT_MAJOR: Remove this line and uncomment the following. |
||
1609 | return $this->maxPerPage; |
||
1610 | // $sortValues = $this->getModelManager()->getDefaultSortValues($this->class); |
||
1611 | |||
1612 | // return $sortValues['_per_page'] ?? 25; |
||
1613 | } |
||
1614 | |||
1615 | /** |
||
1616 | * @param int $maxPageLinks |
||
1617 | */ |
||
1618 | public function setMaxPageLinks($maxPageLinks) |
||
1619 | { |
||
1620 | $this->maxPageLinks = $maxPageLinks; |
||
1621 | } |
||
1622 | |||
1623 | /** |
||
1624 | * @return int |
||
1625 | */ |
||
1626 | public function getMaxPageLinks() |
||
1627 | { |
||
1628 | return $this->maxPageLinks; |
||
1629 | } |
||
1630 | |||
1631 | public function getFormGroups() |
||
1632 | { |
||
1633 | if (!\is_array($this->formGroups) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { |
||
1634 | @trigger_error(sprintf( |
||
1635 | '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.', |
||
1636 | __METHOD__ |
||
1637 | ), E_USER_DEPRECATED); |
||
1638 | } |
||
1639 | |||
1640 | return $this->formGroups; |
||
1641 | } |
||
1642 | |||
1643 | public function setFormGroups(array $formGroups) |
||
1644 | { |
||
1645 | $this->formGroups = $formGroups; |
||
1647 | |||
1648 | public function removeFieldFromFormGroup($key) |
||
1658 | |||
1659 | /** |
||
1660 | * @param string $group |
||
1661 | */ |
||
1662 | public function reorderFormGroup($group, array $keys) |
||
1669 | |||
1670 | public function getFormTabs() |
||
1681 | |||
1682 | public function setFormTabs(array $formTabs) |
||
1686 | |||
1687 | public function getShowTabs() |
||
1698 | |||
1699 | public function setShowTabs(array $showTabs) |
||
1703 | |||
1704 | public function getShowGroups() |
||
1715 | |||
1716 | public function setShowGroups(array $showGroups) |
||
1720 | |||
1721 | public function reorderShowGroup($group, array $keys) |
||
1728 | |||
1729 | public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription) |
||
1733 | |||
1734 | public function getParentFieldDescription() |
||
1754 | |||
1755 | public function hasParentFieldDescription() |
||
1759 | |||
1760 | public function setSubject($subject) |
||
1777 | |||
1778 | public function getSubject() |
||
1798 | |||
1799 | public function hasSubject() |
||
1811 | |||
1812 | public function getFormFieldDescriptions() |
||
1818 | |||
1819 | public function getFormFieldDescription($name) |
||
1823 | |||
1824 | /** |
||
1825 | * Returns true if the admin has a FieldDescription with the given $name. |
||
1826 | * |
||
1827 | * @param string $name |
||
1828 | * |
||
1829 | * @return bool |
||
1830 | */ |
||
1831 | public function hasFormFieldDescription($name) |
||
1835 | |||
1836 | public function addFormFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1840 | |||
1841 | /** |
||
1842 | * remove a FieldDescription. |
||
1843 | * |
||
1844 | * @param string $name |
||
1845 | */ |
||
1846 | public function removeFormFieldDescription($name) |
||
1850 | |||
1851 | /** |
||
1852 | * build and return the collection of form FieldDescription. |
||
1853 | * |
||
1854 | * @return array collection of form FieldDescription |
||
1855 | */ |
||
1856 | public function getShowFieldDescriptions() |
||
1862 | |||
1863 | /** |
||
1864 | * Returns the form FieldDescription with the given $name. |
||
1865 | * |
||
1866 | * @param string $name |
||
1867 | * |
||
1868 | * @return FieldDescriptionInterface |
||
1869 | */ |
||
1870 | public function getShowFieldDescription($name) |
||
1876 | |||
1877 | public function hasShowFieldDescription($name) |
||
1881 | |||
1882 | public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1886 | |||
1887 | public function removeShowFieldDescription($name) |
||
1891 | |||
1892 | public function getListFieldDescriptions() |
||
1898 | |||
1899 | public function getListFieldDescription($name) |
||
1921 | |||
1922 | public function hasListFieldDescription($name) |
||
1928 | |||
1929 | public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1933 | |||
1934 | public function removeListFieldDescription($name) |
||
1938 | |||
1939 | public function getFilterFieldDescription($name) |
||
1943 | |||
1944 | public function hasFilterFieldDescription($name) |
||
1948 | |||
1949 | public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription) |
||
1953 | |||
1954 | public function removeFilterFieldDescription($name) |
||
1958 | |||
1959 | public function getFilterFieldDescriptions() |
||
1965 | |||
1966 | public function addChild(AdminInterface $child) |
||
1999 | |||
2000 | public function hasChild($code) |
||
2004 | |||
2005 | public function getChildren() |
||
2009 | |||
2010 | public function getChild($code) |
||
2014 | |||
2015 | public function setParent(AdminInterface $parent) |
||
2019 | |||
2020 | public function getParent() |
||
2040 | |||
2041 | final public function getRootAncestor() |
||
2051 | |||
2052 | final public function getChildDepth() |
||
2064 | |||
2065 | final public function getCurrentLeafChildAdmin() |
||
2079 | |||
2080 | public function isChild() |
||
2084 | |||
2085 | /** |
||
2086 | * Returns true if the admin has children, false otherwise. |
||
2087 | * |
||
2088 | * @return bool if the admin has children |
||
2089 | */ |
||
2090 | public function hasChildren() |
||
2094 | |||
2095 | public function setUniqid($uniqid) |
||
2099 | |||
2100 | public function getUniqid() |
||
2108 | |||
2109 | /** |
||
2110 | * Returns the classname label. |
||
2111 | * |
||
2112 | * @return string the classname label |
||
2113 | */ |
||
2114 | public function getClassnameLabel() |
||
2118 | |||
2119 | public function getPersistentParameters() |
||
2135 | |||
2136 | /** |
||
2137 | * @param string $name |
||
2138 | * |
||
2139 | * @return mixed|null |
||
2140 | */ |
||
2141 | public function getPersistentParameter($name) |
||
2147 | |||
2148 | public function getBreadcrumbs($action) |
||
2158 | |||
2159 | /** |
||
2160 | * Generates the breadcrumbs array. |
||
2161 | * |
||
2162 | * Note: the method will be called by the top admin instance (parent => child) |
||
2163 | * |
||
2164 | * @param string $action |
||
2165 | * |
||
2166 | * @return array |
||
2167 | */ |
||
2168 | public function buildBreadcrumbs($action, ?ItemInterface $menu = null) |
||
2182 | |||
2183 | /** |
||
2184 | * NEXT_MAJOR : remove this method. |
||
2185 | * |
||
2186 | * @return BreadcrumbsBuilderInterface |
||
2187 | */ |
||
2188 | final public function getBreadcrumbsBuilder() |
||
2203 | |||
2204 | /** |
||
2205 | * NEXT_MAJOR : remove this method. |
||
2206 | * |
||
2207 | * @return AbstractAdmin |
||
2208 | */ |
||
2209 | final public function setBreadcrumbsBuilder(BreadcrumbsBuilderInterface $value) |
||
2220 | |||
2221 | public function setCurrentChild($currentChild) |
||
2225 | |||
2226 | /** |
||
2227 | * NEXT_MAJOR: Remove this method. |
||
2228 | * |
||
2229 | * @deprecated since sonata-project/admin-bundle 3.65, to be removed in 4.0 |
||
2230 | */ |
||
2231 | public function getCurrentChild() |
||
2244 | |||
2245 | public function isCurrentChild(): bool |
||
2249 | |||
2250 | /** |
||
2251 | * Returns the current child admin instance. |
||
2252 | * |
||
2253 | * @return AdminInterface|null the current child admin instance |
||
2254 | */ |
||
2255 | public function getCurrentChildAdmin() |
||
2265 | |||
2266 | public function trans($id, array $parameters = [], $domain = null, $locale = null) |
||
2277 | |||
2278 | /** |
||
2279 | * Translate a message id. |
||
2280 | * |
||
2281 | * NEXT_MAJOR: remove this method |
||
2282 | * |
||
2283 | * @param string $id |
||
2284 | * @param int $count |
||
2285 | * @param string|null $domain |
||
2286 | * @param string|null $locale |
||
2287 | * |
||
2288 | * @return string the translated string |
||
2289 | * |
||
2290 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2291 | */ |
||
2292 | public function transChoice($id, $count, array $parameters = [], $domain = null, $locale = null) |
||
2303 | |||
2304 | public function setTranslationDomain($translationDomain) |
||
2308 | |||
2309 | public function getTranslationDomain() |
||
2313 | |||
2314 | /** |
||
2315 | * {@inheritdoc} |
||
2316 | * |
||
2317 | * NEXT_MAJOR: remove this method |
||
2318 | * |
||
2319 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2320 | */ |
||
2321 | public function setTranslator(TranslatorInterface $translator) |
||
2333 | |||
2334 | /** |
||
2335 | * {@inheritdoc} |
||
2336 | * |
||
2337 | * NEXT_MAJOR: remove this method |
||
2338 | * |
||
2339 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
2340 | */ |
||
2341 | public function getTranslator() |
||
2350 | |||
2351 | public function getTranslationLabel($label, $context = '', $type = '') |
||
2355 | |||
2356 | public function setRequest(Request $request) |
||
2364 | |||
2365 | public function getRequest() |
||
2374 | |||
2375 | public function hasRequest() |
||
2379 | |||
2380 | public function setFormContractor(FormContractorInterface $formBuilder) |
||
2384 | |||
2385 | /** |
||
2386 | * @return FormContractorInterface |
||
2387 | */ |
||
2388 | public function getFormContractor() |
||
2392 | |||
2393 | public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) |
||
2397 | |||
2398 | public function getDatagridBuilder() |
||
2402 | |||
2403 | public function setListBuilder(ListBuilderInterface $listBuilder) |
||
2407 | |||
2408 | public function getListBuilder() |
||
2412 | |||
2413 | public function setShowBuilder(ShowBuilderInterface $showBuilder) |
||
2417 | |||
2418 | /** |
||
2419 | * @return ShowBuilderInterface |
||
2420 | */ |
||
2421 | public function getShowBuilder() |
||
2425 | |||
2426 | public function setConfigurationPool(Pool $configurationPool) |
||
2430 | |||
2431 | /** |
||
2432 | * @return Pool |
||
2433 | */ |
||
2434 | public function getConfigurationPool() |
||
2438 | |||
2439 | public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) |
||
2443 | |||
2444 | /** |
||
2445 | * @return RouteGeneratorInterface |
||
2446 | */ |
||
2447 | public function getRouteGenerator() |
||
2451 | |||
2452 | public function getCode() |
||
2456 | |||
2457 | /** |
||
2458 | * NEXT_MAJOR: Remove this function. |
||
2459 | * |
||
2460 | * @deprecated This method is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0 |
||
2461 | * |
||
2462 | * @param string $baseCodeRoute |
||
2463 | */ |
||
2464 | public function setBaseCodeRoute($baseCodeRoute) |
||
2473 | |||
2474 | public function getBaseCodeRoute() |
||
2496 | |||
2497 | public function getModelManager() |
||
2501 | |||
2502 | public function setModelManager(ModelManagerInterface $modelManager) |
||
2506 | |||
2507 | public function getManagerType() |
||
2511 | |||
2512 | /** |
||
2513 | * @param string $type |
||
2514 | */ |
||
2515 | public function setManagerType($type) |
||
2519 | |||
2520 | public function getObjectIdentifier() |
||
2524 | |||
2525 | /** |
||
2526 | * Set the roles and permissions per role. |
||
2527 | */ |
||
2528 | public function setSecurityInformation(array $information) |
||
2532 | |||
2533 | public function getSecurityInformation() |
||
2537 | |||
2538 | /** |
||
2539 | * Return the list of permissions the user should have in order to display the admin. |
||
2540 | * |
||
2541 | * @param string $context |
||
2542 | * |
||
2543 | * @return array |
||
2544 | */ |
||
2545 | public function getPermissionsShow($context) |
||
2554 | |||
2555 | public function showIn($context) |
||
2564 | |||
2565 | public function createObjectSecurity($object) |
||
2569 | |||
2570 | public function setSecurityHandler(SecurityHandlerInterface $securityHandler) |
||
2574 | |||
2575 | public function getSecurityHandler() |
||
2579 | |||
2580 | public function isGranted($name, $object = null) |
||
2591 | |||
2592 | public function getUrlSafeIdentifier($entity) |
||
2596 | |||
2597 | public function getNormalizedIdentifier($entity) |
||
2601 | |||
2602 | public function id($entity) |
||
2606 | |||
2607 | public function setValidator($validator) |
||
2618 | |||
2619 | public function getValidator() |
||
2623 | |||
2624 | public function getShow() |
||
2630 | |||
2631 | public function setFormTheme(array $formTheme) |
||
2635 | |||
2636 | public function getFormTheme() |
||
2640 | |||
2641 | public function setFilterTheme(array $filterTheme) |
||
2645 | |||
2646 | public function getFilterTheme() |
||
2650 | |||
2651 | public function addExtension(AdminExtensionInterface $extension) |
||
2655 | |||
2656 | public function getExtensions() |
||
2660 | |||
2661 | public function setMenuFactory(FactoryInterface $menuFactory) |
||
2665 | |||
2666 | public function getMenuFactory() |
||
2670 | |||
2671 | public function setRouteBuilder(RouteBuilderInterface $routeBuilder) |
||
2675 | |||
2676 | public function getRouteBuilder() |
||
2680 | |||
2681 | public function toString($object) |
||
2693 | |||
2694 | public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy) |
||
2698 | |||
2699 | public function getLabelTranslatorStrategy() |
||
2703 | |||
2704 | public function supportsPreviewMode() |
||
2708 | |||
2709 | /** |
||
2710 | * NEXT_MAJOR: Remove this. |
||
2711 | * |
||
2712 | * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. |
||
2713 | * |
||
2714 | * Set custom per page options. |
||
2715 | */ |
||
2716 | public function setPerPageOptions(array $options) |
||
2725 | |||
2726 | /** |
||
2727 | * Returns predefined per page options. |
||
2728 | * |
||
2729 | * @return array |
||
2730 | */ |
||
2731 | public function getPerPageOptions() |
||
2743 | |||
2744 | /** |
||
2745 | * Set pager type. |
||
2746 | * |
||
2747 | * @param string $pagerType |
||
2748 | */ |
||
2749 | public function setPagerType($pagerType) |
||
2753 | |||
2754 | /** |
||
2755 | * Get pager type. |
||
2756 | * |
||
2757 | * @return string |
||
2758 | */ |
||
2759 | public function getPagerType() |
||
2763 | |||
2764 | /** |
||
2765 | * Returns true if the per page value is allowed, false otherwise. |
||
2766 | * |
||
2767 | * @param int $perPage |
||
2768 | * |
||
2769 | * @return bool |
||
2770 | */ |
||
2771 | public function determinedPerPageValue($perPage) |
||
2775 | |||
2776 | public function isAclEnabled() |
||
2780 | |||
2781 | public function getObjectMetadata($object) |
||
2785 | |||
2786 | public function getListModes() |
||
2790 | |||
2791 | public function setListMode($mode) |
||
2799 | |||
2800 | public function getListMode() |
||
2808 | |||
2809 | public function getAccessMapping() |
||
2813 | |||
2814 | public function checkAccess($action, $object = null) |
||
2836 | |||
2837 | /** |
||
2838 | * Hook to handle access authorization, without throw Exception. |
||
2839 | * |
||
2840 | * @param string $action |
||
2841 | * @param object $object |
||
2842 | * |
||
2843 | * @return bool |
||
2844 | */ |
||
2845 | public function hasAccess($action, $object = null) |
||
2865 | |||
2866 | /** |
||
2867 | * @param string $action |
||
2868 | * @param object|null $object |
||
2869 | * |
||
2870 | * @return array |
||
2871 | */ |
||
2872 | public function configureActionButtons($action, $object = null) |
||
2946 | |||
2947 | /** |
||
2948 | * @param string $action |
||
2949 | * @param object $object |
||
2950 | * |
||
2951 | * @return array |
||
2952 | */ |
||
2953 | public function getActionButtons($action, $object = null) |
||
2966 | |||
2967 | /** |
||
2968 | * Get the list of actions that can be accessed directly from the dashboard. |
||
2969 | * |
||
2970 | * @return array |
||
2971 | */ |
||
2972 | public function getDashboardActions() |
||
2999 | |||
3000 | /** |
||
3001 | * Setting to true will enable mosaic button for the admin screen. |
||
3002 | * Setting to false will hide mosaic button for the admin screen. |
||
3003 | * |
||
3004 | * @param bool $isShown |
||
3005 | */ |
||
3006 | final public function showMosaicButton($isShown) |
||
3014 | |||
3015 | /** |
||
3016 | * @param object $object |
||
3017 | */ |
||
3018 | final public function getSearchResultLink($object) |
||
3028 | |||
3029 | /** |
||
3030 | * Checks if a filter type is set to a default value. |
||
3031 | * |
||
3032 | * @param string $name |
||
3033 | * |
||
3034 | * @return bool |
||
3035 | */ |
||
3036 | final public function isDefaultFilter($name) |
||
3047 | |||
3048 | /** |
||
3049 | * Check object existence and access, without throw Exception. |
||
3050 | * |
||
3051 | * @param string $action |
||
3052 | * @param object $object |
||
3053 | * |
||
3054 | * @return bool |
||
3055 | */ |
||
3056 | public function canAccessObject($action, $object) |
||
3060 | |||
3061 | protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
||
3065 | |||
3066 | /** |
||
3067 | * @return MutableTemplateRegistryInterface |
||
3068 | */ |
||
3069 | final protected function getTemplateRegistry() |
||
3073 | |||
3074 | /** |
||
3075 | * Returns a list of default sort values. |
||
3076 | * |
||
3077 | * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string} |
||
3078 | */ |
||
3079 | final protected function getDefaultSortValues(): array |
||
3094 | |||
3095 | /** |
||
3096 | * Returns a list of default filters. |
||
3097 | * |
||
3098 | * @return array |
||
3099 | */ |
||
3100 | final protected function getDefaultFilterValues() |
||
3115 | |||
3116 | protected function configureFormFields(FormMapper $form) |
||
3119 | |||
3120 | protected function configureListFields(ListMapper $list) |
||
3123 | |||
3124 | protected function configureDatagridFilters(DatagridMapper $filter) |
||
3127 | |||
3128 | protected function configureShowFields(ShowMapper $show) |
||
3131 | |||
3132 | protected function configureRoutes(RouteCollection $collection) |
||
3135 | |||
3136 | /** |
||
3137 | * Allows you to customize batch actions. |
||
3138 | * |
||
3139 | * @param array $actions List of actions |
||
3140 | * |
||
3141 | * @return array |
||
3142 | */ |
||
3143 | protected function configureBatchActions($actions) |
||
3147 | |||
3148 | /** |
||
3149 | * NEXT_MAJOR: remove this method. |
||
3150 | * |
||
3151 | * @deprecated Use configureTabMenu instead |
||
3152 | */ |
||
3153 | protected function configureSideMenu(ItemInterface $menu, $action, ?AdminInterface $childAdmin = null) |
||
3156 | |||
3157 | /** |
||
3158 | * Configures the tab menu in your admin. |
||
3159 | * |
||
3160 | * @param string $action |
||
3161 | */ |
||
3162 | protected function configureTabMenu(ItemInterface $menu, $action, ?AdminInterface $childAdmin = null) |
||
3168 | |||
3169 | /** |
||
3170 | * build the view FieldDescription array. |
||
3171 | */ |
||
3172 | protected function buildShow() |
||
3187 | |||
3188 | /** |
||
3189 | * build the list FieldDescription array. |
||
3190 | */ |
||
3191 | protected function buildList() |
||
3247 | |||
3248 | /** |
||
3249 | * Build the form FieldDescription collection. |
||
3250 | */ |
||
3251 | protected function buildForm() |
||
3284 | |||
3285 | /** |
||
3286 | * Gets the subclass corresponding to the given name. |
||
3287 | * |
||
3288 | * @param string $name The name of the sub class |
||
3289 | * |
||
3290 | * @return string the subclass |
||
3291 | */ |
||
3292 | protected function getSubClass($name) |
||
3305 | |||
3306 | /** |
||
3307 | * Attach the inline validator to the model metadata, this must be done once per admin. |
||
3308 | */ |
||
3309 | protected function attachInlineValidator() |
||
3336 | |||
3337 | /** |
||
3338 | * NEXT_MAJOR: Remove this function. |
||
3339 | * |
||
3340 | * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. |
||
3341 | * |
||
3342 | * Predefine per page options. |
||
3343 | */ |
||
3344 | protected function predefinePerPageOptions() |
||
3350 | |||
3351 | /** |
||
3352 | * Return list routes with permissions name. |
||
3353 | * |
||
3354 | * @return array<string, string> |
||
3355 | */ |
||
3356 | protected function getAccess() |
||
3381 | |||
3382 | /** |
||
3383 | * Configures a list of default filters. |
||
3384 | */ |
||
3385 | protected function configureDefaultFilterValues(array &$filterValues) |
||
3388 | |||
3389 | /** |
||
3390 | * Configures a list of default sort values. |
||
3391 | * |
||
3392 | * Example: |
||
3393 | * $sortValues['_sort_by'] = 'foo' |
||
3394 | * $sortValues['_sort_order'] = 'DESC' |
||
3395 | */ |
||
3396 | protected function configureDefaultSortValues(array &$sortValues) |
||
3399 | |||
3400 | /** |
||
3401 | * Build all the related urls to the current admin. |
||
3402 | */ |
||
3403 | private function buildRoutes(): void |
||
3426 | } |
||
3427 | |||
3429 |
If you suppress an error, we recommend checking for the error condition explicitly: