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 |
||
65 | abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface |
||
66 | { |
||
67 | public const CONTEXT_MENU = 'menu'; |
||
68 | public const CONTEXT_DASHBOARD = 'dashboard'; |
||
69 | |||
70 | public const CLASS_REGEX = |
||
71 | '@ |
||
72 | (?:([A-Za-z0-9]*)\\\)? # vendor name / app name |
||
73 | (Bundle\\\)? # optional bundle directory |
||
74 | ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix |
||
75 | ( |
||
76 | Entity|Document|Model|PHPCR|CouchDocument|Phpcr| |
||
77 | Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB |
||
78 | )\\\(.*)@x'; |
||
79 | |||
80 | public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; |
||
81 | |||
82 | /** |
||
83 | * The list FieldDescription constructed from the configureListField method. |
||
84 | * |
||
85 | * @var FieldDescriptionInterface[] |
||
86 | */ |
||
87 | protected $listFieldDescriptions = []; |
||
88 | |||
89 | /** |
||
90 | * The show FieldDescription constructed from the configureShowFields method. |
||
91 | * |
||
92 | * @var FieldDescriptionInterface[] |
||
93 | */ |
||
94 | protected $showFieldDescriptions = []; |
||
95 | |||
96 | /** |
||
97 | * The list FieldDescription constructed from the configureFormField method. |
||
98 | * |
||
99 | * @var FieldDescriptionInterface[] |
||
100 | */ |
||
101 | protected $formFieldDescriptions = []; |
||
102 | |||
103 | /** |
||
104 | * The filter FieldDescription constructed from the configureFilterField method. |
||
105 | * |
||
106 | * @var FieldDescriptionInterface[] |
||
107 | */ |
||
108 | protected $filterFieldDescriptions = []; |
||
109 | |||
110 | /** |
||
111 | * The maximum number of page numbers to display in the list. |
||
112 | * |
||
113 | * @var int |
||
114 | */ |
||
115 | protected $maxPageLinks = 25; |
||
116 | |||
117 | /** |
||
118 | * The base route name used to generate the routing information. |
||
119 | * |
||
120 | * @var string |
||
121 | */ |
||
122 | protected $baseRouteName; |
||
123 | |||
124 | /** |
||
125 | * The base route pattern used to generate the routing information. |
||
126 | * |
||
127 | * @var string |
||
128 | */ |
||
129 | protected $baseRoutePattern; |
||
130 | |||
131 | /** |
||
132 | * The base name controller used to generate the routing information. |
||
133 | * |
||
134 | * @var string |
||
135 | */ |
||
136 | protected $baseControllerName; |
||
137 | |||
138 | /** |
||
139 | * The label class name (used in the title/breadcrumb ...). |
||
140 | * |
||
141 | * @var string |
||
142 | */ |
||
143 | protected $classnameLabel; |
||
144 | |||
145 | /** |
||
146 | * The translation domain to be used to translate messages. |
||
147 | * |
||
148 | * @var string |
||
149 | */ |
||
150 | protected $translationDomain = 'messages'; |
||
151 | |||
152 | /** |
||
153 | * Options to set to the form (ie, validation_groups). |
||
154 | * |
||
155 | * @var array |
||
156 | */ |
||
157 | protected $formOptions = []; |
||
158 | |||
159 | /** |
||
160 | * Pager type. |
||
161 | * |
||
162 | * @var string |
||
163 | */ |
||
164 | protected $pagerType = Pager::TYPE_DEFAULT; |
||
165 | |||
166 | /** |
||
167 | * The code related to the admin. |
||
168 | * |
||
169 | * @var string |
||
170 | */ |
||
171 | protected $code; |
||
172 | |||
173 | /** |
||
174 | * The label. |
||
175 | * |
||
176 | * @var string |
||
177 | */ |
||
178 | protected $label; |
||
179 | |||
180 | /** |
||
181 | * Array of routes related to this admin. |
||
182 | * |
||
183 | * @var RouteCollectionInterface |
||
184 | */ |
||
185 | protected $routes; |
||
186 | |||
187 | /** |
||
188 | * The subject only set in edit/update/create mode. |
||
189 | * |
||
190 | * @var object|null |
||
191 | */ |
||
192 | protected $subject; |
||
193 | |||
194 | /** |
||
195 | * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}. |
||
196 | * |
||
197 | * @var array |
||
198 | */ |
||
199 | protected $children = []; |
||
200 | |||
201 | /** |
||
202 | * Reference the parent admin. |
||
203 | * |
||
204 | * @var AdminInterface|null |
||
205 | */ |
||
206 | protected $parent; |
||
207 | |||
208 | /** |
||
209 | * Reference the parent FieldDescription related to this admin |
||
210 | * only set for FieldDescription which is associated to an Sub Admin instance. |
||
211 | * |
||
212 | * @var FieldDescriptionInterface |
||
213 | */ |
||
214 | protected $parentFieldDescription; |
||
215 | |||
216 | /** |
||
217 | * If true then the current admin is part of the nested admin set (from the url). |
||
218 | * |
||
219 | * @var bool |
||
220 | */ |
||
221 | protected $currentChild = false; |
||
222 | |||
223 | /** |
||
224 | * The uniqid is used to avoid clashing with 2 admin related to the code |
||
225 | * ie: a Block linked to a Block. |
||
226 | * |
||
227 | * @var string |
||
228 | */ |
||
229 | protected $uniqid; |
||
230 | |||
231 | /** |
||
232 | * The Entity or Document manager. |
||
233 | * |
||
234 | * @var ModelManagerInterface |
||
235 | */ |
||
236 | protected $modelManager; |
||
237 | |||
238 | /** |
||
239 | * The current request object. |
||
240 | * |
||
241 | * @var Request|null |
||
242 | */ |
||
243 | protected $request; |
||
244 | |||
245 | /** |
||
246 | * The translator component. |
||
247 | * |
||
248 | * NEXT_MAJOR: remove this property |
||
249 | * |
||
250 | * @var TranslatorInterface |
||
251 | * |
||
252 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
253 | */ |
||
254 | protected $translator; |
||
255 | |||
256 | /** |
||
257 | * The related form contractor. |
||
258 | * |
||
259 | * @var FormContractorInterface |
||
260 | */ |
||
261 | protected $formContractor; |
||
262 | |||
263 | /** |
||
264 | * The related list builder. |
||
265 | * |
||
266 | * @var ListBuilderInterface |
||
267 | */ |
||
268 | protected $listBuilder; |
||
269 | |||
270 | /** |
||
271 | * The related view builder. |
||
272 | * |
||
273 | * @var ShowBuilderInterface |
||
274 | */ |
||
275 | protected $showBuilder; |
||
276 | |||
277 | /** |
||
278 | * The related datagrid builder. |
||
279 | * |
||
280 | * @var DatagridBuilderInterface |
||
281 | */ |
||
282 | protected $datagridBuilder; |
||
283 | |||
284 | /** |
||
285 | * @var RouteBuilderInterface |
||
286 | */ |
||
287 | protected $routeBuilder; |
||
288 | |||
289 | /** |
||
290 | * The datagrid instance. |
||
291 | * |
||
292 | * @var DatagridInterface|null |
||
293 | */ |
||
294 | protected $datagrid; |
||
295 | |||
296 | /** |
||
297 | * The router instance. |
||
298 | * |
||
299 | * @var RouteGeneratorInterface|null |
||
300 | */ |
||
301 | protected $routeGenerator; |
||
302 | |||
303 | /** |
||
304 | * @var SecurityHandlerInterface |
||
305 | */ |
||
306 | protected $securityHandler; |
||
307 | |||
308 | /** |
||
309 | * @var ValidatorInterface |
||
310 | */ |
||
311 | protected $validator; |
||
312 | |||
313 | /** |
||
314 | * The configuration pool. |
||
315 | * |
||
316 | * @var Pool |
||
317 | */ |
||
318 | protected $configurationPool; |
||
319 | |||
320 | /** |
||
321 | * @var ItemInterface |
||
322 | */ |
||
323 | protected $menu; |
||
324 | |||
325 | /** |
||
326 | * @var FactoryInterface |
||
327 | */ |
||
328 | protected $menuFactory; |
||
329 | |||
330 | /** |
||
331 | * @var array<string, bool> |
||
332 | */ |
||
333 | protected $loaded = [ |
||
334 | 'routes' => false, |
||
335 | 'tab_menu' => false, |
||
336 | 'show' => false, |
||
337 | 'list' => false, |
||
338 | 'form' => false, |
||
339 | 'datagrid' => false, |
||
340 | ]; |
||
341 | |||
342 | /** |
||
343 | * @var string[] |
||
344 | */ |
||
345 | protected $formTheme = []; |
||
346 | |||
347 | /** |
||
348 | * @var string[] |
||
349 | */ |
||
350 | protected $filterTheme = []; |
||
351 | |||
352 | /** |
||
353 | * @var AdminExtensionInterface[] |
||
354 | */ |
||
355 | protected $extensions = []; |
||
356 | |||
357 | /** |
||
358 | * @var LabelTranslatorStrategyInterface |
||
359 | */ |
||
360 | protected $labelTranslatorStrategy; |
||
361 | |||
362 | /** |
||
363 | * Setting to true will enable preview mode for |
||
364 | * the entity and show a preview button in the |
||
365 | * edit/create forms. |
||
366 | * |
||
367 | * @var bool |
||
368 | */ |
||
369 | protected $supportsPreviewMode = false; |
||
370 | |||
371 | /** |
||
372 | * Roles and permissions per role. |
||
373 | * |
||
374 | * @var array 'role' => ['permission', 'permission'] |
||
375 | */ |
||
376 | protected $securityInformation = []; |
||
377 | |||
378 | protected $cacheIsGranted = []; |
||
379 | |||
380 | /** |
||
381 | * Action list for the search result. |
||
382 | * |
||
383 | * @var string[] |
||
384 | */ |
||
385 | protected $searchResultActions = ['edit', 'show']; |
||
386 | |||
387 | protected $listModes = [ |
||
388 | 'list' => [ |
||
389 | 'class' => 'fa fa-list fa-fw', |
||
390 | ], |
||
391 | 'mosaic' => [ |
||
392 | 'class' => self::MOSAIC_ICON_CLASS, |
||
393 | ], |
||
394 | ]; |
||
395 | |||
396 | /** |
||
397 | * The Access mapping. |
||
398 | * |
||
399 | * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]] |
||
400 | */ |
||
401 | protected $accessMapping = []; |
||
402 | |||
403 | /** |
||
404 | * @var array |
||
405 | */ |
||
406 | private $parentAssociationMapping = []; |
||
407 | |||
408 | /** |
||
409 | * @var MutableTemplateRegistryInterface |
||
410 | */ |
||
411 | private $templateRegistry; |
||
412 | |||
413 | /** |
||
414 | * The class name managed by the admin class. |
||
415 | * |
||
416 | * @var string |
||
417 | */ |
||
418 | private $class; |
||
419 | |||
420 | /** |
||
421 | * The subclasses supported by the admin class. |
||
422 | * |
||
423 | * @var array<string, string> |
||
424 | */ |
||
425 | private $subClasses = []; |
||
426 | |||
427 | /** |
||
428 | * The list collection. |
||
429 | * |
||
430 | * @var FieldDescriptionCollection|null |
||
431 | */ |
||
432 | private $list; |
||
433 | |||
434 | /** |
||
435 | * @var FieldDescriptionCollection|null |
||
436 | */ |
||
437 | private $show; |
||
438 | |||
439 | /** |
||
440 | * @var FormInterface|null |
||
441 | */ |
||
442 | private $form; |
||
443 | |||
444 | /** |
||
445 | * The cached base route name. |
||
446 | * |
||
447 | * @var string |
||
448 | */ |
||
449 | private $cachedBaseRouteName; |
||
450 | |||
451 | /** |
||
452 | * The cached base route pattern. |
||
453 | * |
||
454 | * @var string |
||
455 | */ |
||
456 | private $cachedBaseRoutePattern; |
||
457 | |||
458 | /** |
||
459 | * The form group disposition. |
||
460 | * |
||
461 | * @var array<string, mixed> |
||
462 | */ |
||
463 | private $formGroups = []; |
||
464 | |||
465 | /** |
||
466 | * The form tabs disposition. |
||
467 | * |
||
468 | * @var array<string, mixed> |
||
469 | */ |
||
470 | private $formTabs = []; |
||
471 | |||
472 | /** |
||
473 | * The view group disposition. |
||
474 | * |
||
475 | * @var array<string, mixed> |
||
476 | */ |
||
477 | private $showGroups = []; |
||
478 | |||
479 | /** |
||
480 | * The view tab disposition. |
||
481 | * |
||
482 | * @var array<string, mixed> |
||
483 | */ |
||
484 | private $showTabs = []; |
||
485 | |||
486 | /** |
||
487 | * The manager type to use for the admin. |
||
488 | * |
||
489 | * @var string |
||
490 | */ |
||
491 | private $managerType; |
||
492 | |||
493 | /** |
||
494 | * Component responsible for persisting filters. |
||
495 | * |
||
496 | * @var FilterPersisterInterface|null |
||
497 | */ |
||
498 | private $filterPersister; |
||
499 | |||
500 | public function __construct(string $code, string $class, ?string $baseControllerName = null) |
||
506 | |||
507 | /** |
||
508 | * {@inheritdoc} |
||
509 | */ |
||
510 | public function getExportFormats(): array |
||
516 | |||
517 | /** |
||
518 | * {@inheritdoc} |
||
519 | */ |
||
520 | public function getExportFields(): array |
||
532 | |||
533 | public function getDataSourceIterator(): SourceIteratorInterface |
||
559 | |||
560 | /** |
||
561 | * define custom variable. |
||
562 | */ |
||
563 | public function initialize(): void |
||
571 | |||
572 | public function update(object $object): object |
||
592 | |||
593 | public function create(object $object): object |
||
615 | |||
616 | public function delete(object $object): void |
||
631 | |||
632 | public function preValidate(object $object): void |
||
635 | |||
636 | public function preUpdate(object $object): void |
||
639 | |||
640 | public function postUpdate(object $object): void |
||
643 | |||
644 | public function prePersist(object $object): void |
||
647 | |||
648 | public function postPersist(object $object): void |
||
651 | |||
652 | public function preRemove(object $object): void |
||
655 | |||
656 | public function postRemove(object $object): void |
||
659 | |||
660 | public function preBatchAction(string $actionName, ProxyQueryInterface $query, array &$idx, bool $allElements = false): void |
||
663 | |||
664 | public function getFilterParameters(): array |
||
714 | |||
715 | /** |
||
716 | * Returns the name of the parent related field, so the field can be use to set the default |
||
717 | * value (ie the parent object) or to filter the object. |
||
718 | * |
||
719 | * @throws \InvalidArgumentException |
||
720 | */ |
||
721 | public function getParentAssociationMapping(): ?string |
||
739 | |||
740 | final public function addParentAssociationMapping(string $code, string $value): void |
||
744 | |||
745 | /** |
||
746 | * Returns the baseRoutePattern used to generate the routing information. |
||
747 | * |
||
748 | * @throws \RuntimeException |
||
749 | * |
||
750 | * @return string the baseRoutePattern used to generate the routing information |
||
751 | */ |
||
752 | public function getBaseRoutePattern(): string |
||
800 | |||
801 | /** |
||
802 | * Returns the baseRouteName used to generate the routing information. |
||
803 | * |
||
804 | * @throws \RuntimeException |
||
805 | * |
||
806 | * @return string the baseRouteName used to generate the routing information |
||
807 | */ |
||
808 | public function getBaseRouteName(): string |
||
857 | |||
858 | public function getClass(): string |
||
859 | { |
||
860 | if ($this->hasActiveSubClass()) { |
||
861 | if ($this->hasParentFieldDescription()) { |
||
862 | throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass'); |
||
863 | } |
||
864 | |||
865 | $subClass = $this->getRequest()->query->get('subclass'); |
||
866 | |||
867 | if (!$this->hasSubClass($subClass)) { |
||
868 | throw new \RuntimeException(sprintf('Subclass "%s" is not defined.', $subClass)); |
||
869 | } |
||
870 | |||
871 | return $this->getSubClass($subClass); |
||
872 | } |
||
873 | |||
874 | // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 |
||
875 | if ($this->subject && \is_object($this->subject)) { |
||
876 | return ClassUtils::getClass($this->subject); |
||
877 | } |
||
878 | |||
879 | return $this->class; |
||
880 | } |
||
881 | |||
882 | public function getSubClasses(): array |
||
883 | { |
||
884 | return $this->subClasses; |
||
885 | } |
||
886 | |||
887 | public function setSubClasses(array $subClasses): void |
||
888 | { |
||
889 | $this->subClasses = $subClasses; |
||
890 | } |
||
891 | |||
892 | public function hasSubClass(string $name): bool |
||
893 | { |
||
894 | return isset($this->subClasses[$name]); |
||
895 | } |
||
896 | |||
897 | public function hasActiveSubClass(): bool |
||
898 | { |
||
899 | if (\count($this->subClasses) > 0 && $this->request) { |
||
900 | return null !== $this->getRequest()->query->get('subclass'); |
||
901 | } |
||
902 | |||
903 | return false; |
||
904 | } |
||
905 | |||
906 | public function getActiveSubClass(): string |
||
907 | { |
||
908 | if (!$this->hasActiveSubClass()) { |
||
909 | throw new \LogicException(sprintf( |
||
910 | 'Admin "%s" has no active subclass.', |
||
911 | static::class |
||
912 | )); |
||
913 | } |
||
914 | |||
915 | return $this->getSubClass($this->getActiveSubclassCode()); |
||
916 | } |
||
917 | |||
918 | public function getActiveSubclassCode(): string |
||
919 | { |
||
920 | if (!$this->hasActiveSubClass()) { |
||
921 | throw new \LogicException(sprintf( |
||
922 | 'Admin "%s" has no active subclass.', |
||
923 | static::class |
||
924 | )); |
||
925 | } |
||
926 | |||
927 | $subClass = $this->getRequest()->query->get('subclass'); |
||
928 | |||
929 | if (!$this->hasSubClass($subClass)) { |
||
930 | throw new \LogicException(sprintf( |
||
931 | 'Admin "%s" has no active subclass.', |
||
932 | static::class |
||
933 | )); |
||
934 | } |
||
935 | |||
936 | return $subClass; |
||
937 | } |
||
938 | |||
939 | public function getBatchActions(): array |
||
940 | { |
||
941 | $actions = []; |
||
942 | |||
943 | if ($this->hasRoute('delete') && $this->hasAccess('delete')) { |
||
944 | $actions['delete'] = [ |
||
945 | 'label' => 'action_delete', |
||
946 | 'translation_domain' => 'SonataAdminBundle', |
||
947 | 'ask_confirmation' => true, // by default always true |
||
948 | ]; |
||
949 | } |
||
950 | |||
951 | $actions = $this->configureBatchActions($actions); |
||
952 | |||
953 | foreach ($this->getExtensions() as $extension) { |
||
954 | $actions = $extension->configureBatchActions($this, $actions); |
||
955 | } |
||
956 | |||
957 | foreach ($actions as $name => &$action) { |
||
958 | if (!\array_key_exists('label', $action)) { |
||
959 | $action['label'] = $this->getTranslationLabel($name, 'batch', 'label'); |
||
960 | } |
||
961 | |||
962 | if (!\array_key_exists('translation_domain', $action)) { |
||
963 | $action['translation_domain'] = $this->getTranslationDomain(); |
||
964 | } |
||
965 | } |
||
966 | |||
967 | return $actions; |
||
968 | } |
||
969 | |||
970 | public function getRoutes(): RouteCollectionInterface |
||
971 | { |
||
972 | $this->buildRoutes(); |
||
973 | |||
974 | return $this->routes; |
||
975 | } |
||
976 | |||
977 | public function getRouterIdParameter(): string |
||
978 | { |
||
979 | return sprintf('{%s}', $this->getIdParameter()); |
||
980 | } |
||
981 | |||
982 | public function getIdParameter(): string |
||
983 | { |
||
984 | $parameter = 'id'; |
||
985 | |||
986 | for ($i = 0; $i < $this->getChildDepth(); ++$i) { |
||
987 | $parameter = sprintf('child%s', ucfirst($parameter)); |
||
988 | } |
||
989 | |||
990 | return $parameter; |
||
991 | } |
||
992 | |||
993 | public function hasRoute(string $name): bool |
||
994 | { |
||
995 | if (!$this->routeGenerator) { |
||
996 | throw new \RuntimeException('RouteGenerator cannot be null'); |
||
997 | } |
||
998 | |||
999 | return $this->routeGenerator->hasAdminRoute($this, $name); |
||
1000 | } |
||
1001 | |||
1002 | public function isCurrentRoute(string $name, ?string $adminCode = null): bool |
||
1003 | { |
||
1004 | if (!$this->hasRequest()) { |
||
1005 | return false; |
||
1006 | } |
||
1007 | |||
1008 | $request = $this->getRequest(); |
||
1009 | $route = $request->get('_route'); |
||
1010 | |||
1011 | if ($adminCode) { |
||
1012 | $pool = $this->getConfigurationPool(); |
||
1013 | |||
1014 | if ($pool->hasAdminByAdminCode($adminCode)) { |
||
1015 | $admin = $pool->getAdminByAdminCode($adminCode); |
||
1016 | } else { |
||
1017 | return false; |
||
1018 | } |
||
1019 | } else { |
||
1020 | $admin = $this; |
||
1021 | } |
||
1022 | |||
1023 | return sprintf('%s_%s', $admin->getBaseRouteName(), $name) === $route; |
||
1024 | } |
||
1025 | |||
1026 | public function generateObjectUrl(string $name, object $object, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string |
||
1027 | { |
||
1028 | $parameters['id'] = $this->getUrlSafeIdentifier($object); |
||
1029 | |||
1030 | return $this->generateUrl($name, $parameters, $referenceType); |
||
1031 | } |
||
1032 | |||
1033 | public function generateUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string |
||
1034 | { |
||
1035 | return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); |
||
1036 | } |
||
1037 | |||
1038 | public function generateMenuUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): array |
||
1039 | { |
||
1040 | return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); |
||
1041 | } |
||
1042 | |||
1043 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void |
||
1044 | { |
||
1045 | $this->templateRegistry = $templateRegistry; |
||
1046 | } |
||
1047 | |||
1048 | /** |
||
1049 | * @param array<string, string> $templates |
||
1050 | */ |
||
1051 | public function setTemplates(array $templates): void |
||
1055 | |||
1056 | /** |
||
1057 | * {@inheritdoc} |
||
1058 | */ |
||
1059 | public function setTemplate(string $name, string $template): void |
||
1060 | { |
||
1061 | $this->getTemplateRegistry()->setTemplate($name, $template); |
||
1062 | } |
||
1063 | |||
1064 | public function getNewInstance(): object |
||
1065 | { |
||
1066 | $object = $this->getModelManager()->getModelInstance($this->getClass()); |
||
1067 | |||
1068 | $this->appendParentObject($object); |
||
1069 | |||
1070 | foreach ($this->getExtensions() as $extension) { |
||
1071 | $extension->alterNewInstance($this, $object); |
||
1072 | } |
||
1073 | |||
1076 | |||
1077 | public function getFormBuilder(): FormBuilderInterface |
||
1090 | |||
1091 | /** |
||
1092 | * This method is being called by the main admin class and the child class, |
||
1093 | * the getFormBuilder is only call by the main admin class. |
||
1094 | */ |
||
1095 | public function defineFormBuilder(FormBuilderInterface $formBuilder): void |
||
1112 | |||
1113 | public function attachAdminClass(FieldDescriptionInterface $fieldDescription): void |
||
1141 | |||
1142 | public function getObject($id): ?object |
||
1151 | |||
1152 | public function getForm(): ?FormInterface |
||
1158 | |||
1159 | public function getList(): ?FieldDescriptionCollection |
||
1165 | |||
1166 | final public function createQuery(): ProxyQueryInterface |
||
1177 | |||
1178 | public function getDatagrid(): DatagridInterface |
||
1184 | |||
1185 | public function buildTabMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface |
||
1212 | |||
1213 | public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface |
||
1223 | |||
1224 | public function getRootCode(): string |
||
1228 | |||
1229 | public function getRoot(): AdminInterface |
||
1237 | |||
1238 | public function setBaseControllerName(string $baseControllerName): void |
||
1242 | |||
1243 | public function getBaseControllerName(): string |
||
1247 | |||
1248 | public function setLabel(?string $label): void |
||
1252 | |||
1253 | public function getLabel(): ?string |
||
1257 | |||
1258 | public function setFilterPersister(?FilterPersisterInterface $filterPersister = null): void |
||
1262 | |||
1263 | public function getMaxPerPage(): int |
||
1269 | |||
1270 | public function setMaxPageLinks(int $maxPageLinks): void |
||
1274 | |||
1275 | public function getMaxPageLinks(): int |
||
1279 | |||
1280 | public function getFormGroups(): array |
||
1284 | |||
1285 | public function setFormGroups(array $formGroups): void |
||
1289 | |||
1290 | public function removeFieldFromFormGroup(string $key): void |
||
1300 | |||
1301 | public function reorderFormGroup(string $group, array $keys): void |
||
1307 | |||
1308 | public function getFormTabs(): array |
||
1312 | |||
1313 | public function setFormTabs(array $formTabs): void |
||
1317 | |||
1318 | public function getShowTabs(): array |
||
1322 | |||
1323 | public function setShowTabs(array $showTabs): void |
||
1327 | |||
1328 | public function getShowGroups(): array |
||
1332 | |||
1333 | public function setShowGroups(array $showGroups): void |
||
1337 | |||
1338 | public function reorderShowGroup(string $group, array $keys): void |
||
1344 | |||
1345 | public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription): void |
||
1349 | |||
1350 | public function getParentFieldDescription(): FieldDescriptionInterface |
||
1361 | |||
1362 | public function hasParentFieldDescription(): bool |
||
1366 | |||
1367 | public function setSubject(?object $subject): void |
||
1380 | |||
1381 | public function getSubject(): object |
||
1392 | |||
1393 | public function hasSubject(): bool |
||
1405 | |||
1406 | public function getFormFieldDescriptions(): array |
||
1412 | |||
1413 | public function getFormFieldDescription(string $name): FieldDescriptionInterface |
||
1427 | |||
1428 | /** |
||
1429 | * Returns true if the admin has a FieldDescription with the given $name. |
||
1430 | */ |
||
1431 | public function hasFormFieldDescription(string $name): bool |
||
1437 | |||
1438 | public function addFormFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
1442 | |||
1443 | /** |
||
1444 | * remove a FieldDescription. |
||
1445 | */ |
||
1446 | public function removeFormFieldDescription(string $name): void |
||
1450 | |||
1451 | /** |
||
1452 | * build and return the collection of form FieldDescription. |
||
1453 | * |
||
1454 | * @return FieldDescriptionInterface[] collection of form FieldDescription |
||
1455 | */ |
||
1456 | public function getShowFieldDescriptions(): array |
||
1462 | |||
1463 | /** |
||
1464 | * Returns the form FieldDescription with the given $name. |
||
1465 | */ |
||
1466 | public function getShowFieldDescription(string $name): FieldDescriptionInterface |
||
1480 | |||
1481 | public function hasShowFieldDescription(string $name): bool |
||
1487 | |||
1488 | public function addShowFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
1492 | |||
1493 | public function removeShowFieldDescription(string $name): void |
||
1497 | |||
1498 | public function getListFieldDescriptions(): array |
||
1504 | |||
1505 | public function getListFieldDescription(string $name): FieldDescriptionInterface |
||
1519 | |||
1520 | public function hasListFieldDescription(string $name): bool |
||
1526 | |||
1527 | public function addListFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
1531 | |||
1532 | public function removeListFieldDescription(string $name): void |
||
1536 | |||
1537 | public function getFilterFieldDescription(string $name): FieldDescriptionInterface |
||
1551 | |||
1552 | public function hasFilterFieldDescription(string $name): bool |
||
1558 | |||
1559 | public function addFilterFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
1563 | |||
1564 | public function removeFilterFieldDescription(string $name): void |
||
1568 | |||
1569 | public function getFilterFieldDescriptions(): array |
||
1575 | |||
1576 | public function addChild(AdminInterface $child, string $field): void |
||
1596 | |||
1597 | public function hasChild(string $code): bool |
||
1601 | |||
1602 | public function getChildren(): array |
||
1606 | |||
1607 | public function getChild(string $code): AdminInterface |
||
1619 | |||
1620 | public function setParent(AdminInterface $parent): void |
||
1624 | |||
1625 | public function getParent(): AdminInterface |
||
1636 | |||
1637 | final public function getRootAncestor(): AdminInterface |
||
1647 | |||
1648 | final public function getChildDepth(): int |
||
1660 | |||
1661 | final public function getCurrentLeafChildAdmin(): ?AdminInterface |
||
1675 | |||
1676 | public function isChild(): bool |
||
1680 | |||
1681 | /** |
||
1682 | * Returns true if the admin has children, false otherwise. |
||
1683 | */ |
||
1684 | public function hasChildren(): bool |
||
1688 | |||
1689 | public function setUniqid(string $uniqid): void |
||
1693 | |||
1694 | public function getUniqid(): string |
||
1702 | |||
1703 | /** |
||
1704 | * {@inheritdoc} |
||
1705 | */ |
||
1706 | public function getClassnameLabel(): string |
||
1710 | |||
1711 | public function getPersistentParameters(): array |
||
1723 | |||
1724 | /** |
||
1725 | * {@inheritdoc} |
||
1726 | */ |
||
1727 | public function getPersistentParameter(string $name) |
||
1733 | |||
1734 | public function setCurrentChild(bool $currentChild): void |
||
1738 | |||
1739 | public function isCurrentChild(): bool |
||
1743 | |||
1744 | /** |
||
1745 | * Returns the current child admin instance. |
||
1746 | * |
||
1747 | * @return AdminInterface|null the current child admin instance |
||
1748 | */ |
||
1749 | public function getCurrentChildAdmin(): ?AdminInterface |
||
1759 | |||
1760 | public function setTranslationDomain(string $translationDomain): void |
||
1764 | |||
1765 | public function getTranslationDomain(): string |
||
1769 | |||
1770 | /** |
||
1771 | * {@inheritdoc} |
||
1772 | * |
||
1773 | * NEXT_MAJOR: remove this method |
||
1774 | * |
||
1775 | * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 |
||
1776 | */ |
||
1777 | public function setTranslator(TranslatorInterface $translator): void |
||
1789 | |||
1790 | public function getTranslationLabel(string $label, string $context = '', string $type = ''): string |
||
1794 | |||
1795 | public function setRequest(Request $request): void |
||
1803 | |||
1804 | public function getRequest(): Request |
||
1812 | |||
1813 | public function hasRequest(): bool |
||
1817 | |||
1818 | public function setFormContractor(FormContractorInterface $formBuilder): void |
||
1822 | |||
1823 | public function getFormContractor(): ?FormContractorInterface |
||
1827 | |||
1828 | public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder): void |
||
1832 | |||
1833 | public function getDatagridBuilder(): ?DatagridBuilderInterface |
||
1837 | |||
1838 | public function setListBuilder(ListBuilderInterface $listBuilder): void |
||
1842 | |||
1843 | public function getListBuilder(): ?ListBuilderInterface |
||
1847 | |||
1848 | public function setShowBuilder(?ShowBuilderInterface $showBuilder): void |
||
1852 | |||
1853 | public function getShowBuilder(): ?ShowBuilderInterface |
||
1857 | |||
1858 | public function setConfigurationPool(Pool $configurationPool): void |
||
1862 | |||
1863 | public function getConfigurationPool(): ?Pool |
||
1867 | |||
1868 | public function setRouteGenerator(RouteGeneratorInterface $routeGenerator): void |
||
1872 | |||
1873 | public function getRouteGenerator(): ?RouteGeneratorInterface |
||
1877 | |||
1878 | public function getCode(): string |
||
1882 | |||
1883 | public function getBaseCodeRoute(): string |
||
1891 | |||
1892 | public function getModelManager(): ?ModelManagerInterface |
||
1896 | |||
1897 | public function setModelManager(?ModelManagerInterface $modelManager): void |
||
1901 | |||
1902 | public function getManagerType(): ?string |
||
1906 | |||
1907 | public function setManagerType(?string $type): void |
||
1911 | |||
1912 | public function getObjectIdentifier() |
||
1916 | |||
1917 | /** |
||
1918 | * Set the roles and permissions per role. |
||
1919 | */ |
||
1920 | public function setSecurityInformation(array $information): void |
||
1924 | |||
1925 | public function getSecurityInformation(): array |
||
1929 | |||
1930 | /** |
||
1931 | * Return the list of permissions the user should have in order to display the admin. |
||
1932 | */ |
||
1933 | public function getPermissionsShow(string $context): array |
||
1942 | |||
1943 | public function showIn(string $context): bool |
||
1947 | |||
1948 | public function createObjectSecurity(object $object): void |
||
1952 | |||
1953 | public function setSecurityHandler(SecurityHandlerInterface $securityHandler): void |
||
1957 | |||
1958 | public function getSecurityHandler(): ?SecurityHandlerInterface |
||
1962 | |||
1963 | public function isGranted($name, ?object $object = null): bool |
||
1974 | |||
1975 | public function getUrlSafeIdentifier(object $model): ?string |
||
1979 | |||
1980 | public function getNormalizedIdentifier(object $model): ?string |
||
1984 | |||
1985 | public function id(object $model): ?string |
||
1989 | |||
1990 | public function setValidator(ValidatorInterface $validator): void |
||
1994 | |||
1995 | public function getValidator(): ?ValidatorInterface |
||
1999 | |||
2000 | public function getShow(): ?FieldDescriptionCollection |
||
2006 | |||
2007 | public function setFormTheme(array $formTheme): void |
||
2011 | |||
2012 | public function getFormTheme(): array |
||
2016 | |||
2017 | public function setFilterTheme(array $filterTheme): void |
||
2021 | |||
2022 | public function getFilterTheme(): array |
||
2026 | |||
2027 | public function addExtension(AdminExtensionInterface $extension): void |
||
2031 | |||
2032 | public function getExtensions(): array |
||
2036 | |||
2037 | public function setMenuFactory(FactoryInterface $menuFactory): void |
||
2041 | |||
2042 | public function getMenuFactory(): ?FactoryInterface |
||
2046 | |||
2047 | public function setRouteBuilder(RouteBuilderInterface $routeBuilder): void |
||
2051 | |||
2052 | public function getRouteBuilder(): ?RouteBuilderInterface |
||
2056 | |||
2057 | public function toString(object $object): string |
||
2065 | |||
2066 | public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy): void |
||
2070 | |||
2071 | public function getLabelTranslatorStrategy(): ?LabelTranslatorStrategyInterface |
||
2075 | |||
2076 | public function supportsPreviewMode(): bool |
||
2080 | |||
2081 | /** |
||
2082 | * Returns predefined per page options. |
||
2083 | */ |
||
2084 | public function getPerPageOptions(): array |
||
2094 | |||
2095 | /** |
||
2096 | * Set pager type. |
||
2097 | */ |
||
2098 | public function setPagerType(string $pagerType): void |
||
2102 | |||
2103 | /** |
||
2104 | * Get pager type. |
||
2105 | */ |
||
2106 | public function getPagerType(): string |
||
2110 | |||
2111 | /** |
||
2112 | * Returns true if the per page value is allowed, false otherwise. |
||
2113 | */ |
||
2114 | public function determinedPerPageValue(int $perPage): bool |
||
2118 | |||
2119 | public function isAclEnabled(): bool |
||
2123 | |||
2124 | public function getObjectMetadata(object $object): MetadataInterface |
||
2128 | |||
2129 | public function getListModes(): array |
||
2133 | |||
2134 | public function setListMode(string $mode): void |
||
2142 | |||
2143 | public function getListMode(): string |
||
2151 | |||
2152 | public function getAccessMapping(): array |
||
2156 | |||
2157 | public function checkAccess(string $action, ?object $object = null): void |
||
2179 | |||
2180 | /** |
||
2181 | * {@inheritdoc} |
||
2182 | */ |
||
2183 | public function hasAccess(string $action, ?object $object = null): bool |
||
2203 | |||
2204 | final public function getActionButtons(string $action, ?object $object = null): array |
||
2272 | |||
2273 | /** |
||
2274 | * {@inheritdoc} |
||
2275 | */ |
||
2276 | public function getDashboardActions(): array |
||
2301 | |||
2302 | /** |
||
2303 | * {@inheritdoc} |
||
2304 | */ |
||
2305 | final public function showMosaicButton($isShown): void |
||
2313 | |||
2314 | final public function getSearchResultLink(object $object): ?string |
||
2324 | |||
2325 | public function canAccessObject(string $action, ?object $object = null): bool |
||
2336 | |||
2337 | public function configureActionButtons(array $buttonList, string $action, ?object $object = null): array |
||
2341 | |||
2342 | /** |
||
2343 | * Hook to run after initialization. |
||
2344 | */ |
||
2345 | protected function configure(): void |
||
2348 | |||
2349 | protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
||
2353 | |||
2354 | /** |
||
2355 | * urlize the given word. |
||
2356 | * |
||
2357 | * @param string $sep the separator |
||
2358 | */ |
||
2359 | final protected function urlize(string $word, string $sep = '_'): string |
||
2363 | |||
2364 | final protected function getTemplateRegistry(): MutableTemplateRegistryInterface |
||
2368 | |||
2369 | /** |
||
2370 | * Returns a list of default sort values. |
||
2371 | * |
||
2372 | * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string} |
||
2373 | */ |
||
2374 | final protected function getDefaultSortValues(): array |
||
2386 | |||
2387 | /** |
||
2388 | * Returns a list of default filters. |
||
2389 | */ |
||
2390 | final protected function getDefaultFilterValues(): array |
||
2402 | |||
2403 | protected function configureFormFields(FormMapper $form): void |
||
2406 | |||
2407 | protected function configureListFields(ListMapper $list): void |
||
2410 | |||
2411 | protected function configureDatagridFilters(DatagridMapper $filter): void |
||
2414 | |||
2415 | protected function configureShowFields(ShowMapper $show): void |
||
2418 | |||
2419 | protected function configureRoutes(RouteCollectionInterface $collection): void |
||
2422 | |||
2423 | /** |
||
2424 | * Allows you to customize batch actions. |
||
2425 | * |
||
2426 | * @param array $actions List of actions |
||
2427 | */ |
||
2428 | protected function configureBatchActions(array $actions): array |
||
2432 | |||
2433 | /** |
||
2434 | * Configures the tab menu in your admin. |
||
2435 | */ |
||
2436 | protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminInterface $childAdmin = null): void |
||
2439 | |||
2440 | /** |
||
2441 | * build the view FieldDescription array. |
||
2442 | */ |
||
2443 | protected function buildShow(): void |
||
2460 | |||
2461 | /** |
||
2462 | * build the list FieldDescription array. |
||
2463 | */ |
||
2464 | protected function buildList(): void |
||
2517 | |||
2518 | /** |
||
2519 | * Build the form FieldDescription collection. |
||
2520 | */ |
||
2521 | protected function buildForm(): void |
||
2536 | |||
2537 | /** |
||
2538 | * Gets the subclass corresponding to the given name. |
||
2539 | * |
||
2540 | * @param string $name The name of the sub class |
||
2541 | * |
||
2542 | * @return string the subclass |
||
2543 | */ |
||
2544 | protected function getSubClass(string $name): string |
||
2552 | |||
2553 | /** |
||
2554 | * Return list routes with permissions name. |
||
2555 | * |
||
2556 | * @return array<string, string|array> |
||
2557 | */ |
||
2558 | protected function getAccess(): array |
||
2580 | |||
2581 | /** |
||
2582 | * Configures a list of default filters. |
||
2583 | */ |
||
2584 | protected function configureDefaultFilterValues(array &$filterValues): void |
||
2587 | |||
2588 | /** |
||
2589 | * Configures a list of default sort values. |
||
2590 | * |
||
2591 | * Example: |
||
2592 | * $sortValues['_sort_by'] = 'foo' |
||
2593 | * $sortValues['_sort_order'] = 'DESC' |
||
2594 | */ |
||
2595 | protected function configureDefaultSortValues(array &$sortValues) |
||
2598 | |||
2599 | /** |
||
2600 | * Set the parent object, if any, to the provided object. |
||
2601 | */ |
||
2602 | final protected function appendParentObject(object $object): void |
||
2630 | |||
2631 | /** |
||
2632 | * {@inheritdoc} |
||
2633 | */ |
||
2634 | private function buildDatagrid(): void |
||
2688 | |||
2689 | /** |
||
2690 | * Build all the related urls to the current admin. |
||
2691 | */ |
||
2692 | private function buildRoutes(): void |
||
2715 | } |
||
2716 |
This property has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.