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 |
||
| 63 | abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface |
||
| 64 | { |
||
| 65 | public const CONTEXT_MENU = 'menu'; |
||
| 66 | public const CONTEXT_DASHBOARD = 'dashboard'; |
||
| 67 | |||
| 68 | public const CLASS_REGEX = |
||
| 69 | '@ |
||
| 70 | (?:([A-Za-z0-9]*)\\\)? # vendor name / app name |
||
| 71 | (Bundle\\\)? # optional bundle directory |
||
| 72 | ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix |
||
| 73 | ( |
||
| 74 | Entity|Document|Model|PHPCR|CouchDocument|Phpcr| |
||
| 75 | Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB |
||
| 76 | )\\\(.*)@x'; |
||
| 77 | |||
| 78 | public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The list FieldDescription constructed from the configureListField method. |
||
| 82 | * |
||
| 83 | * @var FieldDescriptionInterface[] |
||
| 84 | */ |
||
| 85 | protected $listFieldDescriptions = []; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The show FieldDescription constructed from the configureShowFields method. |
||
| 89 | * |
||
| 90 | * @var FieldDescriptionInterface[] |
||
| 91 | */ |
||
| 92 | protected $showFieldDescriptions = []; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The list FieldDescription constructed from the configureFormField method. |
||
| 96 | * |
||
| 97 | * @var FieldDescriptionInterface[] |
||
| 98 | */ |
||
| 99 | protected $formFieldDescriptions = []; |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The filter FieldDescription constructed from the configureFilterField method. |
||
| 103 | * |
||
| 104 | * @var FieldDescriptionInterface[] |
||
| 105 | */ |
||
| 106 | protected $filterFieldDescriptions = []; |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The maximum number of page numbers to display in the list. |
||
| 110 | * |
||
| 111 | * @var int |
||
| 112 | */ |
||
| 113 | protected $maxPageLinks = 25; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * The base route name used to generate the routing information. |
||
| 117 | * |
||
| 118 | * @var string |
||
| 119 | */ |
||
| 120 | protected $baseRouteName; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * The base route pattern used to generate the routing information. |
||
| 124 | * |
||
| 125 | * @var string |
||
| 126 | */ |
||
| 127 | protected $baseRoutePattern; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * The base name controller used to generate the routing information. |
||
| 131 | * |
||
| 132 | * @var string |
||
| 133 | */ |
||
| 134 | protected $baseControllerName; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * The label class name (used in the title/breadcrumb ...). |
||
| 138 | * |
||
| 139 | * @var string |
||
| 140 | */ |
||
| 141 | protected $classnameLabel; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * The translation domain to be used to translate messages. |
||
| 145 | * |
||
| 146 | * @var string |
||
| 147 | */ |
||
| 148 | protected $translationDomain = 'messages'; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * Options to set to the form (ie, validation_groups). |
||
| 152 | * |
||
| 153 | * @var array |
||
| 154 | */ |
||
| 155 | protected $formOptions = []; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Pager type. |
||
| 159 | * |
||
| 160 | * @var string |
||
| 161 | */ |
||
| 162 | protected $pagerType = Pager::TYPE_DEFAULT; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * The code related to the admin. |
||
| 166 | * |
||
| 167 | * @var string |
||
| 168 | */ |
||
| 169 | protected $code; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * The label. |
||
| 173 | * |
||
| 174 | * @var string |
||
| 175 | */ |
||
| 176 | protected $label; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Array of routes related to this admin. |
||
| 180 | * |
||
| 181 | * @var RouteCollection |
||
| 182 | */ |
||
| 183 | protected $routes; |
||
| 184 | |||
| 185 | /** |
||
| 186 | * The subject only set in edit/update/create mode. |
||
| 187 | * |
||
| 188 | * @var object|null |
||
| 189 | */ |
||
| 190 | protected $subject; |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}. |
||
| 194 | * |
||
| 195 | * @var array |
||
| 196 | */ |
||
| 197 | protected $children = []; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Reference the parent admin. |
||
| 201 | * |
||
| 202 | * @var AdminInterface|null |
||
| 203 | */ |
||
| 204 | protected $parent; |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Reference the parent FieldDescription related to this admin |
||
| 208 | * only set for FieldDescription which is associated to an Sub Admin instance. |
||
| 209 | * |
||
| 210 | * @var FieldDescriptionInterface |
||
| 211 | */ |
||
| 212 | protected $parentFieldDescription; |
||
| 213 | |||
| 214 | /** |
||
| 215 | * If true then the current admin is part of the nested admin set (from the url). |
||
| 216 | * |
||
| 217 | * @var bool |
||
| 218 | */ |
||
| 219 | protected $currentChild = false; |
||
| 220 | |||
| 221 | /** |
||
| 222 | * The uniqid is used to avoid clashing with 2 admin related to the code |
||
| 223 | * ie: a Block linked to a Block. |
||
| 224 | * |
||
| 225 | * @var string |
||
| 226 | */ |
||
| 227 | protected $uniqid; |
||
| 228 | |||
| 229 | /** |
||
| 230 | * The Entity or Document manager. |
||
| 231 | * |
||
| 232 | * @var ModelManagerInterface |
||
| 233 | */ |
||
| 234 | protected $modelManager; |
||
| 235 | |||
| 236 | /** |
||
| 237 | * The current request object. |
||
| 238 | * |
||
| 239 | * @var Request|null |
||
| 240 | */ |
||
| 241 | protected $request; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * The related form contractor. |
||
| 245 | * |
||
| 246 | * @var FormContractorInterface |
||
| 247 | */ |
||
| 248 | protected $formContractor; |
||
| 249 | |||
| 250 | /** |
||
| 251 | * The related list builder. |
||
| 252 | * |
||
| 253 | * @var ListBuilderInterface |
||
| 254 | */ |
||
| 255 | protected $listBuilder; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * The related view builder. |
||
| 259 | * |
||
| 260 | * @var ShowBuilderInterface |
||
| 261 | */ |
||
| 262 | protected $showBuilder; |
||
| 263 | |||
| 264 | /** |
||
| 265 | * The related datagrid builder. |
||
| 266 | * |
||
| 267 | * @var DatagridBuilderInterface |
||
| 268 | */ |
||
| 269 | protected $datagridBuilder; |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @var RouteBuilderInterface |
||
| 273 | */ |
||
| 274 | protected $routeBuilder; |
||
| 275 | |||
| 276 | /** |
||
| 277 | * The datagrid instance. |
||
| 278 | * |
||
| 279 | * @var DatagridInterface|null |
||
| 280 | */ |
||
| 281 | protected $datagrid; |
||
| 282 | |||
| 283 | /** |
||
| 284 | * The router instance. |
||
| 285 | * |
||
| 286 | * @var RouteGeneratorInterface|null |
||
| 287 | */ |
||
| 288 | protected $routeGenerator; |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @var SecurityHandlerInterface |
||
| 292 | */ |
||
| 293 | protected $securityHandler; |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @var ValidatorInterface |
||
| 297 | */ |
||
| 298 | protected $validator; |
||
| 299 | |||
| 300 | /** |
||
| 301 | * The configuration pool. |
||
| 302 | * |
||
| 303 | * @var Pool |
||
| 304 | */ |
||
| 305 | protected $configurationPool; |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @var ItemInterface |
||
| 309 | */ |
||
| 310 | protected $menu; |
||
| 311 | |||
| 312 | /** |
||
| 313 | * @var FactoryInterface |
||
| 314 | */ |
||
| 315 | protected $menuFactory; |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @var array<string, bool> |
||
| 319 | */ |
||
| 320 | protected $loaded = [ |
||
| 321 | 'routes' => false, |
||
| 322 | 'tab_menu' => false, |
||
| 323 | 'show' => false, |
||
| 324 | 'list' => false, |
||
| 325 | 'form' => false, |
||
| 326 | 'datagrid' => false, |
||
| 327 | ]; |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @var string[] |
||
| 331 | */ |
||
| 332 | protected $formTheme = []; |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @var string[] |
||
| 336 | */ |
||
| 337 | protected $filterTheme = []; |
||
| 338 | |||
| 339 | /** |
||
| 340 | * @var AdminExtensionInterface[] |
||
| 341 | */ |
||
| 342 | protected $extensions = []; |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @var LabelTranslatorStrategyInterface |
||
| 346 | */ |
||
| 347 | protected $labelTranslatorStrategy; |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Setting to true will enable preview mode for |
||
| 351 | * the entity and show a preview button in the |
||
| 352 | * edit/create forms. |
||
| 353 | * |
||
| 354 | * @var bool |
||
| 355 | */ |
||
| 356 | protected $supportsPreviewMode = false; |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Roles and permissions per role. |
||
| 360 | * |
||
| 361 | * @var array 'role' => ['permission', 'permission'] |
||
| 362 | */ |
||
| 363 | protected $securityInformation = []; |
||
| 364 | |||
| 365 | protected $cacheIsGranted = []; |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Action list for the search result. |
||
| 369 | * |
||
| 370 | * @var string[] |
||
| 371 | */ |
||
| 372 | protected $searchResultActions = ['edit', 'show']; |
||
| 373 | |||
| 374 | protected $listModes = [ |
||
| 375 | 'list' => [ |
||
| 376 | 'class' => 'fa fa-list fa-fw', |
||
| 377 | ], |
||
| 378 | 'mosaic' => [ |
||
| 379 | 'class' => self::MOSAIC_ICON_CLASS, |
||
| 380 | ], |
||
| 381 | ]; |
||
| 382 | |||
| 383 | /** |
||
| 384 | * The Access mapping. |
||
| 385 | * |
||
| 386 | * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]] |
||
| 387 | */ |
||
| 388 | protected $accessMapping = []; |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @var array |
||
| 392 | */ |
||
| 393 | private $parentAssociationMapping = []; |
||
| 394 | |||
| 395 | /** |
||
| 396 | * @var MutableTemplateRegistryInterface |
||
| 397 | */ |
||
| 398 | private $templateRegistry; |
||
| 399 | |||
| 400 | /** |
||
| 401 | * The class name managed by the admin class. |
||
| 402 | * |
||
| 403 | * @var string |
||
| 404 | */ |
||
| 405 | private $class; |
||
| 406 | |||
| 407 | /** |
||
| 408 | * The subclasses supported by the admin class. |
||
| 409 | * |
||
| 410 | * @var array<string, string> |
||
| 411 | */ |
||
| 412 | private $subClasses = []; |
||
| 413 | |||
| 414 | /** |
||
| 415 | * The list collection. |
||
| 416 | * |
||
| 417 | * @var FieldDescriptionCollection|null |
||
| 418 | */ |
||
| 419 | private $list; |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @var FieldDescriptionCollection|null |
||
| 423 | */ |
||
| 424 | private $show; |
||
| 425 | |||
| 426 | /** |
||
| 427 | * @var Form|null |
||
| 428 | */ |
||
| 429 | private $form; |
||
| 430 | |||
| 431 | /** |
||
| 432 | * The cached base route name. |
||
| 433 | * |
||
| 434 | * @var string |
||
| 435 | */ |
||
| 436 | private $cachedBaseRouteName; |
||
| 437 | |||
| 438 | /** |
||
| 439 | * The cached base route pattern. |
||
| 440 | * |
||
| 441 | * @var string |
||
| 442 | */ |
||
| 443 | private $cachedBaseRoutePattern; |
||
| 444 | |||
| 445 | /** |
||
| 446 | * The form group disposition. |
||
| 447 | * |
||
| 448 | * @var array<string, mixed> |
||
| 449 | */ |
||
| 450 | private $formGroups = []; |
||
| 451 | |||
| 452 | /** |
||
| 453 | * The form tabs disposition. |
||
| 454 | * |
||
| 455 | * @var array<string, mixed> |
||
| 456 | */ |
||
| 457 | private $formTabs = []; |
||
| 458 | |||
| 459 | /** |
||
| 460 | * The view group disposition. |
||
| 461 | * |
||
| 462 | * @var array<string, mixed> |
||
| 463 | */ |
||
| 464 | private $showGroups = []; |
||
| 465 | |||
| 466 | /** |
||
| 467 | * The view tab disposition. |
||
| 468 | * |
||
| 469 | * @var array<string, mixed> |
||
| 470 | */ |
||
| 471 | private $showTabs = []; |
||
| 472 | |||
| 473 | /** |
||
| 474 | * The manager type to use for the admin. |
||
| 475 | * |
||
| 476 | * @var string |
||
| 477 | */ |
||
| 478 | private $managerType; |
||
| 479 | |||
| 480 | /** |
||
| 481 | * Component responsible for persisting filters. |
||
| 482 | * |
||
| 483 | * @var FilterPersisterInterface|null |
||
| 484 | */ |
||
| 485 | private $filterPersister; |
||
| 486 | |||
| 487 | public function __construct(string $code, string $class, ?string $baseControllerName = null) |
||
| 488 | { |
||
| 489 | $this->code = $code; |
||
| 490 | $this->class = $class; |
||
| 491 | $this->baseControllerName = $baseControllerName; |
||
| 492 | } |
||
| 493 | |||
| 494 | /** |
||
| 495 | * {@inheritdoc} |
||
| 496 | */ |
||
| 497 | public function getExportFormats(): array |
||
| 498 | { |
||
| 499 | return [ |
||
| 500 | 'json', 'xml', 'csv', 'xls', |
||
| 501 | ]; |
||
| 502 | } |
||
| 503 | |||
| 504 | /** |
||
| 505 | * {@inheritdoc} |
||
| 506 | */ |
||
| 507 | public function getExportFields(): array |
||
| 508 | { |
||
| 509 | $fields = $this->getModelManager()->getExportFields($this->getClass()); |
||
| 510 | |||
| 511 | foreach ($this->getExtensions() as $extension) { |
||
| 512 | if (method_exists($extension, 'configureExportFields')) { |
||
| 513 | $fields = $extension->configureExportFields($this, $fields); |
||
| 514 | } |
||
| 515 | } |
||
| 516 | |||
| 517 | return $fields; |
||
| 518 | } |
||
| 519 | |||
| 520 | public function getDataSourceIterator(): SourceIteratorInterface |
||
| 521 | { |
||
| 522 | $datagrid = $this->getDatagrid(); |
||
| 523 | $datagrid->buildPager(); |
||
| 524 | |||
| 525 | $fields = []; |
||
| 526 | |||
| 527 | foreach ($this->getExportFields() as $key => $field) { |
||
| 528 | $fields[$key] = $this->getTranslationLabel($field, 'export', 'label'); |
||
| 529 | } |
||
| 530 | |||
| 531 | return $this->getModelManager()->getDataSourceIterator($datagrid, $fields); |
||
| 532 | } |
||
| 533 | |||
| 534 | public function validate(ErrorElement $errorElement, $object): void |
||
| 535 | { |
||
| 536 | } |
||
| 537 | |||
| 538 | /** |
||
| 539 | * define custom variable. |
||
| 540 | */ |
||
| 541 | public function initialize(): void |
||
| 542 | { |
||
| 543 | if (!$this->classnameLabel) { |
||
| 544 | $this->classnameLabel = substr($this->getClass(), strrpos($this->getClass(), '\\') + 1); |
||
| 545 | } |
||
| 546 | |||
| 547 | $this->configure(); |
||
| 548 | } |
||
| 549 | |||
| 550 | public function update(object $object): object |
||
| 551 | { |
||
| 552 | $this->preUpdate($object); |
||
| 553 | foreach ($this->extensions as $extension) { |
||
| 554 | $extension->preUpdate($this, $object); |
||
| 555 | } |
||
| 556 | |||
| 557 | $result = $this->getModelManager()->update($object); |
||
| 558 | // BC compatibility |
||
| 559 | if (null !== $result) { |
||
| 560 | $object = $result; |
||
| 561 | } |
||
| 562 | |||
| 563 | $this->postUpdate($object); |
||
| 564 | foreach ($this->extensions as $extension) { |
||
| 565 | $extension->postUpdate($this, $object); |
||
| 566 | } |
||
| 567 | |||
| 568 | return $object; |
||
| 569 | } |
||
| 570 | |||
| 571 | public function create(object $object): object |
||
| 572 | { |
||
| 573 | $this->prePersist($object); |
||
| 574 | foreach ($this->extensions as $extension) { |
||
| 575 | $extension->prePersist($this, $object); |
||
| 576 | } |
||
| 577 | |||
| 578 | $result = $this->getModelManager()->create($object); |
||
| 579 | // BC compatibility |
||
| 580 | if (null !== $result) { |
||
| 581 | $object = $result; |
||
| 582 | } |
||
| 583 | |||
| 584 | $this->postPersist($object); |
||
| 585 | foreach ($this->extensions as $extension) { |
||
| 586 | $extension->postPersist($this, $object); |
||
| 587 | } |
||
| 588 | |||
| 589 | $this->createObjectSecurity($object); |
||
| 590 | |||
| 591 | return $object; |
||
| 592 | } |
||
| 593 | |||
| 594 | public function delete(object $object): void |
||
| 595 | { |
||
| 596 | $this->preRemove($object); |
||
| 597 | foreach ($this->extensions as $extension) { |
||
| 598 | $extension->preRemove($this, $object); |
||
| 599 | } |
||
| 600 | |||
| 601 | $this->getSecurityHandler()->deleteObjectSecurity($this, $object); |
||
| 602 | $this->getModelManager()->delete($object); |
||
| 603 | |||
| 604 | $this->postRemove($object); |
||
| 605 | foreach ($this->extensions as $extension) { |
||
| 606 | $extension->postRemove($this, $object); |
||
| 607 | } |
||
| 608 | } |
||
| 609 | |||
| 610 | public function preValidate(object $object): void |
||
| 611 | { |
||
| 612 | } |
||
| 613 | |||
| 614 | public function preUpdate(object $object): void |
||
| 615 | { |
||
| 616 | } |
||
| 617 | |||
| 618 | public function postUpdate(object $object): void |
||
| 619 | { |
||
| 620 | } |
||
| 621 | |||
| 622 | public function prePersist(object $object): void |
||
| 623 | { |
||
| 624 | } |
||
| 625 | |||
| 626 | public function postPersist(object $object): void |
||
| 627 | { |
||
| 628 | } |
||
| 629 | |||
| 630 | public function preRemove(object $object): void |
||
| 631 | { |
||
| 632 | } |
||
| 633 | |||
| 634 | public function postRemove(object $object): void |
||
| 635 | { |
||
| 636 | } |
||
| 637 | |||
| 638 | public function preBatchAction(string $actionName, ProxyQueryInterface $query, array &$idx, bool $allElements = false): void |
||
| 639 | { |
||
| 640 | } |
||
| 641 | |||
| 642 | public function getFilterParameters(): array |
||
| 643 | { |
||
| 644 | $parameters = []; |
||
| 645 | |||
| 646 | // build the values array |
||
| 647 | if ($this->hasRequest()) { |
||
| 648 | $filters = $this->request->query->get('filter', []); |
||
| 649 | if (isset($filters['_page'])) { |
||
| 650 | $filters['_page'] = (int) $filters['_page']; |
||
| 651 | } |
||
| 652 | if (isset($filters['_per_page'])) { |
||
| 653 | $filters['_per_page'] = (int) $filters['_per_page']; |
||
| 654 | } |
||
| 655 | |||
| 656 | // if filter persistence is configured |
||
| 657 | if (null !== $this->filterPersister) { |
||
| 658 | // if reset filters is asked, remove from storage |
||
| 659 | if ('reset' === $this->request->query->get('filters')) { |
||
| 660 | $this->filterPersister->reset($this->getCode()); |
||
| 661 | } |
||
| 662 | |||
| 663 | // if no filters, fetch from storage |
||
| 664 | // otherwise save to storage |
||
| 665 | if (empty($filters)) { |
||
| 666 | $filters = $this->filterPersister->get($this->getCode()); |
||
| 667 | } else { |
||
| 668 | $this->filterPersister->set($this->getCode(), $filters); |
||
| 669 | } |
||
| 670 | } |
||
| 671 | |||
| 672 | $parameters = array_merge( |
||
| 673 | $this->getModelManager()->getDefaultSortValues($this->getClass()), |
||
| 674 | $this->getDefaultSortValues(), |
||
| 675 | $this->getDefaultFilterValues(), |
||
| 676 | $filters |
||
| 677 | ); |
||
| 678 | |||
| 679 | if (!$this->determinedPerPageValue($parameters['_per_page'])) { |
||
| 680 | $parameters['_per_page'] = $this->getMaxPerPage(); |
||
| 681 | } |
||
| 682 | |||
| 683 | // always force the parent value |
||
| 684 | if ($this->isChild() && $this->getParentAssociationMapping()) { |
||
| 685 | $name = str_replace('.', '__', $this->getParentAssociationMapping()); |
||
| 686 | $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())]; |
||
| 687 | } |
||
| 688 | } |
||
| 689 | |||
| 690 | return $parameters; |
||
| 691 | } |
||
| 692 | |||
| 693 | /** |
||
| 694 | * Returns the name of the parent related field, so the field can be use to set the default |
||
| 695 | * value (ie the parent object) or to filter the object. |
||
| 696 | * |
||
| 697 | * @throws \InvalidArgumentException |
||
| 698 | */ |
||
| 699 | public function getParentAssociationMapping(): ?string |
||
| 700 | { |
||
| 701 | if ($this->isChild()) { |
||
| 702 | $parent = $this->getParent()->getCode(); |
||
| 703 | |||
| 704 | if (\array_key_exists($parent, $this->parentAssociationMapping)) { |
||
| 705 | return $this->parentAssociationMapping[$parent]; |
||
| 706 | } |
||
| 707 | |||
| 708 | throw new \InvalidArgumentException(sprintf( |
||
| 709 | 'There\'s no association between %s and %s.', |
||
| 710 | $this->getCode(), |
||
| 711 | $this->getParent()->getCode() |
||
| 712 | )); |
||
| 713 | } |
||
| 714 | |||
| 715 | return null; |
||
| 716 | } |
||
| 717 | |||
| 718 | final public function addParentAssociationMapping(string $code, string $value): void |
||
| 719 | { |
||
| 720 | $this->parentAssociationMapping[$code] = $value; |
||
| 721 | } |
||
| 722 | |||
| 723 | /** |
||
| 724 | * Returns the baseRoutePattern used to generate the routing information. |
||
| 725 | * |
||
| 726 | * @throws \RuntimeException |
||
| 727 | * |
||
| 728 | * @return string the baseRoutePattern used to generate the routing information |
||
| 729 | */ |
||
| 730 | public function getBaseRoutePattern(): string |
||
| 731 | { |
||
| 732 | if (null !== $this->cachedBaseRoutePattern) { |
||
| 733 | return $this->cachedBaseRoutePattern; |
||
| 734 | } |
||
| 735 | |||
| 736 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern |
||
| 737 | $baseRoutePattern = $this->baseRoutePattern; |
||
| 738 | if (!$this->baseRoutePattern) { |
||
| 739 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
| 740 | |||
| 741 | if (!$matches) { |
||
| 742 | throw new \RuntimeException(sprintf( |
||
| 743 | 'Please define a default `baseRoutePattern` value for the admin class `%s`', |
||
| 744 | static::class |
||
| 745 | )); |
||
| 746 | } |
||
| 747 | $baseRoutePattern = $this->urlize($matches[5], '-'); |
||
| 748 | } |
||
| 749 | |||
| 750 | $this->cachedBaseRoutePattern = sprintf( |
||
| 751 | '%s/%s/%s', |
||
| 752 | $this->getParent()->getBaseRoutePattern(), |
||
| 753 | $this->getParent()->getRouterIdParameter(), |
||
| 754 | $baseRoutePattern |
||
| 755 | ); |
||
| 756 | } elseif ($this->baseRoutePattern) { |
||
| 757 | $this->cachedBaseRoutePattern = $this->baseRoutePattern; |
||
| 758 | } else { |
||
| 759 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
| 760 | |||
| 761 | if (!$matches) { |
||
| 762 | throw new \RuntimeException(sprintf( |
||
| 763 | 'Please define a default `baseRoutePattern` value for the admin class `%s`', |
||
| 764 | static::class |
||
| 765 | )); |
||
| 766 | } |
||
| 767 | |||
| 768 | $this->cachedBaseRoutePattern = sprintf( |
||
| 769 | '/%s%s/%s', |
||
| 770 | empty($matches[1]) ? '' : $this->urlize($matches[1], '-').'/', |
||
| 771 | $this->urlize($matches[3], '-'), |
||
| 772 | $this->urlize($matches[5], '-') |
||
| 773 | ); |
||
| 774 | } |
||
| 775 | |||
| 776 | return $this->cachedBaseRoutePattern; |
||
| 777 | } |
||
| 778 | |||
| 779 | /** |
||
| 780 | * Returns the baseRouteName used to generate the routing information. |
||
| 781 | * |
||
| 782 | * @throws \RuntimeException |
||
| 783 | * |
||
| 784 | * @return string the baseRouteName used to generate the routing information |
||
| 785 | */ |
||
| 786 | public function getBaseRouteName(): string |
||
| 787 | { |
||
| 788 | if (null !== $this->cachedBaseRouteName) { |
||
| 789 | return $this->cachedBaseRouteName; |
||
| 790 | } |
||
| 791 | |||
| 792 | if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name |
||
| 793 | $baseRouteName = $this->baseRouteName; |
||
| 794 | if (!$this->baseRouteName) { |
||
| 795 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
| 796 | |||
| 797 | if (!$matches) { |
||
| 798 | throw new \RuntimeException(sprintf( |
||
| 799 | 'Cannot automatically determine base route name,' |
||
| 800 | .' please define a default `baseRouteName` value for the admin class `%s`', |
||
| 801 | static::class |
||
| 802 | )); |
||
| 803 | } |
||
| 804 | $baseRouteName = $this->urlize($matches[5]); |
||
| 805 | } |
||
| 806 | |||
| 807 | $this->cachedBaseRouteName = sprintf( |
||
| 808 | '%s_%s', |
||
| 809 | $this->getParent()->getBaseRouteName(), |
||
| 810 | $baseRouteName |
||
| 811 | ); |
||
| 812 | } elseif ($this->baseRouteName) { |
||
| 813 | $this->cachedBaseRouteName = $this->baseRouteName; |
||
| 814 | } else { |
||
| 815 | preg_match(self::CLASS_REGEX, $this->class, $matches); |
||
| 816 | |||
| 817 | if (!$matches) { |
||
| 818 | throw new \RuntimeException(sprintf( |
||
| 819 | 'Cannot automatically determine base route name,' |
||
| 820 | .' please define a default `baseRouteName` value for the admin class `%s`', |
||
| 821 | static::class |
||
| 822 | )); |
||
| 823 | } |
||
| 824 | |||
| 825 | $this->cachedBaseRouteName = sprintf( |
||
| 826 | 'admin_%s%s_%s', |
||
| 827 | empty($matches[1]) ? '' : $this->urlize($matches[1]).'_', |
||
| 828 | $this->urlize($matches[3]), |
||
| 829 | $this->urlize($matches[5]) |
||
| 830 | ); |
||
| 831 | } |
||
| 832 | |||
| 833 | return $this->cachedBaseRouteName; |
||
| 834 | } |
||
| 835 | |||
| 836 | public function getClass(): string |
||
| 837 | { |
||
| 838 | if ($this->hasActiveSubClass()) { |
||
| 839 | if ($this->hasParentFieldDescription()) { |
||
| 840 | throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass'); |
||
| 841 | } |
||
| 842 | |||
| 843 | $subClass = $this->getRequest()->query->get('subclass'); |
||
| 844 | |||
| 845 | if (!$this->hasSubClass($subClass)) { |
||
| 846 | throw new \RuntimeException(sprintf('Subclass "%s" is not defined.', $subClass)); |
||
| 847 | } |
||
| 848 | |||
| 849 | return $this->getSubClass($subClass); |
||
| 850 | } |
||
| 851 | |||
| 852 | // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 |
||
| 853 | if ($this->subject && \is_object($this->subject)) { |
||
| 854 | return ClassUtils::getClass($this->subject); |
||
| 855 | } |
||
| 856 | |||
| 857 | return $this->class; |
||
| 858 | } |
||
| 859 | |||
| 860 | public function getSubClasses(): array |
||
| 861 | { |
||
| 862 | return $this->subClasses; |
||
| 863 | } |
||
| 864 | |||
| 865 | public function setSubClasses(array $subClasses): void |
||
| 866 | { |
||
| 867 | $this->subClasses = $subClasses; |
||
| 868 | } |
||
| 869 | |||
| 870 | public function hasSubClass(string $name): bool |
||
| 871 | { |
||
| 872 | return isset($this->subClasses[$name]); |
||
| 873 | } |
||
| 874 | |||
| 875 | public function hasActiveSubClass(): bool |
||
| 876 | { |
||
| 877 | if (\count($this->subClasses) > 0 && $this->request) { |
||
| 878 | return null !== $this->getRequest()->query->get('subclass'); |
||
| 879 | } |
||
| 880 | |||
| 881 | return false; |
||
| 882 | } |
||
| 883 | |||
| 884 | public function getActiveSubClass(): string |
||
| 885 | { |
||
| 886 | if (!$this->hasActiveSubClass()) { |
||
| 887 | throw new \LogicException(sprintf( |
||
| 888 | 'Admin "%s" has no active subclass.', |
||
| 889 | static::class |
||
| 890 | )); |
||
| 891 | } |
||
| 892 | |||
| 893 | return $this->getSubClass($this->getActiveSubclassCode()); |
||
| 894 | } |
||
| 895 | |||
| 896 | public function getActiveSubclassCode(): string |
||
| 897 | { |
||
| 898 | if (!$this->hasActiveSubClass()) { |
||
| 899 | throw new \LogicException(sprintf( |
||
| 900 | 'Admin "%s" has no active subclass.', |
||
| 901 | static::class |
||
| 902 | )); |
||
| 903 | } |
||
| 904 | |||
| 905 | $subClass = $this->getRequest()->query->get('subclass'); |
||
| 906 | |||
| 907 | if (!$this->hasSubClass($subClass)) { |
||
| 908 | throw new \LogicException(sprintf( |
||
| 909 | 'Admin "%s" has no active subclass.', |
||
| 910 | static::class |
||
| 911 | )); |
||
| 912 | } |
||
| 913 | |||
| 914 | return $subClass; |
||
| 915 | } |
||
| 916 | |||
| 917 | public function getBatchActions(): array |
||
| 918 | { |
||
| 919 | $actions = []; |
||
| 920 | |||
| 921 | if ($this->hasRoute('delete') && $this->hasAccess('delete')) { |
||
| 922 | $actions['delete'] = [ |
||
| 923 | 'label' => 'action_delete', |
||
| 924 | 'translation_domain' => 'SonataAdminBundle', |
||
| 925 | 'ask_confirmation' => true, // by default always true |
||
| 926 | ]; |
||
| 927 | } |
||
| 928 | |||
| 929 | $actions = $this->configureBatchActions($actions); |
||
| 930 | |||
| 931 | foreach ($this->getExtensions() as $extension) { |
||
| 932 | $actions = $extension->configureBatchActions($this, $actions); |
||
| 933 | } |
||
| 934 | |||
| 935 | foreach ($actions as $name => &$action) { |
||
| 936 | if (!\array_key_exists('label', $action)) { |
||
| 937 | $action['label'] = $this->getTranslationLabel($name, 'batch', 'label'); |
||
| 938 | } |
||
| 939 | |||
| 940 | if (!\array_key_exists('translation_domain', $action)) { |
||
| 941 | $action['translation_domain'] = $this->getTranslationDomain(); |
||
| 942 | } |
||
| 943 | } |
||
| 944 | |||
| 945 | return $actions; |
||
| 946 | } |
||
| 947 | |||
| 948 | /** |
||
| 949 | * NEXT_MAJOR: Create a `RouteCollectionInterface` and use as return type. |
||
| 950 | */ |
||
| 951 | public function getRoutes(): RouteCollection |
||
| 952 | { |
||
| 953 | $this->buildRoutes(); |
||
| 954 | |||
| 955 | return $this->routes; |
||
| 956 | } |
||
| 957 | |||
| 958 | public function getRouterIdParameter(): string |
||
| 959 | { |
||
| 960 | return sprintf('{%s}', $this->getIdParameter()); |
||
| 961 | } |
||
| 962 | |||
| 963 | public function getIdParameter(): string |
||
| 964 | { |
||
| 965 | $parameter = 'id'; |
||
| 966 | |||
| 967 | for ($i = 0; $i < $this->getChildDepth(); ++$i) { |
||
| 968 | $parameter = sprintf('child%s', ucfirst($parameter)); |
||
| 969 | } |
||
| 970 | |||
| 971 | return $parameter; |
||
| 972 | } |
||
| 973 | |||
| 974 | public function hasRoute(string $name): bool |
||
| 975 | { |
||
| 976 | if (!$this->routeGenerator) { |
||
| 977 | throw new \RuntimeException('RouteGenerator cannot be null'); |
||
| 978 | } |
||
| 979 | |||
| 980 | return $this->routeGenerator->hasAdminRoute($this, $name); |
||
| 981 | } |
||
| 982 | |||
| 983 | public function isCurrentRoute(string $name, ?string $adminCode = null): bool |
||
| 984 | { |
||
| 985 | if (!$this->hasRequest()) { |
||
| 986 | return false; |
||
| 987 | } |
||
| 988 | |||
| 989 | $request = $this->getRequest(); |
||
| 990 | $route = $request->get('_route'); |
||
| 991 | |||
| 992 | if ($adminCode) { |
||
| 993 | $admin = $this->getConfigurationPool()->getAdminByAdminCode($adminCode); |
||
| 994 | } else { |
||
| 995 | $admin = $this; |
||
| 996 | } |
||
| 997 | |||
| 998 | if (!$admin) { |
||
| 999 | return false; |
||
| 1000 | } |
||
| 1001 | |||
| 1002 | return sprintf('%s_%s', $admin->getBaseRouteName(), $name) === $route; |
||
| 1003 | } |
||
| 1004 | |||
| 1005 | public function generateObjectUrl(string $name, object $object, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string |
||
| 1006 | { |
||
| 1007 | $parameters['id'] = $this->getUrlSafeIdentifier($object); |
||
| 1008 | |||
| 1009 | return $this->generateUrl($name, $parameters, $referenceType); |
||
| 1010 | } |
||
| 1011 | |||
| 1012 | public function generateUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string |
||
| 1013 | { |
||
| 1014 | return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); |
||
| 1015 | } |
||
| 1016 | |||
| 1017 | public function generateMenuUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): array |
||
| 1018 | { |
||
| 1019 | return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void |
||
| 1023 | { |
||
| 1024 | $this->templateRegistry = $templateRegistry; |
||
| 1025 | } |
||
| 1026 | |||
| 1027 | /** |
||
| 1028 | * @param array<string, string> $templates |
||
| 1029 | */ |
||
| 1030 | public function setTemplates(array $templates): void |
||
| 1031 | { |
||
| 1032 | $this->getTemplateRegistry()->setTemplates($templates); |
||
| 1033 | } |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * {@inheritdoc} |
||
| 1037 | */ |
||
| 1038 | public function setTemplate(string $name, string $template): void |
||
| 1039 | { |
||
| 1040 | $this->getTemplateRegistry()->setTemplate($name, $template); |
||
| 1041 | } |
||
| 1042 | |||
| 1043 | public function getNewInstance(): object |
||
| 1044 | { |
||
| 1045 | $object = $this->getModelManager()->getModelInstance($this->getClass()); |
||
| 1046 | |||
| 1047 | $this->appendParentObject($object); |
||
| 1048 | |||
| 1049 | foreach ($this->getExtensions() as $extension) { |
||
| 1050 | $extension->alterNewInstance($this, $object); |
||
| 1051 | } |
||
| 1052 | |||
| 1053 | return $object; |
||
| 1054 | } |
||
| 1055 | |||
| 1056 | public function getFormBuilder(): FormBuilderInterface |
||
| 1057 | { |
||
| 1058 | $this->formOptions['data_class'] = $this->getClass(); |
||
| 1059 | |||
| 1060 | $formBuilder = $this->getFormContractor()->getFormBuilder( |
||
| 1061 | $this->getUniqid(), |
||
| 1062 | $this->formOptions |
||
| 1063 | ); |
||
| 1064 | |||
| 1065 | $this->defineFormBuilder($formBuilder); |
||
| 1066 | |||
| 1067 | return $formBuilder; |
||
| 1068 | } |
||
| 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 |
||
| 1075 | { |
||
| 1076 | if (!$this->hasSubject()) { |
||
| 1077 | throw new \LogicException(sprintf( |
||
| 1078 | 'Admin "%s" has no subject.', |
||
| 1079 | static::class |
||
| 1080 | )); |
||
| 1081 | } |
||
| 1082 | |||
| 1083 | $mapper = new FormMapper($this->getFormContractor(), $formBuilder, $this); |
||
| 1084 | |||
| 1085 | $this->configureFormFields($mapper); |
||
| 1086 | |||
| 1087 | foreach ($this->getExtensions() as $extension) { |
||
| 1088 | $extension->configureFormFields($mapper); |
||
| 1089 | } |
||
| 1090 | |||
| 1091 | $this->attachInlineValidator(); |
||
| 1092 | } |
||
| 1093 | |||
| 1094 | public function attachAdminClass(FieldDescriptionInterface $fieldDescription): void |
||
| 1095 | { |
||
| 1096 | $pool = $this->getConfigurationPool(); |
||
| 1097 | |||
| 1098 | $adminCode = $fieldDescription->getOption('admin_code'); |
||
| 1099 | |||
| 1100 | if (null !== $adminCode) { |
||
| 1101 | if (!$pool->hasAdminByAdminCode($adminCode)) { |
||
| 1102 | return; |
||
| 1103 | } |
||
| 1104 | |||
| 1105 | $admin = $pool->getAdminByAdminCode($adminCode); |
||
| 1106 | } else { |
||
| 1107 | $targetModel = $fieldDescription->getTargetModel(); |
||
| 1108 | |||
| 1109 | if (!$pool->hasAdminByClass($targetModel)) { |
||
| 1110 | return; |
||
| 1111 | } |
||
| 1112 | |||
| 1113 | $admin = $pool->getAdminByClass($targetModel); |
||
| 1114 | } |
||
| 1115 | |||
| 1116 | if ($this->hasRequest()) { |
||
| 1117 | $admin->setRequest($this->getRequest()); |
||
| 1118 | } |
||
| 1119 | |||
| 1120 | $fieldDescription->setAssociationAdmin($admin); |
||
| 1121 | } |
||
| 1122 | |||
| 1123 | public function getObject($id): ?object |
||
| 1124 | { |
||
| 1125 | $object = $this->getModelManager()->find($this->getClass(), $id); |
||
| 1126 | foreach ($this->getExtensions() as $extension) { |
||
| 1127 | $extension->alterObject($this, $object); |
||
| 1128 | } |
||
| 1129 | |||
| 1130 | return $object; |
||
| 1131 | } |
||
| 1132 | |||
| 1133 | public function getForm(): ?FormInterface |
||
| 1134 | { |
||
| 1135 | $this->buildForm(); |
||
| 1136 | |||
| 1137 | return $this->form; |
||
| 1138 | } |
||
| 1139 | |||
| 1140 | public function getList(): ?FieldDescriptionCollection |
||
| 1141 | { |
||
| 1142 | $this->buildList(); |
||
| 1143 | |||
| 1144 | return $this->list; |
||
| 1145 | } |
||
| 1146 | |||
| 1147 | /** |
||
| 1148 | * @final since sonata-project/admin-bundle 3.63.0 |
||
| 1149 | */ |
||
| 1150 | public function createQuery(): ProxyQueryInterface |
||
| 1151 | { |
||
| 1152 | $query = $this->getModelManager()->createQuery($this->getClass()); |
||
| 1153 | |||
| 1154 | $query = $this->configureQuery($query); |
||
| 1155 | foreach ($this->extensions as $extension) { |
||
| 1156 | $extension->configureQuery($this, $query); |
||
| 1157 | } |
||
| 1158 | |||
| 1159 | return $query; |
||
| 1160 | } |
||
| 1161 | |||
| 1162 | public function getDatagrid(): DatagridInterface |
||
| 1163 | { |
||
| 1164 | $this->buildDatagrid(); |
||
| 1165 | |||
| 1166 | return $this->datagrid; |
||
| 1167 | } |
||
| 1168 | |||
| 1169 | public function buildTabMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface |
||
| 1170 | { |
||
| 1171 | if ($this->loaded['tab_menu']) { |
||
| 1172 | return $this->menu; |
||
| 1173 | } |
||
| 1174 | |||
| 1175 | $this->loaded['tab_menu'] = true; |
||
| 1176 | |||
| 1177 | $menu = $this->menuFactory->createItem('root'); |
||
| 1178 | $menu->setChildrenAttribute('class', 'nav navbar-nav'); |
||
| 1179 | $menu->setExtra('translation_domain', $this->translationDomain); |
||
| 1180 | |||
| 1181 | // Prevents BC break with KnpMenuBundle v1.x |
||
| 1182 | if (method_exists($menu, 'setCurrentUri')) { |
||
| 1183 | $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo()); |
||
| 1184 | } |
||
| 1185 | |||
| 1186 | $this->configureTabMenu($menu, $action, $childAdmin); |
||
| 1187 | |||
| 1188 | foreach ($this->getExtensions() as $extension) { |
||
| 1189 | $extension->configureTabMenu($this, $menu, $action, $childAdmin); |
||
| 1190 | } |
||
| 1191 | |||
| 1192 | $this->menu = $menu; |
||
| 1193 | |||
| 1194 | return $this->menu; |
||
| 1195 | } |
||
| 1196 | |||
| 1197 | public function getSideMenu(string $action, ?AdminInterface $childAdmin = null): ItemInterface |
||
| 1198 | { |
||
| 1199 | if ($this->isChild()) { |
||
| 1200 | return $this->getParent()->getSideMenu($action, $this); |
||
| 1201 | } |
||
| 1202 | |||
| 1203 | $this->buildTabMenu($action, $childAdmin); |
||
| 1204 | |||
| 1205 | return $this->menu; |
||
| 1206 | } |
||
| 1207 | |||
| 1208 | public function getRootCode(): string |
||
| 1209 | { |
||
| 1210 | return $this->getRoot()->getCode(); |
||
| 1211 | } |
||
| 1212 | |||
| 1213 | public function getRoot(): AdminInterface |
||
| 1214 | { |
||
| 1215 | if (!$this->hasParentFieldDescription()) { |
||
| 1216 | return $this; |
||
| 1217 | } |
||
| 1218 | |||
| 1219 | return $this->getParentFieldDescription()->getAdmin()->getRoot(); |
||
| 1220 | } |
||
| 1221 | |||
| 1222 | public function setBaseControllerName(string $baseControllerName): void |
||
| 1223 | { |
||
| 1224 | $this->baseControllerName = $baseControllerName; |
||
| 1225 | } |
||
| 1226 | |||
| 1227 | public function getBaseControllerName(): string |
||
| 1228 | { |
||
| 1229 | return $this->baseControllerName; |
||
| 1230 | } |
||
| 1231 | |||
| 1232 | public function setLabel(?string $label): void |
||
| 1233 | { |
||
| 1234 | $this->label = $label; |
||
| 1235 | } |
||
| 1236 | |||
| 1237 | public function getLabel(): ?string |
||
| 1238 | { |
||
| 1239 | return $this->label; |
||
| 1240 | } |
||
| 1241 | |||
| 1242 | public function setFilterPersister(?FilterPersisterInterface $filterPersister = null): void |
||
| 1243 | { |
||
| 1244 | $this->filterPersister = $filterPersister; |
||
| 1245 | } |
||
| 1246 | |||
| 1247 | public function getMaxPerPage(): int |
||
| 1248 | { |
||
| 1249 | $sortValues = $this->getModelManager()->getDefaultSortValues($this->class); |
||
| 1250 | |||
| 1251 | return $sortValues['_per_page'] ?? 25; |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | public function setMaxPageLinks(int $maxPageLinks): void |
||
| 1255 | { |
||
| 1256 | $this->maxPageLinks = $maxPageLinks; |
||
| 1257 | } |
||
| 1258 | |||
| 1259 | public function getMaxPageLinks(): int |
||
| 1260 | { |
||
| 1261 | return $this->maxPageLinks; |
||
| 1262 | } |
||
| 1263 | |||
| 1264 | public function getFormGroups(): array |
||
| 1265 | { |
||
| 1266 | return $this->formGroups; |
||
| 1267 | } |
||
| 1268 | |||
| 1269 | public function setFormGroups(array $formGroups): void |
||
| 1270 | { |
||
| 1271 | $this->formGroups = $formGroups; |
||
| 1272 | } |
||
| 1273 | |||
| 1274 | public function removeFieldFromFormGroup(string $key): void |
||
| 1275 | { |
||
| 1276 | foreach ($this->formGroups as $name => $formGroup) { |
||
| 1277 | unset($this->formGroups[$name]['fields'][$key]); |
||
| 1278 | |||
| 1279 | if (empty($this->formGroups[$name]['fields'])) { |
||
| 1280 | unset($this->formGroups[$name]); |
||
| 1281 | } |
||
| 1282 | } |
||
| 1283 | } |
||
| 1284 | |||
| 1285 | public function reorderFormGroup(string $group, array $keys): void |
||
| 1286 | { |
||
| 1287 | $formGroups = $this->getFormGroups(); |
||
| 1288 | $formGroups[$group]['fields'] = array_merge(array_flip($keys), $formGroups[$group]['fields']); |
||
| 1289 | $this->setFormGroups($formGroups); |
||
| 1290 | } |
||
| 1291 | |||
| 1292 | public function getFormTabs(): array |
||
| 1293 | { |
||
| 1294 | return $this->formTabs; |
||
| 1295 | } |
||
| 1296 | |||
| 1297 | public function setFormTabs(array $formTabs): void |
||
| 1298 | { |
||
| 1299 | $this->formTabs = $formTabs; |
||
| 1300 | } |
||
| 1301 | |||
| 1302 | public function getShowTabs(): array |
||
| 1303 | { |
||
| 1304 | return $this->showTabs; |
||
| 1305 | } |
||
| 1306 | |||
| 1307 | public function setShowTabs(array $showTabs): void |
||
| 1308 | { |
||
| 1309 | $this->showTabs = $showTabs; |
||
| 1310 | } |
||
| 1311 | |||
| 1312 | public function getShowGroups(): array |
||
| 1313 | { |
||
| 1314 | return $this->showGroups; |
||
| 1315 | } |
||
| 1316 | |||
| 1317 | public function setShowGroups(array $showGroups): void |
||
| 1318 | { |
||
| 1319 | $this->showGroups = $showGroups; |
||
| 1320 | } |
||
| 1321 | |||
| 1322 | public function reorderShowGroup(string $group, array $keys): void |
||
| 1323 | { |
||
| 1324 | $showGroups = $this->getShowGroups(); |
||
| 1325 | $showGroups[$group]['fields'] = array_merge(array_flip($keys), $showGroups[$group]['fields']); |
||
| 1326 | $this->setShowGroups($showGroups); |
||
| 1327 | } |
||
| 1328 | |||
| 1329 | public function setParentFieldDescription(?FieldDescriptionInterface $parentFieldDescription): void |
||
| 1330 | { |
||
| 1331 | $this->parentFieldDescription = $parentFieldDescription; |
||
| 1332 | } |
||
| 1333 | |||
| 1334 | public function getParentFieldDescription(): FieldDescriptionInterface |
||
| 1335 | { |
||
| 1336 | if (!$this->hasParentFieldDescription()) { |
||
| 1337 | throw new \LogicException(sprintf( |
||
| 1338 | 'Admin "%s" has no parent field description.', |
||
| 1339 | static::class |
||
| 1340 | )); |
||
| 1341 | } |
||
| 1342 | |||
| 1343 | return $this->parentFieldDescription; |
||
| 1344 | } |
||
| 1345 | |||
| 1346 | public function hasParentFieldDescription(): bool |
||
| 1347 | { |
||
| 1348 | return $this->parentFieldDescription instanceof FieldDescriptionInterface; |
||
| 1349 | } |
||
| 1350 | |||
| 1351 | public function setSubject(?object $subject): void |
||
| 1352 | { |
||
| 1353 | if (\is_object($subject) && !is_a($subject, $this->getClass(), true)) { |
||
| 1354 | $message = <<<'EOT' |
||
| 1355 | You are trying to set entity an instance of "%s", |
||
| 1356 | which is not the one registered with this admin class ("%s"). |
||
| 1357 | This is deprecated since 3.5 and will no longer be supported in 4.0. |
||
| 1358 | EOT; |
||
| 1359 | |||
| 1360 | // NEXT_MAJOR : throw an exception instead |
||
| 1361 | @trigger_error(sprintf($message, \get_class($subject), $this->getClass()), E_USER_DEPRECATED); |
||
| 1362 | } |
||
| 1363 | |||
| 1364 | $this->subject = $subject; |
||
| 1365 | } |
||
| 1366 | |||
| 1367 | public function getSubject(): object |
||
| 1368 | { |
||
| 1369 | if (!$this->hasSubject()) { |
||
| 1370 | throw new \LogicException(sprintf( |
||
| 1371 | 'Admin "%s" has no subject.', |
||
| 1372 | static::class |
||
| 1373 | )); |
||
| 1374 | } |
||
| 1375 | |||
| 1376 | return $this->subject; |
||
| 1377 | } |
||
| 1378 | |||
| 1379 | public function hasSubject(): bool |
||
| 1380 | { |
||
| 1381 | if (null === $this->subject && $this->hasRequest() && !$this->hasParentFieldDescription()) { |
||
| 1382 | $id = $this->request->get($this->getIdParameter()); |
||
| 1383 | |||
| 1384 | if (null !== $id) { |
||
| 1385 | $this->subject = $this->getObject($id); |
||
| 1386 | } |
||
| 1387 | } |
||
| 1388 | |||
| 1389 | return null !== $this->subject; |
||
| 1390 | } |
||
| 1391 | |||
| 1392 | public function getFormFieldDescriptions(): array |
||
| 1393 | { |
||
| 1394 | $this->buildForm(); |
||
| 1395 | |||
| 1396 | return $this->formFieldDescriptions; |
||
| 1397 | } |
||
| 1398 | |||
| 1399 | public function getFormFieldDescription(string $name): ?FieldDescriptionInterface |
||
| 1400 | { |
||
| 1401 | $this->buildForm(); |
||
| 1402 | |||
| 1403 | if (!$this->hasFormFieldDescription($name)) { |
||
| 1404 | throw new \LogicException(sprintf( |
||
| 1405 | 'Admin "%s" has no form field description for the field %s.', |
||
| 1406 | static::class, |
||
| 1407 | $name |
||
| 1408 | )); |
||
| 1409 | } |
||
| 1410 | |||
| 1411 | return $this->formFieldDescriptions[$name]; |
||
| 1412 | } |
||
| 1413 | |||
| 1414 | /** |
||
| 1415 | * Returns true if the admin has a FieldDescription with the given $name. |
||
| 1416 | */ |
||
| 1417 | public function hasFormFieldDescription(string $name): bool |
||
| 1418 | { |
||
| 1419 | $this->buildForm(); |
||
| 1420 | |||
| 1421 | return \array_key_exists($name, $this->formFieldDescriptions) ? true : false; |
||
| 1422 | } |
||
| 1423 | |||
| 1424 | public function addFormFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
| 1425 | { |
||
| 1426 | $this->formFieldDescriptions[$name] = $fieldDescription; |
||
| 1427 | } |
||
| 1428 | |||
| 1429 | /** |
||
| 1430 | * remove a FieldDescription. |
||
| 1431 | */ |
||
| 1432 | public function removeFormFieldDescription(string $name): void |
||
| 1433 | { |
||
| 1434 | unset($this->formFieldDescriptions[$name]); |
||
| 1435 | } |
||
| 1436 | |||
| 1437 | /** |
||
| 1438 | * build and return the collection of form FieldDescription. |
||
| 1439 | * |
||
| 1440 | * @return FieldDescriptionInterface[] collection of form FieldDescription |
||
| 1441 | */ |
||
| 1442 | public function getShowFieldDescriptions(): array |
||
| 1443 | { |
||
| 1444 | $this->buildShow(); |
||
| 1445 | |||
| 1446 | return $this->showFieldDescriptions; |
||
| 1447 | } |
||
| 1448 | |||
| 1449 | /** |
||
| 1450 | * Returns the form FieldDescription with the given $name. |
||
| 1451 | */ |
||
| 1452 | public function getShowFieldDescription(string $name): FieldDescriptionInterface |
||
| 1453 | { |
||
| 1454 | $this->buildShow(); |
||
| 1455 | |||
| 1456 | if (!$this->hasShowFieldDescription($name)) { |
||
| 1457 | throw new \LogicException(sprintf( |
||
| 1458 | 'Admin "%s" has no show field description for the field %s.', |
||
| 1459 | static::class, |
||
| 1460 | $name |
||
| 1461 | )); |
||
| 1462 | } |
||
| 1463 | |||
| 1464 | return $this->showFieldDescriptions[$name]; |
||
| 1465 | } |
||
| 1466 | |||
| 1467 | public function hasShowFieldDescription(string $name): bool |
||
| 1468 | { |
||
| 1469 | $this->buildShow(); |
||
| 1470 | |||
| 1471 | return \array_key_exists($name, $this->showFieldDescriptions); |
||
| 1472 | } |
||
| 1473 | |||
| 1474 | public function addShowFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
| 1475 | { |
||
| 1476 | $this->showFieldDescriptions[$name] = $fieldDescription; |
||
| 1477 | } |
||
| 1478 | |||
| 1479 | public function removeShowFieldDescription(string $name): void |
||
| 1480 | { |
||
| 1481 | unset($this->showFieldDescriptions[$name]); |
||
| 1482 | } |
||
| 1483 | |||
| 1484 | public function getListFieldDescriptions(): array |
||
| 1485 | { |
||
| 1486 | $this->buildList(); |
||
| 1487 | |||
| 1488 | return $this->listFieldDescriptions; |
||
| 1489 | } |
||
| 1490 | |||
| 1491 | public function getListFieldDescription(string $name): FieldDescriptionInterface |
||
| 1492 | { |
||
| 1493 | $this->buildList(); |
||
| 1494 | |||
| 1495 | if (!$this->hasListFieldDescription($name)) { |
||
| 1496 | throw new \LogicException(sprintf( |
||
| 1497 | 'Admin "%s" has no list field description for %s.', |
||
| 1498 | static::class, |
||
| 1499 | $name |
||
| 1500 | )); |
||
| 1501 | } |
||
| 1502 | |||
| 1503 | return $this->listFieldDescriptions[$name]; |
||
| 1504 | } |
||
| 1505 | |||
| 1506 | public function hasListFieldDescription(string $name): bool |
||
| 1507 | { |
||
| 1508 | $this->buildList(); |
||
| 1509 | |||
| 1510 | return \array_key_exists($name, $this->listFieldDescriptions) ? true : false; |
||
| 1511 | } |
||
| 1512 | |||
| 1513 | public function addListFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
| 1514 | { |
||
| 1515 | $this->listFieldDescriptions[$name] = $fieldDescription; |
||
| 1516 | } |
||
| 1517 | |||
| 1518 | public function removeListFieldDescription(string $name): void |
||
| 1519 | { |
||
| 1520 | unset($this->listFieldDescriptions[$name]); |
||
| 1521 | } |
||
| 1522 | |||
| 1523 | public function getFilterFieldDescription(string $name): FieldDescriptionInterface |
||
| 1524 | { |
||
| 1525 | $this->buildDatagrid(); |
||
| 1526 | |||
| 1527 | if (!$this->hasFilterFieldDescription($name)) { |
||
| 1528 | throw new \LogicException(sprintf( |
||
| 1529 | 'Admin "%s" has no filter field description for the field %s.', |
||
| 1530 | static::class, |
||
| 1531 | $name |
||
| 1532 | )); |
||
| 1533 | } |
||
| 1534 | |||
| 1535 | return $this->filterFieldDescriptions[$name]; |
||
| 1536 | } |
||
| 1537 | |||
| 1538 | public function hasFilterFieldDescription(string $name): bool |
||
| 1539 | { |
||
| 1540 | $this->buildDatagrid(); |
||
| 1541 | |||
| 1542 | return \array_key_exists($name, $this->filterFieldDescriptions) ? true : false; |
||
| 1543 | } |
||
| 1544 | |||
| 1545 | public function addFilterFieldDescription(string $name, FieldDescriptionInterface $fieldDescription): void |
||
| 1546 | { |
||
| 1547 | $this->filterFieldDescriptions[$name] = $fieldDescription; |
||
| 1548 | } |
||
| 1549 | |||
| 1550 | public function removeFilterFieldDescription(string $name): void |
||
| 1551 | { |
||
| 1552 | unset($this->filterFieldDescriptions[$name]); |
||
| 1553 | } |
||
| 1554 | |||
| 1555 | public function getFilterFieldDescriptions(): array |
||
| 1556 | { |
||
| 1557 | $this->buildDatagrid(); |
||
| 1558 | |||
| 1559 | return $this->filterFieldDescriptions; |
||
| 1560 | } |
||
| 1561 | |||
| 1562 | public function addChild(AdminInterface $child, string $field): void |
||
| 1563 | { |
||
| 1564 | $parentAdmin = $this; |
||
| 1565 | while ($parentAdmin->isChild() && $parentAdmin->getCode() !== $child->getCode()) { |
||
| 1566 | $parentAdmin = $parentAdmin->getParent(); |
||
| 1567 | } |
||
| 1568 | |||
| 1569 | if ($parentAdmin->getCode() === $child->getCode()) { |
||
| 1570 | throw new \RuntimeException(sprintf( |
||
| 1571 | 'Circular reference detected! The child admin `%s` is already in the parent tree of the `%s` admin.', |
||
| 1572 | $child->getCode(), |
||
| 1573 | $this->getCode() |
||
| 1574 | )); |
||
| 1575 | } |
||
| 1576 | |||
| 1577 | $this->children[$child->getCode()] = $child; |
||
| 1578 | |||
| 1579 | $child->setParent($this); |
||
| 1580 | $child->addParentAssociationMapping($this->getCode(), $field); |
||
| 1581 | } |
||
| 1582 | |||
| 1583 | public function hasChild(string $code): bool |
||
| 1584 | { |
||
| 1585 | return isset($this->children[$code]); |
||
| 1586 | } |
||
| 1587 | |||
| 1588 | public function getChildren(): array |
||
| 1589 | { |
||
| 1590 | return $this->children; |
||
| 1591 | } |
||
| 1592 | |||
| 1593 | public function getChild(string $code): AdminInterface |
||
| 1594 | { |
||
| 1595 | if (!$this->hasChild($code)) { |
||
| 1596 | throw new \LogicException(sprintf( |
||
| 1597 | 'Admin "%s" has no child for the code %s.', |
||
| 1598 | static::class, |
||
| 1599 | $code |
||
| 1600 | )); |
||
| 1601 | } |
||
| 1602 | |||
| 1603 | return $this->children[$code]; |
||
| 1604 | } |
||
| 1605 | |||
| 1606 | public function setParent(AdminInterface $parent): void |
||
| 1607 | { |
||
| 1608 | $this->parent = $parent; |
||
| 1609 | } |
||
| 1610 | |||
| 1611 | public function getParent(): AdminInterface |
||
| 1612 | { |
||
| 1613 | if (!$this->isChild()) { |
||
| 1614 | throw new \LogicException(sprintf( |
||
| 1615 | 'Admin "%s" has no parent.', |
||
| 1616 | static::class |
||
| 1617 | )); |
||
| 1618 | } |
||
| 1619 | |||
| 1620 | return $this->parent; |
||
| 1621 | } |
||
| 1622 | |||
| 1623 | final public function getRootAncestor(): AdminInterface |
||
| 1633 | |||
| 1634 | final public function getChildDepth(): int |
||
| 1646 | |||
| 1647 | final public function getCurrentLeafChildAdmin(): ?AdminInterface |
||
| 1661 | |||
| 1662 | public function isChild(): bool |
||
| 1666 | |||
| 1667 | /** |
||
| 1668 | * Returns true if the admin has children, false otherwise. |
||
| 1669 | */ |
||
| 1670 | public function hasChildren(): bool |
||
| 1671 | { |
||
| 1672 | return \count($this->children) > 0; |
||
| 1673 | } |
||
| 1674 | |||
| 1675 | public function setUniqid(string $uniqid): void |
||
| 1676 | { |
||
| 1677 | $this->uniqid = $uniqid; |
||
| 1678 | } |
||
| 1679 | |||
| 1680 | public function getUniqid(): string |
||
| 1681 | { |
||
| 1682 | if (!$this->uniqid) { |
||
| 1683 | $this->uniqid = sprintf('s%s', uniqid()); |
||
| 1684 | } |
||
| 1685 | |||
| 1686 | return $this->uniqid; |
||
| 1687 | } |
||
| 1688 | |||
| 1689 | /** |
||
| 1690 | * {@inheritdoc} |
||
| 1691 | */ |
||
| 1692 | public function getClassnameLabel(): string |
||
| 1693 | { |
||
| 1694 | return $this->classnameLabel; |
||
| 1695 | } |
||
| 1696 | |||
| 1697 | public function getPersistentParameters(): array |
||
| 1698 | { |
||
| 1699 | $parameters = []; |
||
| 1700 | |||
| 1701 | foreach ($this->getExtensions() as $extension) { |
||
| 1702 | $params = $extension->getPersistentParameters($this); |
||
| 1703 | |||
| 1704 | $parameters = array_merge($parameters, $params); |
||
| 1705 | } |
||
| 1706 | |||
| 1707 | return $parameters; |
||
| 1708 | } |
||
| 1709 | |||
| 1710 | /** |
||
| 1711 | * {@inheritdoc} |
||
| 1712 | */ |
||
| 1713 | public function getPersistentParameter(string $name) |
||
| 1714 | { |
||
| 1715 | $parameters = $this->getPersistentParameters(); |
||
| 1716 | |||
| 1717 | return $parameters[$name] ?? null; |
||
| 1718 | } |
||
| 1719 | |||
| 1720 | public function setCurrentChild(bool $currentChild): void |
||
| 1721 | { |
||
| 1722 | $this->currentChild = $currentChild; |
||
| 1723 | } |
||
| 1724 | |||
| 1725 | public function isCurrentChild(): bool |
||
| 1726 | { |
||
| 1727 | return $this->currentChild; |
||
| 1728 | } |
||
| 1729 | |||
| 1730 | /** |
||
| 1731 | * Returns the current child admin instance. |
||
| 1732 | * |
||
| 1733 | * @return AdminInterface|null the current child admin instance |
||
| 1734 | */ |
||
| 1735 | public function getCurrentChildAdmin(): ?AdminInterface |
||
| 1736 | { |
||
| 1737 | foreach ($this->children as $children) { |
||
| 1738 | if ($children->isCurrentChild()) { |
||
| 1739 | return $children; |
||
| 1740 | } |
||
| 1741 | } |
||
| 1742 | |||
| 1743 | return null; |
||
| 1744 | } |
||
| 1745 | |||
| 1746 | public function setTranslationDomain(string $translationDomain): void |
||
| 1747 | { |
||
| 1748 | $this->translationDomain = $translationDomain; |
||
| 1749 | } |
||
| 1750 | |||
| 1751 | public function getTranslationDomain(): string |
||
| 1752 | { |
||
| 1753 | return $this->translationDomain; |
||
| 1754 | } |
||
| 1755 | |||
| 1756 | public function getTranslationLabel(string $label, string $context = '', string $type = ''): string |
||
| 1757 | { |
||
| 1758 | return $this->getLabelTranslatorStrategy()->getLabel($label, $context, $type); |
||
| 1759 | } |
||
| 1760 | |||
| 1761 | public function setRequest(Request $request): void |
||
| 1762 | { |
||
| 1763 | $this->request = $request; |
||
| 1764 | |||
| 1765 | foreach ($this->getChildren() as $children) { |
||
| 1766 | $children->setRequest($request); |
||
| 1767 | } |
||
| 1768 | } |
||
| 1769 | |||
| 1770 | public function getRequest(): Request |
||
| 1771 | { |
||
| 1772 | if (!$this->request) { |
||
| 1773 | throw new \LogicException('The Request object has not been set'); |
||
| 1774 | } |
||
| 1775 | |||
| 1776 | return $this->request; |
||
| 1777 | } |
||
| 1778 | |||
| 1779 | public function hasRequest(): bool |
||
| 1780 | { |
||
| 1781 | return null !== $this->request; |
||
| 1782 | } |
||
| 1783 | |||
| 1784 | public function setFormContractor(?FormContractorInterface $formBuilder): void |
||
| 1785 | { |
||
| 1786 | $this->formContractor = $formBuilder; |
||
| 1788 | |||
| 1789 | public function getFormContractor(): ?FormContractorInterface |
||
| 1793 | |||
| 1794 | public function setDatagridBuilder(?DatagridBuilderInterface $datagridBuilder): void |
||
| 1798 | |||
| 1799 | public function getDatagridBuilder(): ?DatagridBuilderInterface |
||
| 1803 | |||
| 1804 | public function setListBuilder(?ListBuilderInterface $listBuilder): void |
||
| 1808 | |||
| 1809 | public function getListBuilder(): ?ListBuilderInterface |
||
| 1813 | |||
| 1814 | public function setShowBuilder(?ShowBuilderInterface $showBuilder): void |
||
| 1818 | |||
| 1819 | public function getShowBuilder(): ?ShowBuilderInterface |
||
| 1823 | |||
| 1824 | public function setConfigurationPool(?Pool $configurationPool): void |
||
| 1828 | |||
| 1829 | public function getConfigurationPool(): ?Pool |
||
| 1833 | |||
| 1834 | public function setRouteGenerator(RouteGeneratorInterface $routeGenerator): void |
||
| 1838 | |||
| 1839 | public function getRouteGenerator(): ?RouteGeneratorInterface |
||
| 1843 | |||
| 1844 | public function getCode(): string |
||
| 1848 | |||
| 1849 | public function getBaseCodeRoute(): string |
||
| 1857 | |||
| 1858 | public function getModelManager(): ?ModelManagerInterface |
||
| 1862 | |||
| 1863 | public function setModelManager(?ModelManagerInterface $modelManager): void |
||
| 1867 | |||
| 1868 | public function getManagerType(): ?string |
||
| 1872 | |||
| 1873 | public function setManagerType(?string $type): void |
||
| 1877 | |||
| 1878 | public function getObjectIdentifier() |
||
| 1882 | |||
| 1883 | /** |
||
| 1884 | * Set the roles and permissions per role. |
||
| 1885 | */ |
||
| 1886 | public function setSecurityInformation(array $information): void |
||
| 1890 | |||
| 1891 | public function getSecurityInformation(): array |
||
| 1895 | |||
| 1896 | /** |
||
| 1897 | * Return the list of permissions the user should have in order to display the admin. |
||
| 1898 | */ |
||
| 1899 | public function getPermissionsShow(string $context): array |
||
| 1908 | |||
| 1909 | public function showIn(string $context): bool |
||
| 1918 | |||
| 1919 | public function createObjectSecurity(object $object): void |
||
| 1923 | |||
| 1924 | public function setSecurityHandler(?SecurityHandlerInterface $securityHandler): void |
||
| 1928 | |||
| 1929 | public function getSecurityHandler(): ?SecurityHandlerInterface |
||
| 1933 | |||
| 1934 | /** |
||
| 1935 | * NEXT_MAJOR: Decide the type declaration for the $name argument, since it is |
||
| 1936 | * passed as argument 1 for `SecurityHandlerInterface::isGranted()`, which |
||
| 1937 | * accepts string and array. |
||
| 1938 | */ |
||
| 1939 | public function isGranted($name, ?object $object = null): bool |
||
| 1950 | |||
| 1951 | /** |
||
| 1952 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is |
||
| 1953 | * passed as argument 1 for `ModelManagerInterface::getUrlSafeIdentifier()`, which |
||
| 1954 | * accepts null. |
||
| 1955 | */ |
||
| 1956 | public function getUrlSafeIdentifier($model): ?string |
||
| 1960 | |||
| 1961 | /** |
||
| 1962 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is |
||
| 1963 | * passed as argument 1 for `ModelManagerInterface::getNormalizedIdentifier()`, which |
||
| 1964 | * accepts null. |
||
| 1965 | */ |
||
| 1966 | public function getNormalizedIdentifier($model): ?string |
||
| 1970 | |||
| 1971 | /** |
||
| 1972 | * NEXT_MAJOR: Decide the type declaration for the $model argument, since it is |
||
| 1973 | * passed as argument 1 for `ModelManagerInterface::getNormalizedIdentifier()`, which |
||
| 1974 | * accepts null. |
||
| 1975 | */ |
||
| 1976 | public function id($model): ?string |
||
| 1980 | |||
| 1981 | public function setValidator(?ValidatorInterface $validator): void |
||
| 1985 | |||
| 1986 | public function getValidator(): ?ValidatorInterface |
||
| 1990 | |||
| 1991 | public function getShow(): ?FieldDescriptionCollection |
||
| 1997 | |||
| 1998 | public function setFormTheme(array $formTheme): void |
||
| 2002 | |||
| 2003 | public function getFormTheme(): array |
||
| 2007 | |||
| 2008 | public function setFilterTheme(array $filterTheme): void |
||
| 2012 | |||
| 2013 | public function getFilterTheme(): array |
||
| 2017 | |||
| 2018 | public function addExtension(AdminExtensionInterface $extension): void |
||
| 2022 | |||
| 2023 | public function getExtensions(): array |
||
| 2027 | |||
| 2028 | public function setMenuFactory(?FactoryInterface $menuFactory): void |
||
| 2032 | |||
| 2033 | public function getMenuFactory(): ?FactoryInterface |
||
| 2037 | |||
| 2038 | public function setRouteBuilder(?RouteBuilderInterface $routeBuilder): void |
||
| 2042 | |||
| 2043 | public function getRouteBuilder(): ?RouteBuilderInterface |
||
| 2047 | |||
| 2048 | /** |
||
| 2049 | * NEXT_MAJOR: Decide the type declaration for the $object argument, since there |
||
| 2050 | * are tests ensuring to accept null (`GetShortObjectDescriptionActionTest::testGetShortObjectDescriptionActionEmptyObjectIdAsJson()`). |
||
| 2051 | */ |
||
| 2052 | public function toString($object): string |
||
| 2064 | |||
| 2065 | public function setLabelTranslatorStrategy(?LabelTranslatorStrategyInterface $labelTranslatorStrategy): void |
||
| 2069 | |||
| 2070 | public function getLabelTranslatorStrategy(): ?LabelTranslatorStrategyInterface |
||
| 2074 | |||
| 2075 | public function supportsPreviewMode(): bool |
||
| 2079 | |||
| 2080 | /** |
||
| 2081 | * Returns predefined per page options. |
||
| 2082 | */ |
||
| 2083 | public function getPerPageOptions(): array |
||
| 2093 | |||
| 2094 | /** |
||
| 2095 | * Set pager type. |
||
| 2096 | */ |
||
| 2097 | public function setPagerType(string $pagerType): void |
||
| 2101 | |||
| 2102 | /** |
||
| 2103 | * Get pager type. |
||
| 2104 | */ |
||
| 2105 | public function getPagerType(): string |
||
| 2109 | |||
| 2110 | /** |
||
| 2111 | * Returns true if the per page value is allowed, false otherwise. |
||
| 2112 | */ |
||
| 2113 | public function determinedPerPageValue(int $perPage): bool |
||
| 2117 | |||
| 2118 | public function isAclEnabled(): bool |
||
| 2122 | |||
| 2123 | /** |
||
| 2124 | * NEXT_MAJOR: Decide the type declaration for the $object argument, since it is |
||
| 2125 | * passed as argument 1 to `toString()` method, which currently accepts null. |
||
| 2126 | */ |
||
| 2127 | public function getObjectMetadata($object): MetadataInterface |
||
| 2131 | |||
| 2132 | public function getListModes(): array |
||
| 2136 | |||
| 2137 | public function setListMode(string $mode): void |
||
| 2145 | |||
| 2146 | public function getListMode(): string |
||
| 2154 | |||
| 2155 | public function getAccessMapping(): array |
||
| 2159 | |||
| 2160 | public function checkAccess(string $action, ?object $object = null): void |
||
| 2182 | |||
| 2183 | /** |
||
| 2184 | * {@inheritdoc} |
||
| 2185 | */ |
||
| 2186 | public function hasAccess(string $action, ?object $object = null): bool |
||
| 2206 | |||
| 2207 | final public function getActionButtons(string $action, ?object $object = null): array |
||
| 2275 | |||
| 2276 | /** |
||
| 2277 | * {@inheritdoc} |
||
| 2278 | */ |
||
| 2279 | public function getDashboardActions(): array |
||
| 2304 | |||
| 2305 | /** |
||
| 2306 | * {@inheritdoc} |
||
| 2307 | */ |
||
| 2308 | final public function showMosaicButton($isShown): void |
||
| 2316 | |||
| 2317 | final public function getSearchResultLink(object $object): ?string |
||
| 2327 | |||
| 2328 | /** |
||
| 2329 | * Checks if a filter type is set to a default value. |
||
| 2330 | */ |
||
| 2331 | final public function isDefaultFilter(string $name): bool |
||
| 2342 | |||
| 2343 | public function canAccessObject(string $action, ?object $object = null): bool |
||
| 2347 | |||
| 2348 | public function configureActionButtons(array $buttonList, string $action, ?object $object = null): array |
||
| 2352 | |||
| 2353 | /** |
||
| 2354 | * Hook to run after initialization. |
||
| 2355 | */ |
||
| 2356 | protected function configure(): void |
||
| 2359 | |||
| 2360 | protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface |
||
| 2364 | |||
| 2365 | /** |
||
| 2366 | * urlize the given word. |
||
| 2367 | * |
||
| 2368 | * @param string $sep the separator |
||
| 2369 | */ |
||
| 2370 | final protected function urlize(string $word, string $sep = '_'): string |
||
| 2374 | |||
| 2375 | final protected function getTemplateRegistry(): MutableTemplateRegistryInterface |
||
| 2379 | |||
| 2380 | /** |
||
| 2381 | * Returns a list of default sort values. |
||
| 2382 | * |
||
| 2383 | * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string} |
||
| 2384 | */ |
||
| 2385 | final protected function getDefaultSortValues(): array |
||
| 2397 | |||
| 2398 | /** |
||
| 2399 | * Returns a list of default filters. |
||
| 2400 | */ |
||
| 2401 | final protected function getDefaultFilterValues(): array |
||
| 2413 | |||
| 2414 | protected function configureFormFields(FormMapper $form): void |
||
| 2417 | |||
| 2418 | protected function configureListFields(ListMapper $list): void |
||
| 2421 | |||
| 2422 | protected function configureDatagridFilters(DatagridMapper $filter): void |
||
| 2425 | |||
| 2426 | protected function configureShowFields(ShowMapper $show): void |
||
| 2429 | |||
| 2430 | protected function configureRoutes(RouteCollection $collection): void |
||
| 2433 | |||
| 2434 | /** |
||
| 2435 | * Allows you to customize batch actions. |
||
| 2436 | * |
||
| 2437 | * @param array $actions List of actions |
||
| 2438 | */ |
||
| 2439 | protected function configureBatchActions(array $actions): array |
||
| 2443 | |||
| 2444 | /** |
||
| 2445 | * Configures the tab menu in your admin. |
||
| 2446 | */ |
||
| 2447 | protected function configureTabMenu(ItemInterface $menu, string $action, ?AdminInterface $childAdmin = null): void |
||
| 2450 | |||
| 2451 | /** |
||
| 2452 | * build the view FieldDescription array. |
||
| 2453 | */ |
||
| 2454 | protected function buildShow(): void |
||
| 2471 | |||
| 2472 | /** |
||
| 2473 | * build the list FieldDescription array. |
||
| 2474 | */ |
||
| 2475 | protected function buildList(): void |
||
| 2528 | |||
| 2529 | /** |
||
| 2530 | * Build the form FieldDescription collection. |
||
| 2531 | */ |
||
| 2532 | protected function buildForm(): void |
||
| 2547 | |||
| 2548 | /** |
||
| 2549 | * Gets the subclass corresponding to the given name. |
||
| 2550 | * |
||
| 2551 | * @param string $name The name of the sub class |
||
| 2552 | * |
||
| 2553 | * @return string the subclass |
||
| 2554 | */ |
||
| 2555 | protected function getSubClass(string $name): string |
||
| 2563 | |||
| 2564 | /** |
||
| 2565 | * Attach the inline validator to the model metadata, this must be done once per admin. |
||
| 2566 | */ |
||
| 2567 | protected function attachInlineValidator(): void |
||
| 2604 | |||
| 2605 | /** |
||
| 2606 | * Return list routes with permissions name. |
||
| 2607 | * |
||
| 2608 | * @return array<string, string> |
||
| 2609 | */ |
||
| 2610 | protected function getAccess(): array |
||
| 2632 | |||
| 2633 | /** |
||
| 2634 | * Configures a list of default filters. |
||
| 2635 | */ |
||
| 2636 | protected function configureDefaultFilterValues(array &$filterValues): void |
||
| 2639 | |||
| 2640 | /** |
||
| 2641 | * Configures a list of default sort values. |
||
| 2642 | * |
||
| 2643 | * Example: |
||
| 2644 | * $sortValues['_sort_by'] = 'foo' |
||
| 2645 | * $sortValues['_sort_order'] = 'DESC' |
||
| 2646 | */ |
||
| 2647 | protected function configureDefaultSortValues(array &$sortValues) |
||
| 2650 | |||
| 2651 | /** |
||
| 2652 | * Set the parent object, if any, to the provided object. |
||
| 2653 | */ |
||
| 2654 | final protected function appendParentObject(object $object): void |
||
| 2682 | |||
| 2683 | /** |
||
| 2684 | * {@inheritdoc} |
||
| 2685 | */ |
||
| 2686 | private function buildDatagrid(): void |
||
| 2740 | |||
| 2741 | /** |
||
| 2742 | * Build all the related urls to the current admin. |
||
| 2743 | */ |
||
| 2744 | private function buildRoutes(): void |
||
| 2767 | } |
||
| 2768 | |||
| 2770 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.