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 | ||
| 64 | abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface | ||
| 65 | { | ||
| 66 | public const CONTEXT_MENU = 'menu'; | ||
| 67 | public const CONTEXT_DASHBOARD = 'dashboard'; | ||
| 68 | |||
| 69 | public const CLASS_REGEX = | ||
| 70 | '@ | ||
| 71 | (?:([A-Za-z0-9]*)\\\)? # vendor name / app name | ||
| 72 | (Bundle\\\)? # optional bundle directory | ||
| 73 | ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix | ||
| 74 | ( | ||
| 75 | Entity|Document|Model|PHPCR|CouchDocument|Phpcr| | ||
| 76 | Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB | ||
| 77 | )\\\(.*)@x'; | ||
| 78 | |||
| 79 | public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; | ||
| 80 | |||
| 81 | /** | ||
| 82 | * The list FieldDescription constructed from the configureListField method. | ||
| 83 | * | ||
| 84 | * @var FieldDescriptionInterface[] | ||
| 85 | */ | ||
| 86 | protected $listFieldDescriptions = []; | ||
| 87 | |||
| 88 | /** | ||
| 89 | * The show FieldDescription constructed from the configureShowFields method. | ||
| 90 | * | ||
| 91 | * @var FieldDescriptionInterface[] | ||
| 92 | */ | ||
| 93 | protected $showFieldDescriptions = []; | ||
| 94 | |||
| 95 | /** | ||
| 96 | * The list FieldDescription constructed from the configureFormField method. | ||
| 97 | * | ||
| 98 | * @var FieldDescriptionInterface[] | ||
| 99 | */ | ||
| 100 | protected $formFieldDescriptions = []; | ||
| 101 | |||
| 102 | /** | ||
| 103 | * The filter FieldDescription constructed from the configureFilterField method. | ||
| 104 | * | ||
| 105 | * @var FieldDescriptionInterface[] | ||
| 106 | */ | ||
| 107 | protected $filterFieldDescriptions = []; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * The maximum number of page numbers to display in the list. | ||
| 111 | * | ||
| 112 | * @var int | ||
| 113 | */ | ||
| 114 | protected $maxPageLinks = 25; | ||
| 115 | |||
| 116 | /** | ||
| 117 | * The base route name used to generate the routing information. | ||
| 118 | * | ||
| 119 | * @var string | ||
| 120 | */ | ||
| 121 | protected $baseRouteName; | ||
| 122 | |||
| 123 | /** | ||
| 124 | * The base route pattern used to generate the routing information. | ||
| 125 | * | ||
| 126 | * @var string | ||
| 127 | */ | ||
| 128 | protected $baseRoutePattern; | ||
| 129 | |||
| 130 | /** | ||
| 131 | * The base name controller used to generate the routing information. | ||
| 132 | * | ||
| 133 | * @var string | ||
| 134 | */ | ||
| 135 | protected $baseControllerName; | ||
| 136 | |||
| 137 | /** | ||
| 138 | * The label class name (used in the title/breadcrumb ...). | ||
| 139 | * | ||
| 140 | * @var string | ||
| 141 | */ | ||
| 142 | protected $classnameLabel; | ||
| 143 | |||
| 144 | /** | ||
| 145 | * The translation domain to be used to translate messages. | ||
| 146 | * | ||
| 147 | * @var string | ||
| 148 | */ | ||
| 149 | protected $translationDomain = 'messages'; | ||
| 150 | |||
| 151 | /** | ||
| 152 | * Options to set to the form (ie, validation_groups). | ||
| 153 | * | ||
| 154 | * @var array | ||
| 155 | */ | ||
| 156 | protected $formOptions = []; | ||
| 157 | |||
| 158 | /** | ||
| 159 | * Pager type. | ||
| 160 | * | ||
| 161 | * @var string | ||
| 162 | */ | ||
| 163 | protected $pagerType = Pager::TYPE_DEFAULT; | ||
| 164 | |||
| 165 | /** | ||
| 166 | * The code related to the admin. | ||
| 167 | * | ||
| 168 | * @var string | ||
| 169 | */ | ||
| 170 | protected $code; | ||
| 171 | |||
| 172 | /** | ||
| 173 | * The label. | ||
| 174 | * | ||
| 175 | * @var string | ||
| 176 | */ | ||
| 177 | protected $label; | ||
| 178 | |||
| 179 | /** | ||
| 180 | * Array of routes related to this admin. | ||
| 181 | * | ||
| 182 | * @var RouteCollectionInterface | ||
| 183 | */ | ||
| 184 | protected $routes; | ||
| 185 | |||
| 186 | /** | ||
| 187 | * The subject only set in edit/update/create mode. | ||
| 188 | * | ||
| 189 | * @var object|null | ||
| 190 | */ | ||
| 191 | protected $subject; | ||
| 192 | |||
| 193 | /** | ||
| 194 |      * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}. | ||
| 195 | * | ||
| 196 | * @var array | ||
| 197 | */ | ||
| 198 | protected $children = []; | ||
| 199 | |||
| 200 | /** | ||
| 201 | * Reference the parent admin. | ||
| 202 | * | ||
| 203 | * @var AdminInterface|null | ||
| 204 | */ | ||
| 205 | protected $parent; | ||
| 206 | |||
| 207 | /** | ||
| 208 | * Reference the parent FieldDescription related to this admin | ||
| 209 | * only set for FieldDescription which is associated to an Sub Admin instance. | ||
| 210 | * | ||
| 211 | * @var FieldDescriptionInterface | ||
| 212 | */ | ||
| 213 | protected $parentFieldDescription; | ||
| 214 | |||
| 215 | /** | ||
| 216 | * If true then the current admin is part of the nested admin set (from the url). | ||
| 217 | * | ||
| 218 | * @var bool | ||
| 219 | */ | ||
| 220 | protected $currentChild = false; | ||
| 221 | |||
| 222 | /** | ||
| 223 | * The uniqid is used to avoid clashing with 2 admin related to the code | ||
| 224 | * ie: a Block linked to a Block. | ||
| 225 | * | ||
| 226 | * @var string | ||
| 227 | */ | ||
| 228 | protected $uniqid; | ||
| 229 | |||
| 230 | /** | ||
| 231 | * The Entity or Document manager. | ||
| 232 | * | ||
| 233 | * @var ModelManagerInterface | ||
| 234 | */ | ||
| 235 | protected $modelManager; | ||
| 236 | |||
| 237 | /** | ||
| 238 | * The current request object. | ||
| 239 | * | ||
| 240 | * @var Request|null | ||
| 241 | */ | ||
| 242 | protected $request; | ||
| 243 | |||
| 244 | /** | ||
| 245 | * The related form contractor. | ||
| 246 | * | ||
| 247 | * @var FormContractorInterface | ||
| 248 | */ | ||
| 249 | protected $formContractor; | ||
| 250 | |||
| 251 | /** | ||
| 252 | * The related list builder. | ||
| 253 | * | ||
| 254 | * @var ListBuilderInterface | ||
| 255 | */ | ||
| 256 | protected $listBuilder; | ||
| 257 | |||
| 258 | /** | ||
| 259 | * The related view builder. | ||
| 260 | * | ||
| 261 | * @var ShowBuilderInterface | ||
| 262 | */ | ||
| 263 | protected $showBuilder; | ||
| 264 | |||
| 265 | /** | ||
| 266 | * The related datagrid builder. | ||
| 267 | * | ||
| 268 | * @var DatagridBuilderInterface | ||
| 269 | */ | ||
| 270 | protected $datagridBuilder; | ||
| 271 | |||
| 272 | /** | ||
| 273 | * @var RouteBuilderInterface | ||
| 274 | */ | ||
| 275 | protected $routeBuilder; | ||
| 276 | |||
| 277 | /** | ||
| 278 | * The datagrid instance. | ||
| 279 | * | ||
| 280 | * @var DatagridInterface|null | ||
| 281 | */ | ||
| 282 | protected $datagrid; | ||
| 283 | |||
| 284 | /** | ||
| 285 | * The router instance. | ||
| 286 | * | ||
| 287 | * @var RouteGeneratorInterface|null | ||
| 288 | */ | ||
| 289 | protected $routeGenerator; | ||
| 290 | |||
| 291 | /** | ||
| 292 | * @var SecurityHandlerInterface | ||
| 293 | */ | ||
| 294 | protected $securityHandler; | ||
| 295 | |||
| 296 | /** | ||
| 297 | * @var ValidatorInterface | ||
| 298 | */ | ||
| 299 | protected $validator; | ||
| 300 | |||
| 301 | /** | ||
| 302 | * The configuration pool. | ||
| 303 | * | ||
| 304 | * @var Pool | ||
| 305 | */ | ||
| 306 | protected $configurationPool; | ||
| 307 | |||
| 308 | /** | ||
| 309 | * @var ItemInterface | ||
| 310 | */ | ||
| 311 | protected $menu; | ||
| 312 | |||
| 313 | /** | ||
| 314 | * @var FactoryInterface | ||
| 315 | */ | ||
| 316 | protected $menuFactory; | ||
| 317 | |||
| 318 | /** | ||
| 319 | * @var array<string, bool> | ||
| 320 | */ | ||
| 321 | protected $loaded = [ | ||
| 322 | 'routes' => false, | ||
| 323 | 'tab_menu' => false, | ||
| 324 | 'show' => false, | ||
| 325 | 'list' => false, | ||
| 326 | 'form' => false, | ||
| 327 | 'datagrid' => false, | ||
| 328 | ]; | ||
| 329 | |||
| 330 | /** | ||
| 331 | * @var string[] | ||
| 332 | */ | ||
| 333 | protected $formTheme = []; | ||
| 334 | |||
| 335 | /** | ||
| 336 | * @var string[] | ||
| 337 | */ | ||
| 338 | protected $filterTheme = []; | ||
| 339 | |||
| 340 | /** | ||
| 341 | * @var AdminExtensionInterface[] | ||
| 342 | */ | ||
| 343 | protected $extensions = []; | ||
| 344 | |||
| 345 | /** | ||
| 346 | * @var LabelTranslatorStrategyInterface | ||
| 347 | */ | ||
| 348 | protected $labelTranslatorStrategy; | ||
| 349 | |||
| 350 | /** | ||
| 351 | * Setting to true will enable preview mode for | ||
| 352 | * the entity and show a preview button in the | ||
| 353 | * edit/create forms. | ||
| 354 | * | ||
| 355 | * @var bool | ||
| 356 | */ | ||
| 357 | protected $supportsPreviewMode = false; | ||
| 358 | |||
| 359 | /** | ||
| 360 | * Roles and permissions per role. | ||
| 361 | * | ||
| 362 | * @var array 'role' => ['permission', 'permission'] | ||
| 363 | */ | ||
| 364 | protected $securityInformation = []; | ||
| 365 | |||
| 366 | protected $cacheIsGranted = []; | ||
| 367 | |||
| 368 | /** | ||
| 369 | * Action list for the search result. | ||
| 370 | * | ||
| 371 | * @var string[] | ||
| 372 | */ | ||
| 373 | protected $searchResultActions = ['edit', 'show']; | ||
| 374 | |||
| 375 | protected $listModes = [ | ||
| 376 | 'list' => [ | ||
| 377 | 'class' => 'fa fa-list fa-fw', | ||
| 378 | ], | ||
| 379 | 'mosaic' => [ | ||
| 380 | 'class' => self::MOSAIC_ICON_CLASS, | ||
| 381 | ], | ||
| 382 | ]; | ||
| 383 | |||
| 384 | /** | ||
| 385 | * The Access mapping. | ||
| 386 | * | ||
| 387 | * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]] | ||
| 388 | */ | ||
| 389 | protected $accessMapping = []; | ||
| 390 | |||
| 391 | /** | ||
| 392 | * @var array | ||
| 393 | */ | ||
| 394 | private $parentAssociationMapping = []; | ||
| 395 | |||
| 396 | /** | ||
| 397 | * @var MutableTemplateRegistryInterface | ||
| 398 | */ | ||
| 399 | private $templateRegistry; | ||
| 400 | |||
| 401 | /** | ||
| 402 | * The class name managed by the admin class. | ||
| 403 | * | ||
| 404 | * @var string | ||
| 405 | */ | ||
| 406 | private $class; | ||
| 407 | |||
| 408 | /** | ||
| 409 | * The subclasses supported by the admin class. | ||
| 410 | * | ||
| 411 | * @var array<string, string> | ||
| 412 | */ | ||
| 413 | private $subClasses = []; | ||
| 414 | |||
| 415 | /** | ||
| 416 | * The list collection. | ||
| 417 | * | ||
| 418 | * @var FieldDescriptionCollection|null | ||
| 419 | */ | ||
| 420 | private $list; | ||
| 421 | |||
| 422 | /** | ||
| 423 | * @var FieldDescriptionCollection|null | ||
| 424 | */ | ||
| 425 | private $show; | ||
| 426 | |||
| 427 | /** | ||
| 428 | * @var Form|null | ||
| 429 | */ | ||
| 430 | private $form; | ||
| 431 | |||
| 432 | /** | ||
| 433 | * The cached base route name. | ||
| 434 | * | ||
| 435 | * @var string | ||
| 436 | */ | ||
| 437 | private $cachedBaseRouteName; | ||
| 438 | |||
| 439 | /** | ||
| 440 | * The cached base route pattern. | ||
| 441 | * | ||
| 442 | * @var string | ||
| 443 | */ | ||
| 444 | private $cachedBaseRoutePattern; | ||
| 445 | |||
| 446 | /** | ||
| 447 | * The form group disposition. | ||
| 448 | * | ||
| 449 | * @var array<string, mixed> | ||
| 450 | */ | ||
| 451 | private $formGroups = []; | ||
| 452 | |||
| 453 | /** | ||
| 454 | * The form tabs disposition. | ||
| 455 | * | ||
| 456 | * @var array<string, mixed> | ||
| 457 | */ | ||
| 458 | private $formTabs = []; | ||
| 459 | |||
| 460 | /** | ||
| 461 | * The view group disposition. | ||
| 462 | * | ||
| 463 | * @var array<string, mixed> | ||
| 464 | */ | ||
| 465 | private $showGroups = []; | ||
| 466 | |||
| 467 | /** | ||
| 468 | * The view tab disposition. | ||
| 469 | * | ||
| 470 | * @var array<string, mixed> | ||
| 471 | */ | ||
| 472 | private $showTabs = []; | ||
| 473 | |||
| 474 | /** | ||
| 475 | * The manager type to use for the admin. | ||
| 476 | * | ||
| 477 | * @var string | ||
| 478 | */ | ||
| 479 | private $managerType; | ||
| 480 | |||
| 481 | /** | ||
| 482 | * Component responsible for persisting filters. | ||
| 483 | * | ||
| 484 | * @var FilterPersisterInterface|null | ||
| 485 | */ | ||
| 486 | private $filterPersister; | ||
| 487 | |||
| 488 | public function __construct(string $code, string $class, ?string $baseControllerName = null) | ||
| 489 |     { | ||
| 490 | $this->code = $code; | ||
| 491 | $this->class = $class; | ||
| 492 | $this->baseControllerName = $baseControllerName; | ||
| 493 | } | ||
| 494 | |||
| 495 | /** | ||
| 496 |      * {@inheritdoc} | ||
| 497 | */ | ||
| 498 | public function getExportFormats(): array | ||
| 499 |     { | ||
| 500 | return [ | ||
| 501 | 'json', 'xml', 'csv', 'xls', | ||
| 502 | ]; | ||
| 503 | } | ||
| 504 | |||
| 505 | /** | ||
| 506 |      * {@inheritdoc} | ||
| 507 | */ | ||
| 508 | public function getExportFields(): array | ||
| 509 |     { | ||
| 510 | $fields = $this->getModelManager()->getExportFields($this->getClass()); | ||
| 511 | |||
| 512 |         foreach ($this->getExtensions() as $extension) { | ||
| 513 |             if (method_exists($extension, 'configureExportFields')) { | ||
| 514 | $fields = $extension->configureExportFields($this, $fields); | ||
| 515 | } | ||
| 516 | } | ||
| 517 | |||
| 518 | return $fields; | ||
| 519 | } | ||
| 520 | |||
| 521 | public function getDataSourceIterator(): SourceIteratorInterface | ||
| 522 |     { | ||
| 523 | $datagrid = $this->getDatagrid(); | ||
| 524 | $datagrid->buildPager(); | ||
| 525 | |||
| 526 | $fields = []; | ||
| 527 | |||
| 528 |         foreach ($this->getExportFields() as $key => $field) { | ||
| 529 | $label = $this->getTranslationLabel($field, 'export', 'label'); | ||
| 530 | |||
| 531 | $fields[$label] = $field; | ||
| 532 | } | ||
| 533 | |||
| 534 | return $this->getModelManager()->getDataSourceIterator($datagrid, $fields); | ||
| 535 | } | ||
| 536 | |||
| 537 | public function validate(ErrorElement $errorElement, $object): void | ||
| 538 |     { | ||
| 539 | } | ||
| 540 | |||
| 541 | /** | ||
| 542 | * define custom variable. | ||
| 543 | */ | ||
| 544 | public function initialize(): void | ||
| 545 |     { | ||
| 546 |         if (!$this->classnameLabel) { | ||
| 547 | $this->classnameLabel = substr($this->getClass(), strrpos($this->getClass(), '\\') + 1); | ||
| 548 | } | ||
| 549 | |||
| 550 | $this->configure(); | ||
| 551 | } | ||
| 552 | |||
| 553 | public function update(object $object): object | ||
| 554 |     { | ||
| 555 | $this->preUpdate($object); | ||
| 556 |         foreach ($this->extensions as $extension) { | ||
| 557 | $extension->preUpdate($this, $object); | ||
| 558 | } | ||
| 559 | |||
| 560 | $result = $this->getModelManager()->update($object); | ||
| 561 | // BC compatibility | ||
| 562 |         if (null !== $result) { | ||
| 563 | $object = $result; | ||
| 564 | } | ||
| 565 | |||
| 566 | $this->postUpdate($object); | ||
| 567 |         foreach ($this->extensions as $extension) { | ||
| 568 | $extension->postUpdate($this, $object); | ||
| 569 | } | ||
| 570 | |||
| 571 | return $object; | ||
| 572 | } | ||
| 573 | |||
| 574 | public function create(object $object): object | ||
| 575 |     { | ||
| 576 | $this->prePersist($object); | ||
| 577 |         foreach ($this->extensions as $extension) { | ||
| 578 | $extension->prePersist($this, $object); | ||
| 579 | } | ||
| 580 | |||
| 581 | $result = $this->getModelManager()->create($object); | ||
| 582 | // BC compatibility | ||
| 583 |         if (null !== $result) { | ||
| 584 | $object = $result; | ||
| 585 | } | ||
| 586 | |||
| 587 | $this->postPersist($object); | ||
| 588 |         foreach ($this->extensions as $extension) { | ||
| 589 | $extension->postPersist($this, $object); | ||
| 590 | } | ||
| 591 | |||
| 592 | $this->createObjectSecurity($object); | ||
| 593 | |||
| 594 | return $object; | ||
| 595 | } | ||
| 596 | |||
| 597 | public function delete(object $object): void | ||
| 598 |     { | ||
| 599 | $this->preRemove($object); | ||
| 600 |         foreach ($this->extensions as $extension) { | ||
| 601 | $extension->preRemove($this, $object); | ||
| 602 | } | ||
| 603 | |||
| 604 | $this->getSecurityHandler()->deleteObjectSecurity($this, $object); | ||
| 605 | $this->getModelManager()->delete($object); | ||
| 606 | |||
| 607 | $this->postRemove($object); | ||
| 608 |         foreach ($this->extensions as $extension) { | ||
| 609 | $extension->postRemove($this, $object); | ||
| 610 | } | ||
| 611 | } | ||
| 612 | |||
| 613 | public function preValidate(object $object): void | ||
| 614 |     { | ||
| 615 | } | ||
| 616 | |||
| 617 | public function preUpdate(object $object): void | ||
| 618 |     { | ||
| 619 | } | ||
| 620 | |||
| 621 | public function postUpdate(object $object): void | ||
| 622 |     { | ||
| 623 | } | ||
| 624 | |||
| 625 | public function prePersist(object $object): void | ||
| 626 |     { | ||
| 627 | } | ||
| 628 | |||
| 629 | public function postPersist(object $object): void | ||
| 630 |     { | ||
| 631 | } | ||
| 632 | |||
| 633 | public function preRemove(object $object): void | ||
| 634 |     { | ||
| 635 | } | ||
| 636 | |||
| 637 | public function postRemove(object $object): void | ||
| 638 |     { | ||
| 639 | } | ||
| 640 | |||
| 641 | public function preBatchAction(string $actionName, ProxyQueryInterface $query, array &$idx, bool $allElements = false): void | ||
| 642 |     { | ||
| 643 | } | ||
| 644 | |||
| 645 | public function getFilterParameters(): array | ||
| 646 |     { | ||
| 647 | $parameters = []; | ||
| 648 | |||
| 649 | // build the values array | ||
| 650 |         if ($this->hasRequest()) { | ||
| 651 |             $filters = $this->request->query->get('filter', []); | ||
| 652 |             if (isset($filters['_page'])) { | ||
| 653 | $filters['_page'] = (int) $filters['_page']; | ||
| 654 | } | ||
| 655 |             if (isset($filters['_per_page'])) { | ||
| 656 | $filters['_per_page'] = (int) $filters['_per_page']; | ||
| 657 | } | ||
| 658 | |||
| 659 | // if filter persistence is configured | ||
| 660 |             if (null !== $this->filterPersister) { | ||
| 661 | // if reset filters is asked, remove from storage | ||
| 662 |                 if ('reset' === $this->request->query->get('filters')) { | ||
| 663 | $this->filterPersister->reset($this->getCode()); | ||
| 664 | } | ||
| 665 | |||
| 666 | // if no filters, fetch from storage | ||
| 667 | // otherwise save to storage | ||
| 668 |                 if (empty($filters)) { | ||
| 669 | $filters = $this->filterPersister->get($this->getCode()); | ||
| 670 |                 } else { | ||
| 671 | $this->filterPersister->set($this->getCode(), $filters); | ||
| 672 | } | ||
| 673 | } | ||
| 674 | |||
| 675 | $parameters = array_merge( | ||
| 676 | $this->getModelManager()->getDefaultSortValues($this->getClass()), | ||
| 677 | $this->getDefaultSortValues(), | ||
| 678 | $this->getDefaultFilterValues(), | ||
| 679 | $filters | ||
| 680 | ); | ||
| 681 | |||
| 682 |             if (!isset($parameters['_per_page']) || !$this->determinedPerPageValue($parameters['_per_page'])) { | ||
| 683 | $parameters['_per_page'] = $this->getMaxPerPage(); | ||
| 684 | } | ||
| 685 | |||
| 686 | // always force the parent value | ||
| 687 |             if ($this->isChild() && $this->getParentAssociationMapping()) { | ||
| 688 |                 $name = str_replace('.', '__', $this->getParentAssociationMapping()); | ||
| 689 | $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())]; | ||
| 690 | } | ||
| 691 | } | ||
| 692 | |||
| 693 | return $parameters; | ||
| 694 | } | ||
| 695 | |||
| 696 | /** | ||
| 697 | * Returns the name of the parent related field, so the field can be use to set the default | ||
| 698 | * value (ie the parent object) or to filter the object. | ||
| 699 | * | ||
| 700 | * @throws \InvalidArgumentException | ||
| 701 | */ | ||
| 702 | public function getParentAssociationMapping(): ?string | ||
| 703 |     { | ||
| 704 |         if ($this->isChild()) { | ||
| 705 | $parent = $this->getParent()->getCode(); | ||
| 706 | |||
| 707 |             if (\array_key_exists($parent, $this->parentAssociationMapping)) { | ||
| 708 | return $this->parentAssociationMapping[$parent]; | ||
| 709 | } | ||
| 710 | |||
| 711 | throw new \InvalidArgumentException(sprintf( | ||
| 712 | 'There\'s no association between %s and %s.', | ||
| 713 | $this->getCode(), | ||
| 714 | $this->getParent()->getCode() | ||
| 715 | )); | ||
| 716 | } | ||
| 717 | |||
| 718 | return null; | ||
| 719 | } | ||
| 720 | |||
| 721 | final public function addParentAssociationMapping(string $code, string $value): void | ||
| 722 |     { | ||
| 723 | $this->parentAssociationMapping[$code] = $value; | ||
| 724 | } | ||
| 725 | |||
| 726 | /** | ||
| 727 | * Returns the baseRoutePattern used to generate the routing information. | ||
| 728 | * | ||
| 729 | * @throws \RuntimeException | ||
| 730 | * | ||
| 731 | * @return string the baseRoutePattern used to generate the routing information | ||
| 732 | */ | ||
| 733 | public function getBaseRoutePattern(): string | ||
| 734 |     { | ||
| 735 |         if (null !== $this->cachedBaseRoutePattern) { | ||
| 736 | return $this->cachedBaseRoutePattern; | ||
| 737 | } | ||
| 738 | |||
| 739 |         if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern | ||
| 740 | $baseRoutePattern = $this->baseRoutePattern; | ||
| 741 |             if (!$this->baseRoutePattern) { | ||
| 742 | preg_match(self::CLASS_REGEX, $this->class, $matches); | ||
| 743 | |||
| 744 |                 if (!$matches) { | ||
|  | |||
| 745 | throw new \RuntimeException(sprintf( | ||
| 746 | 'Please define a default `baseRoutePattern` value for the admin class `%s`', | ||
| 747 | static::class | ||
| 748 | )); | ||
| 749 | } | ||
| 750 | $baseRoutePattern = $this->urlize($matches[5], '-'); | ||
| 751 | } | ||
| 752 | |||
| 753 | $this->cachedBaseRoutePattern = sprintf( | ||
| 754 | '%s/%s/%s', | ||
| 755 | $this->getParent()->getBaseRoutePattern(), | ||
| 756 | $this->getParent()->getRouterIdParameter(), | ||
| 757 | $baseRoutePattern | ||
| 758 | ); | ||
| 759 |         } elseif ($this->baseRoutePattern) { | ||
| 760 | $this->cachedBaseRoutePattern = $this->baseRoutePattern; | ||
| 761 |         } else { | ||
| 762 | preg_match(self::CLASS_REGEX, $this->class, $matches); | ||
| 763 | |||
| 764 |             if (!$matches) { | ||
| 765 | throw new \RuntimeException(sprintf( | ||
| 766 | 'Please define a default `baseRoutePattern` value for the admin class `%s`', | ||
| 767 | static::class | ||
| 768 | )); | ||
| 769 | } | ||
| 770 | |||
| 771 | $this->cachedBaseRoutePattern = sprintf( | ||
| 772 | '/%s%s/%s', | ||
| 773 | empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/', | ||
| 774 | $this->urlize($matches[3], '-'), | ||
| 775 | $this->urlize($matches[5], '-') | ||
| 776 | ); | ||
| 777 | } | ||
| 778 | |||
| 779 | return $this->cachedBaseRoutePattern; | ||
| 780 | } | ||
| 781 | |||
| 782 | /** | ||
| 783 | * Returns the baseRouteName used to generate the routing information. | ||
| 784 | * | ||
| 785 | * @throws \RuntimeException | ||
| 786 | * | ||
| 787 | * @return string the baseRouteName used to generate the routing information | ||
| 788 | */ | ||
| 789 | public function getBaseRouteName(): string | ||
| 790 |     { | ||
| 791 |         if (null !== $this->cachedBaseRouteName) { | ||
| 792 | return $this->cachedBaseRouteName; | ||
| 793 | } | ||
| 794 | |||
| 795 |         if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name | ||
| 796 | $baseRouteName = $this->baseRouteName; | ||
| 797 |             if (!$this->baseRouteName) { | ||
| 798 | preg_match(self::CLASS_REGEX, $this->class, $matches); | ||
| 799 | |||
| 800 |                 if (!$matches) { | ||
| 801 | throw new \RuntimeException(sprintf( | ||
| 802 | 'Cannot automatically determine base route name,' | ||
| 803 | .' please define a default `baseRouteName` value for the admin class `%s`', | ||
| 804 | static::class | ||
| 805 | )); | ||
| 806 | } | ||
| 807 | $baseRouteName = $this->urlize($matches[5]); | ||
| 808 | } | ||
| 809 | |||
| 810 | $this->cachedBaseRouteName = sprintf( | ||
| 811 | '%s_%s', | ||
| 812 | $this->getParent()->getBaseRouteName(), | ||
| 813 | $baseRouteName | ||
| 814 | ); | ||
| 815 |         } elseif ($this->baseRouteName) { | ||
| 816 | $this->cachedBaseRouteName = $this->baseRouteName; | ||
| 817 |         } else { | ||
| 818 | preg_match(self::CLASS_REGEX, $this->class, $matches); | ||
| 819 | |||
| 820 |             if (!$matches) { | ||
| 821 | throw new \RuntimeException(sprintf( | ||
| 822 | 'Cannot automatically determine base route name,' | ||
| 823 | .' please define a default `baseRouteName` value for the admin class `%s`', | ||
| 824 | static::class | ||
| 825 | )); | ||
| 826 | } | ||
| 827 | |||
| 828 | $this->cachedBaseRouteName = sprintf( | ||
| 829 | 'admin_%s%s_%s', | ||
| 830 | empty($matches[1]) ? '' : $this->urlize($matches[1]).'_', | ||
| 831 | $this->urlize($matches[3]), | ||
| 832 | $this->urlize($matches[5]) | ||
| 833 | ); | ||
| 834 | } | ||
| 835 | |||
| 836 | return $this->cachedBaseRouteName; | ||
| 837 | } | ||
| 838 | |||
| 839 | public function getClass(): string | ||
| 840 |     { | ||
| 841 |         if ($this->hasActiveSubClass()) { | ||
| 842 |             if ($this->hasParentFieldDescription()) { | ||
| 843 |                 throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass'); | ||
| 844 | } | ||
| 845 | |||
| 846 |             $subClass = $this->getRequest()->query->get('subclass'); | ||
| 847 | |||
| 848 |             if (!$this->hasSubClass($subClass)) { | ||
| 849 |                 throw new \RuntimeException(sprintf('Subclass "%s" is not defined.', $subClass)); | ||
| 850 | } | ||
| 851 | |||
| 852 | return $this->getSubClass($subClass); | ||
| 853 | } | ||
| 854 | |||
| 855 | // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 | ||
| 856 |         if ($this->subject && \is_object($this->subject)) { | ||
| 857 | return ClassUtils::getClass($this->subject); | ||
| 858 | } | ||
| 859 | |||
| 860 | return $this->class; | ||
| 861 | } | ||
| 862 | |||
| 863 | public function getSubClasses(): array | ||
| 864 |     { | ||
| 865 | return $this->subClasses; | ||
| 866 | } | ||
| 867 | |||
| 868 | public function setSubClasses(array $subClasses): void | ||
| 869 |     { | ||
| 870 | $this->subClasses = $subClasses; | ||
| 871 | } | ||
| 872 | |||
| 873 | public function hasSubClass(string $name): bool | ||
| 874 |     { | ||
| 875 | return isset($this->subClasses[$name]); | ||
| 876 | } | ||
| 877 | |||
| 878 | public function hasActiveSubClass(): bool | ||
| 879 |     { | ||
| 880 |         if (\count($this->subClasses) > 0 && $this->request) { | ||
| 881 |             return null !== $this->getRequest()->query->get('subclass'); | ||
| 882 | } | ||
| 883 | |||
| 884 | return false; | ||
| 885 | } | ||
| 886 | |||
| 887 | public function getActiveSubClass(): string | ||
| 888 |     { | ||
| 889 |         if (!$this->hasActiveSubClass()) { | ||
| 890 | throw new \LogicException(sprintf( | ||
| 891 | 'Admin "%s" has no active subclass.', | ||
| 892 | static::class | ||
| 893 | )); | ||
| 894 | } | ||
| 895 | |||
| 896 | return $this->getSubClass($this->getActiveSubclassCode()); | ||
| 897 | } | ||
| 898 | |||
| 899 | public function getActiveSubclassCode(): string | ||
| 900 |     { | ||
| 901 |         if (!$this->hasActiveSubClass()) { | ||
| 902 | throw new \LogicException(sprintf( | ||
| 903 | 'Admin "%s" has no active subclass.', | ||
| 904 | static::class | ||
| 905 | )); | ||
| 906 | } | ||
| 907 | |||
| 908 |         $subClass = $this->getRequest()->query->get('subclass'); | ||
| 909 | |||
| 910 |         if (!$this->hasSubClass($subClass)) { | ||
| 911 | throw new \LogicException(sprintf( | ||
| 912 | 'Admin "%s" has no active subclass.', | ||
| 913 | static::class | ||
| 914 | )); | ||
| 915 | } | ||
| 916 | |||
| 917 | return $subClass; | ||
| 918 | } | ||
| 919 | |||
| 920 | public function getBatchActions(): array | ||
| 921 |     { | ||
| 922 | $actions = []; | ||
| 923 | |||
| 924 |         if ($this->hasRoute('delete') && $this->hasAccess('delete')) { | ||
| 925 | $actions['delete'] = [ | ||
| 926 | 'label' => 'action_delete', | ||
| 927 | 'translation_domain' => 'SonataAdminBundle', | ||
| 928 | 'ask_confirmation' => true, // by default always true | ||
| 929 | ]; | ||
| 930 | } | ||
| 931 | |||
| 932 | $actions = $this->configureBatchActions($actions); | ||
| 933 | |||
| 934 |         foreach ($this->getExtensions() as $extension) { | ||
| 935 | $actions = $extension->configureBatchActions($this, $actions); | ||
| 936 | } | ||
| 937 | |||
| 938 |         foreach ($actions  as $name => &$action) { | ||
| 939 |             if (!\array_key_exists('label', $action)) { | ||
| 940 | $action['label'] = $this->getTranslationLabel($name, 'batch', 'label'); | ||
| 941 | } | ||
| 942 | |||
| 943 |             if (!\array_key_exists('translation_domain', $action)) { | ||
| 944 | $action['translation_domain'] = $this->getTranslationDomain(); | ||
| 945 | } | ||
| 946 | } | ||
| 947 | |||
| 948 | return $actions; | ||
| 949 | } | ||
| 950 | |||
| 951 | public function getRoutes(): RouteCollectionInterface | ||
| 957 | |||
| 958 | public function getRouterIdParameter(): string | ||
| 962 | |||
| 963 | public function getIdParameter(): string | ||
| 973 | |||
| 974 | public function hasRoute(string $name): bool | ||
| 982 | |||
| 983 | public function isCurrentRoute(string $name, ?string $adminCode = null): bool | ||
| 1004 | |||
| 1005 | public function generateObjectUrl(string $name, object $object, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string | ||
| 1011 | |||
| 1012 | public function generateUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string | ||
| 1016 | |||
| 1017 | public function generateMenuUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): array | ||
| 1021 | |||
| 1022 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void | ||
| 1026 | |||
| 1027 | /** | ||
| 1028 | * @param array<string, string> $templates | ||
| 1029 | */ | ||
| 1030 | public function setTemplates(array $templates): void | ||
| 1034 | |||
| 1035 | /** | ||
| 1036 |      * {@inheritdoc} | ||
| 1037 | */ | ||
| 1038 | public function setTemplate(string $name, string $template): void | ||
| 1042 | |||
| 1043 | public function getNewInstance(): object | ||
| 1055 | |||
| 1056 | public function getFormBuilder(): FormBuilderInterface | ||
| 1069 | |||
| 1070 | /** | ||
| 1071 | * This method is being called by the main admin class and the child class, | ||
| 1072 | * the getFormBuilder is only call by the main admin class. | ||
| 1073 | */ | ||
| 1074 | public function defineFormBuilder(FormBuilderInterface $formBuilder): void | ||
| 1093 | |||
| 1094 | public function attachAdminClass(FieldDescriptionInterface $fieldDescription): void | ||
| 1122 | |||
| 1123 | public function getObject($id): ?object | ||
| 1132 | |||
| 1133 | public function getForm(): ?FormInterface | ||
| 1139 | |||
| 1140 | public function getList(): ?FieldDescriptionCollection | ||
| 1146 | |||
| 1147 | final public function createQuery(): ProxyQueryInterface | ||
| 1148 |     { | ||
| 1149 | $query = $this->getModelManager()->createQuery($this->getClass()); | ||
| 1150 | |||
| 1151 | $query = $this->configureQuery($query); | ||
| 1152 |         foreach ($this->extensions as $extension) { | ||
| 1153 | $extension->configureQuery($this, $query); | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | return $query; | ||
| 1157 | } | ||
| 1158 | |||
| 1159 | public function getDatagrid(): DatagridInterface | ||
| 1160 |     { | ||
| 1161 | $this->buildDatagrid(); | ||
| 1162 | |||
| 1163 | return $this->datagrid; | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | public function buildTabMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface | ||
| 1167 |     { | ||
| 1168 |         if ($this->loaded['tab_menu']) { | ||
| 1169 | return $this->menu; | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | $this->loaded['tab_menu'] = true; | ||
| 1173 | |||
| 1174 |         $menu = $this->menuFactory->createItem('root'); | ||
| 1175 |         $menu->setChildrenAttribute('class', 'nav navbar-nav'); | ||
| 1176 |         $menu->setExtra('translation_domain', $this->translationDomain); | ||
| 1177 | |||
| 1178 | // Prevents BC break with KnpMenuBundle v1.x | ||
| 1179 |         if (method_exists($menu, 'setCurrentUri')) { | ||
| 1180 | $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo()); | ||
| 1181 | } | ||
| 1182 | |||
| 1183 | $this->configureTabMenu($menu, $action, $childAdmin); | ||
| 1184 | |||
| 1185 |         foreach ($this->getExtensions() as $extension) { | ||
| 1186 | $extension->configureTabMenu($this, $menu, $action, $childAdmin); | ||
| 1187 | } | ||
| 1188 | |||
| 1189 | $this->menu = $menu; | ||
| 1190 | |||
| 1191 | return $this->menu; | ||
| 1192 | } | ||
| 1193 | |||
| 1194 | public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface | ||
| 1195 |     { | ||
| 1196 |         if ($this->isChild()) { | ||
| 1197 | return $this->getParent()->getSideMenu($action, $this); | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | $this->buildTabMenu($action, $childAdmin); | ||
| 1201 | |||
| 1202 | return $this->menu; | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | public function getRootCode(): string | ||
| 1206 |     { | ||
| 1207 | return $this->getRoot()->getCode(); | ||
| 1208 | } | ||
| 1209 | |||
| 1210 | public function getRoot(): AdminInterface | ||
| 1211 |     { | ||
| 1212 |         if (!$this->hasParentFieldDescription()) { | ||
| 1213 | return $this; | ||
| 1214 | } | ||
| 1215 | |||
| 1216 | return $this->getParentFieldDescription()->getAdmin()->getRoot(); | ||
| 1217 | } | ||
| 1218 | |||
| 1219 | public function setBaseControllerName(string $baseControllerName): void | ||
| 1220 |     { | ||
| 1221 | $this->baseControllerName = $baseControllerName; | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | public function getBaseControllerName(): string | ||
| 1225 |     { | ||
| 1226 | return $this->baseControllerName; | ||
| 1227 | } | ||
| 1228 | |||
| 1229 | public function setLabel(?string $label): void | ||
| 1230 |     { | ||
| 1231 | $this->label = $label; | ||
| 1232 | } | ||
| 1233 | |||
| 1234 | public function getLabel(): ?string | ||
| 1235 |     { | ||
| 1236 | return $this->label; | ||
| 1237 | } | ||
| 1238 | |||
| 1239 | public function setFilterPersister(?FilterPersisterInterface $filterPersister = null): void | ||
| 1240 |     { | ||
| 1241 | $this->filterPersister = $filterPersister; | ||
| 1242 | } | ||
| 1243 | |||
| 1244 | public function getMaxPerPage(): int | ||
| 1245 |     { | ||
| 1246 | $sortValues = $this->getModelManager()->getDefaultSortValues($this->class); | ||
| 1247 | |||
| 1248 | return $sortValues['_per_page'] ?? 25; | ||
| 1249 | } | ||
| 1250 | |||
| 1251 | public function setMaxPageLinks(int $maxPageLinks): void | ||
| 1252 |     { | ||
| 1253 | $this->maxPageLinks = $maxPageLinks; | ||
| 1254 | } | ||
| 1255 | |||
| 1256 | public function getMaxPageLinks(): int | ||
| 1257 |     { | ||
| 1258 | return $this->maxPageLinks; | ||
| 1259 | } | ||
| 1260 | |||
| 1261 | public function getFormGroups(): array | ||
| 1262 |     { | ||
| 1263 | return $this->formGroups; | ||
| 1264 | } | ||
| 1265 | |||
| 1266 | public function setFormGroups(array $formGroups): void | ||
| 1267 |     { | ||
| 1268 | $this->formGroups = $formGroups; | ||
| 1269 | } | ||
| 1270 | |||
| 1271 | public function removeFieldFromFormGroup(string $key): void | ||
| 1272 |     { | ||
| 1273 |         foreach ($this->formGroups as $name => $formGroup) { | ||
| 1274 | unset($this->formGroups[$name]['fields'][$key]); | ||
| 1275 | |||
| 1276 |             if (empty($this->formGroups[$name]['fields'])) { | ||
| 1277 | unset($this->formGroups[$name]); | ||
| 1278 | } | ||
| 1279 | } | ||
| 1280 | } | ||
| 1281 | |||
| 1282 | public function reorderFormGroup(string $group, array $keys): void | ||
| 1283 |     { | ||
| 1284 | $formGroups = $this->getFormGroups(); | ||
| 1285 | $formGroups[$group]['fields'] = array_merge(array_flip($keys), $formGroups[$group]['fields']); | ||
| 1286 | $this->setFormGroups($formGroups); | ||
| 1287 | } | ||
| 1288 | |||
| 1289 | public function getFormTabs(): array | ||
| 1290 |     { | ||
| 1291 | return $this->formTabs; | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | public function setFormTabs(array $formTabs): void | ||
| 1295 |     { | ||
| 1296 | $this->formTabs = $formTabs; | ||
| 1297 | } | ||
| 1298 | |||
| 1299 | public function getShowTabs(): array | ||
| 1300 |     { | ||
| 1301 | return $this->showTabs; | ||
| 1302 | } | ||
| 1303 | |||
| 1304 | public function setShowTabs(array $showTabs): void | ||
| 1305 |     { | ||
| 1306 | $this->showTabs = $showTabs; | ||
| 1307 | } | ||
| 1308 | |||
| 1309 | public function getShowGroups(): array | ||
| 1310 |     { | ||
| 1311 | return $this->showGroups; | ||
| 1312 | } | ||
| 1313 | |||
| 1314 | public function setShowGroups(array $showGroups): void | ||
| 1315 |     { | ||
| 1316 | $this->showGroups = $showGroups; | ||
| 1317 | } | ||
| 1318 | |||
| 1319 | public function reorderShowGroup(string $group, array $keys): void | ||
| 1320 |     { | ||
| 1321 | $showGroups = $this->getShowGroups(); | ||
| 1322 | $showGroups[$group]['fields'] = array_merge(array_flip($keys), $showGroups[$group]['fields']); | ||
| 1323 | $this->setShowGroups($showGroups); | ||
| 1324 | } | ||
| 1325 | |||
| 1326 | public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription): void | ||
| 1327 |     { | ||
| 1328 | $this->parentFieldDescription = $parentFieldDescription; | ||
| 1329 | } | ||
| 1330 | |||
| 1331 | public function getParentFieldDescription(): FieldDescriptionInterface | ||
| 1332 |     { | ||
| 1333 |         if (!$this->hasParentFieldDescription()) { | ||
| 1334 | throw new \LogicException(sprintf( | ||
| 1335 | 'Admin "%s" has no parent field description.', | ||
| 1336 | static::class | ||
| 1337 | )); | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | return $this->parentFieldDescription; | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | public function hasParentFieldDescription(): bool | ||
| 1344 |     { | ||
| 1345 | return $this->parentFieldDescription instanceof FieldDescriptionInterface; | ||
| 1346 | } | ||
| 1347 | |||
| 1348 | public function setSubject(?object $subject): void | ||
| 1349 |     { | ||
| 1350 |         if (\is_object($subject) && !is_a($subject, $this->getClass(), true)) { | ||
| 1351 | throw new \LogicException(sprintf( | ||
| 1352 | 'Admin "%s" does not allow this subject: %s, use the one register with this admin class %s', | ||
| 1353 | static::class, | ||
| 1354 | \get_class($subject), | ||
| 1355 | $this->getClass() | ||
| 1356 | )); | ||
| 1357 | } | ||
| 1358 | |||
| 1359 | $this->subject = $subject; | ||
| 1360 | } | ||
| 1361 | |||
| 1362 | public function getSubject(): object | ||
| 1373 | |||
| 1374 | public function hasSubject(): bool | ||
| 1386 | |||
| 1387 | public function getFormFieldDescriptions(): array | ||
| 1393 | |||
| 1394 | public function getFormFieldDescription(string $name): FieldDescriptionInterface | ||
| 1408 | |||
| 1409 | /** | ||
| 1410 | * Returns true if the admin has a FieldDescription with the given $name. | ||
| 1411 | */ | ||
| 1412 | public function hasFormFieldDescription(string $name): bool | ||
| 1418 | |||
| 1419 | public function addFormFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void | ||
| 1423 | |||
| 1424 | /** | ||
| 1425 | * remove a FieldDescription. | ||
| 1426 | */ | ||
| 1427 | public function removeFormFieldDescription(string $name): void | ||
| 1431 | |||
| 1432 | /** | ||
| 1433 | * build and return the collection of form FieldDescription. | ||
| 1434 | * | ||
| 1435 | * @return FieldDescriptionInterface[] collection of form FieldDescription | ||
| 1436 | */ | ||
| 1437 | public function getShowFieldDescriptions(): array | ||
| 1443 | |||
| 1444 | /** | ||
| 1445 | * Returns the form FieldDescription with the given $name. | ||
| 1446 | */ | ||
| 1447 | public function getShowFieldDescription(string $name): FieldDescriptionInterface | ||
| 1461 | |||
| 1462 | public function hasShowFieldDescription(string $name): bool | ||
| 1468 | |||
| 1469 | public function addShowFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void | ||
| 1473 | |||
| 1474 | public function removeShowFieldDescription(string $name): void | ||
| 1478 | |||
| 1479 | public function getListFieldDescriptions(): array | ||
| 1485 | |||
| 1486 | public function getListFieldDescription(string $name): FieldDescriptionInterface | ||
| 1500 | |||
| 1501 | public function hasListFieldDescription(string $name): bool | ||
| 1507 | |||
| 1508 | public function addListFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void | ||
| 1512 | |||
| 1513 | public function removeListFieldDescription(string $name): void | ||
| 1517 | |||
| 1518 | public function getFilterFieldDescription(string $name): FieldDescriptionInterface | ||
| 1532 | |||
| 1533 | public function hasFilterFieldDescription(string $name): bool | ||
| 1539 | |||
| 1540 | public function addFilterFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void | ||
| 1544 | |||
| 1545 | public function removeFilterFieldDescription(string $name): void | ||
| 1549 | |||
| 1550 | public function getFilterFieldDescriptions(): array | ||
| 1556 | |||
| 1557 | public function addChild(AdminInterface $child, string $field): void | ||
| 1577 | |||
| 1578 | public function hasChild(string $code): bool | ||
| 1582 | |||
| 1583 | public function getChildren(): array | ||
| 1587 | |||
| 1588 | public function getChild(string $code): AdminInterface | ||
| 1600 | |||
| 1601 | public function setParent(AdminInterface $parent): void | ||
| 1605 | |||
| 1606 | public function getParent(): AdminInterface | ||
| 1617 | |||
| 1618 | final public function getRootAncestor(): AdminInterface | ||
| 1628 | |||
| 1629 | final public function getChildDepth(): int | ||
| 1641 | |||
| 1642 | final public function getCurrentLeafChildAdmin(): ?AdminInterface | ||
| 1656 | |||
| 1657 | public function isChild(): bool | ||
| 1661 | |||
| 1662 | /** | ||
| 1663 | * Returns true if the admin has children, false otherwise. | ||
| 1664 | */ | ||
| 1665 | public function hasChildren(): bool | ||
| 1669 | |||
| 1670 | public function setUniqid(string $uniqid): void | ||
| 1674 | |||
| 1675 | public function getUniqid(): string | ||
| 1683 | |||
| 1684 | /** | ||
| 1685 |      * {@inheritdoc} | ||
| 1686 | */ | ||
| 1687 | public function getClassnameLabel(): string | ||
| 1691 | |||
| 1692 | public function getPersistentParameters(): array | ||
| 1704 | |||
| 1705 | /** | ||
| 1706 |      * {@inheritdoc} | ||
| 1707 | */ | ||
| 1708 | public function getPersistentParameter(string $name) | ||
| 1714 | |||
| 1715 | public function setCurrentChild(bool $currentChild): void | ||
| 1719 | |||
| 1720 | public function isCurrentChild(): bool | ||
| 1724 | |||
| 1725 | /** | ||
| 1726 | * Returns the current child admin instance. | ||
| 1727 | * | ||
| 1728 | * @return AdminInterface|null the current child admin instance | ||
| 1729 | */ | ||
| 1730 | public function getCurrentChildAdmin(): ?AdminInterface | ||
| 1740 | |||
| 1741 | public function setTranslationDomain(string $translationDomain): void | ||
| 1745 | |||
| 1746 | public function getTranslationDomain(): string | ||
| 1750 | |||
| 1751 | public function getTranslationLabel(string $label, string $context = '', string $type = ''): string | ||
| 1755 | |||
| 1756 | public function setRequest(Request $request): void | ||
| 1764 | |||
| 1765 | public function getRequest(): Request | ||
| 1773 | |||
| 1774 | public function hasRequest(): bool | ||
| 1778 | |||
| 1779 | public function setFormContractor(FormContractorInterface $formBuilder): void | ||
| 1783 | |||
| 1784 | public function getFormContractor(): ?FormContractorInterface | ||
| 1788 | |||
| 1789 | public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder): void | ||
| 1793 | |||
| 1794 | public function getDatagridBuilder(): ?DatagridBuilderInterface | ||
| 1798 | |||
| 1799 | public function setListBuilder(ListBuilderInterface $listBuilder): void | ||
| 1803 | |||
| 1804 | public function getListBuilder(): ?ListBuilderInterface | ||
| 1808 | |||
| 1809 | public function setShowBuilder(?ShowBuilderInterface $showBuilder): void | ||
| 1813 | |||
| 1814 | public function getShowBuilder(): ?ShowBuilderInterface | ||
| 1818 | |||
| 1819 | public function setConfigurationPool(Pool $configurationPool): void | ||
| 1823 | |||
| 1824 | public function getConfigurationPool(): ?Pool | ||
| 1828 | |||
| 1829 | public function setRouteGenerator(RouteGeneratorInterface $routeGenerator): void | ||
| 1833 | |||
| 1834 | public function getRouteGenerator(): ?RouteGeneratorInterface | ||
| 1838 | |||
| 1839 | public function getCode(): string | ||
| 1843 | |||
| 1844 | public function getBaseCodeRoute(): string | ||
| 1852 | |||
| 1853 | public function getModelManager(): ?ModelManagerInterface | ||
| 1857 | |||
| 1858 | public function setModelManager(?ModelManagerInterface $modelManager): void | ||
| 1862 | |||
| 1863 | public function getManagerType(): ?string | ||
| 1867 | |||
| 1868 | public function setManagerType(?string $type): void | ||
| 1872 | |||
| 1873 | public function getObjectIdentifier() | ||
| 1877 | |||
| 1878 | /** | ||
| 1879 | * Set the roles and permissions per role. | ||
| 1880 | */ | ||
| 1881 | public function setSecurityInformation(array $information): void | ||
| 1885 | |||
| 1886 | public function getSecurityInformation(): array | ||
| 1890 | |||
| 1891 | /** | ||
| 1892 | * Return the list of permissions the user should have in order to display the admin. | ||
| 1893 | */ | ||
| 1894 | public function getPermissionsShow(string $context): array | ||
| 1903 | |||
| 1904 | public function showIn(string $context): bool | ||
| 1913 | |||
| 1914 | public function createObjectSecurity(object $object): void | ||
| 1918 | |||
| 1919 | public function setSecurityHandler(SecurityHandlerInterface $securityHandler): void | ||
| 1923 | |||
| 1924 | public function getSecurityHandler(): ?SecurityHandlerInterface | ||
| 1928 | |||
| 1929 | /** | ||
| 1930 | * NEXT_MAJOR: Decide the type declaration for the $name argument, since it is | ||
| 1931 | * passed as argument 1 for `SecurityHandlerInterface::isGranted()`, which | ||
| 1932 | * accepts string and array. | ||
| 1933 | */ | ||
| 1934 | public function isGranted($name, ?object $object = null): bool | ||
| 1945 | |||
| 1946 | /** | ||
| 1947 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is | ||
| 1948 | * passed as argument 1 for `ModelManagerInterface::getUrlSafeIdentifier()`, which | ||
| 1949 | * accepts null. | ||
| 1950 | */ | ||
| 1951 | public function getUrlSafeIdentifier($model): ?string | ||
| 1955 | |||
| 1956 | /** | ||
| 1957 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is | ||
| 1958 | * passed as argument 1 for `ModelManagerInterface::getNormalizedIdentifier()`, which | ||
| 1959 | * accepts null. | ||
| 1960 | */ | ||
| 1961 | public function getNormalizedIdentifier($model): ?string | ||
| 1965 | |||
| 1966 | /** | ||
| 1967 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is | ||
| 1968 | * passed as argument 1 for `ModelManagerInterface::getNormalizedIdentifier()`, which | ||
| 1969 | * accepts null. | ||
| 1970 | */ | ||
| 1971 | public function id($model): ?string | ||
| 1975 | |||
| 1976 | public function setValidator(ValidatorInterface $validator): void | ||
| 1980 | |||
| 1981 | public function getValidator(): ?ValidatorInterface | ||
| 1985 | |||
| 1986 | public function getShow(): ?FieldDescriptionCollection | ||
| 1992 | |||
| 1993 | public function setFormTheme(array $formTheme): void | ||
| 1997 | |||
| 1998 | public function getFormTheme(): array | ||
| 2002 | |||
| 2003 | public function setFilterTheme(array $filterTheme): void | ||
| 2007 | |||
| 2008 | public function getFilterTheme(): array | ||
| 2012 | |||
| 2013 | public function addExtension(AdminExtensionInterface $extension): void | ||
| 2017 | |||
| 2018 | public function getExtensions(): array | ||
| 2022 | |||
| 2023 | public function setMenuFactory(FactoryInterface $menuFactory): void | ||
| 2027 | |||
| 2028 | public function getMenuFactory(): ?FactoryInterface | ||
| 2032 | |||
| 2033 | public function setRouteBuilder(RouteBuilderInterface $routeBuilder): void | ||
| 2037 | |||
| 2038 | public function getRouteBuilder(): ?RouteBuilderInterface | ||
| 2042 | |||
| 2043 | /** | ||
| 2044 | * NEXT_MAJOR: Decide the type declaration for the $object argument, since there | ||
| 2045 | * are tests ensuring to accept null (`GetShortObjectDescriptionActionTest::testGetShortObjectDescriptionActionEmptyObjectIdAsJson()`). | ||
| 2046 | */ | ||
| 2047 | public function toString($object): string | ||
| 2059 | |||
| 2060 | public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy): void | ||
| 2064 | |||
| 2065 | public function getLabelTranslatorStrategy(): ?LabelTranslatorStrategyInterface | ||
| 2069 | |||
| 2070 | public function supportsPreviewMode(): bool | ||
| 2074 | |||
| 2075 | /** | ||
| 2076 | * Returns predefined per page options. | ||
| 2077 | */ | ||
| 2078 | public function getPerPageOptions(): array | ||
| 2088 | |||
| 2089 | /** | ||
| 2090 | * Set pager type. | ||
| 2091 | */ | ||
| 2092 | public function setPagerType(string $pagerType): void | ||
| 2096 | |||
| 2097 | /** | ||
| 2098 | * Get pager type. | ||
| 2099 | */ | ||
| 2100 | public function getPagerType(): string | ||
| 2104 | |||
| 2105 | /** | ||
| 2106 | * Returns true if the per page value is allowed, false otherwise. | ||
| 2107 | */ | ||
| 2108 | public function determinedPerPageValue(int $perPage): bool | ||
| 2112 | |||
| 2113 | public function isAclEnabled(): bool | ||
| 2117 | |||
| 2118 | /** | ||
| 2119 | * NEXT_MAJOR: Decide the type declaration for the $object argument, since it is | ||
| 2120 | * passed as argument 1 to `toString()` method, which currently accepts null. | ||
| 2121 | */ | ||
| 2122 | public function getObjectMetadata($object): MetadataInterface | ||
| 2126 | |||
| 2127 | public function getListModes(): array | ||
| 2131 | |||
| 2132 | public function setListMode(string $mode): void | ||
| 2140 | |||
| 2141 | public function getListMode(): string | ||
| 2149 | |||
| 2150 | public function getAccessMapping(): array | ||
| 2154 | |||
| 2155 | public function checkAccess(string $action, ?object $object = null): void | ||
| 2177 | |||
| 2178 | /** | ||
| 2179 |      * {@inheritdoc} | ||
| 2180 | */ | ||
| 2181 | public function hasAccess(string $action, ?object $object = null): bool | ||
| 2201 | |||
| 2202 | final public function getActionButtons(string $action, ?object $object = null): array | ||
| 2270 | |||
| 2271 | /** | ||
| 2272 |      * {@inheritdoc} | ||
| 2273 | */ | ||
| 2274 | public function getDashboardActions(): array | ||
| 2299 | |||
| 2300 | /** | ||
| 2301 |      * {@inheritdoc} | ||
| 2302 | */ | ||
| 2303 | final public function showMosaicButton($isShown): void | ||
| 2311 | |||
| 2312 | final public function getSearchResultLink(object $object): ?string | ||
| 2322 | |||
| 2323 | /** | ||
| 2324 | * Checks if a filter type is set to a default value. | ||
| 2325 | */ | ||
| 2326 | final public function isDefaultFilter(string $name): bool | ||
| 2337 | |||
| 2338 | public function canAccessObject(string $action, ?object $object = null): bool | ||
| 2342 | |||
| 2343 | public function configureActionButtons(array $buttonList, string $action, ?object $object = null): array | ||
| 2347 | |||
| 2348 | /** | ||
| 2349 | * Hook to run after initialization. | ||
| 2350 | */ | ||
| 2351 | protected function configure(): void | ||
| 2354 | |||
| 2355 | protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface | ||
| 2359 | |||
| 2360 | /** | ||
| 2361 | * urlize the given word. | ||
| 2362 | * | ||
| 2363 | * @param string $sep the separator | ||
| 2364 | */ | ||
| 2365 | final protected function urlize(string $word, string $sep = '_'): string | ||
| 2369 | |||
| 2370 | final protected function getTemplateRegistry(): MutableTemplateRegistryInterface | ||
| 2374 | |||
| 2375 | /** | ||
| 2376 | * Returns a list of default sort values. | ||
| 2377 | * | ||
| 2378 |      * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string} | ||
| 2379 | */ | ||
| 2380 | final protected function getDefaultSortValues(): array | ||
| 2392 | |||
| 2393 | /** | ||
| 2394 | * Returns a list of default filters. | ||
| 2395 | */ | ||
| 2396 | final protected function getDefaultFilterValues(): array | ||
| 2408 | |||
| 2409 | protected function configureFormFields(FormMapper $form): void | ||
| 2412 | |||
| 2413 | protected function configureListFields(ListMapper $list): void | ||
| 2416 | |||
| 2417 | protected function configureDatagridFilters(DatagridMapper $filter): void | ||
| 2420 | |||
| 2421 | protected function configureShowFields(ShowMapper $show): void | ||
| 2424 | |||
| 2425 | protected function configureRoutes(RouteCollectionInterface $collection): void | ||
| 2428 | |||
| 2429 | /** | ||
| 2430 | * Allows you to customize batch actions. | ||
| 2431 | * | ||
| 2432 | * @param array $actions List of actions | ||
| 2433 | */ | ||
| 2434 | protected function configureBatchActions(array $actions): array | ||
| 2438 | |||
| 2439 | /** | ||
| 2440 | * Configures the tab menu in your admin. | ||
| 2441 | */ | ||
| 2442 | protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminInterface $childAdmin = null): void | ||
| 2445 | |||
| 2446 | /** | ||
| 2447 | * build the view FieldDescription array. | ||
| 2448 | */ | ||
| 2449 | protected function buildShow(): void | ||
| 2466 | |||
| 2467 | /** | ||
| 2468 | * build the list FieldDescription array. | ||
| 2469 | */ | ||
| 2470 | protected function buildList(): void | ||
| 2523 | |||
| 2524 | /** | ||
| 2525 | * Build the form FieldDescription collection. | ||
| 2526 | */ | ||
| 2527 | protected function buildForm(): void | ||
| 2542 | |||
| 2543 | /** | ||
| 2544 | * Gets the subclass corresponding to the given name. | ||
| 2545 | * | ||
| 2546 | * @param string $name The name of the sub class | ||
| 2547 | * | ||
| 2548 | * @return string the subclass | ||
| 2549 | */ | ||
| 2550 | protected function getSubClass(string $name): string | ||
| 2558 | |||
| 2559 | /** | ||
| 2560 | * Attach the inline validator to the model metadata, this must be done once per admin. | ||
| 2561 | */ | ||
| 2562 | protected function attachInlineValidator(): void | ||
| 2599 | |||
| 2600 | /** | ||
| 2601 | * Return list routes with permissions name. | ||
| 2602 | * | ||
| 2603 | * @return array<string, string> | ||
| 2604 | */ | ||
| 2605 | protected function getAccess(): array | ||
| 2627 | |||
| 2628 | /** | ||
| 2629 | * Configures a list of default filters. | ||
| 2630 | */ | ||
| 2631 | protected function configureDefaultFilterValues(array &$filterValues): void | ||
| 2634 | |||
| 2635 | /** | ||
| 2636 | * Configures a list of default sort values. | ||
| 2637 | * | ||
| 2638 | * Example: | ||
| 2639 | * $sortValues['_sort_by'] = 'foo' | ||
| 2640 | * $sortValues['_sort_order'] = 'DESC' | ||
| 2641 | */ | ||
| 2642 | protected function configureDefaultSortValues(array &$sortValues) | ||
| 2645 | |||
| 2646 | /** | ||
| 2647 | * Set the parent object, if any, to the provided object. | ||
| 2648 | */ | ||
| 2649 | final protected function appendParentObject(object $object): void | ||
| 2677 | |||
| 2678 | /** | ||
| 2679 |      * {@inheritdoc} | ||
| 2680 | */ | ||
| 2681 | private function buildDatagrid(): void | ||
| 2735 | |||
| 2736 | /** | ||
| 2737 | * Build all the related urls to the current admin. | ||
| 2738 | */ | ||
| 2739 | private function buildRoutes(): void | ||
| 2762 | } | ||
| 2763 | |||
| 2764 | class_exists(ErrorElement::class); | ||
| 2765 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.