vendor/sonata-project/admin-bundle/src/Admin/AbstractAdmin.php line 605

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\AdminBundle\Admin;
  12. use Doctrine\Common\Util\ClassUtils;
  13. use Knp\Menu\FactoryInterface;
  14. use Knp\Menu\ItemInterface;
  15. use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
  16. use Sonata\AdminBundle\Builder\FormContractorInterface;
  17. use Sonata\AdminBundle\Builder\ListBuilderInterface;
  18. use Sonata\AdminBundle\Builder\RouteBuilderInterface;
  19. use Sonata\AdminBundle\Builder\ShowBuilderInterface;
  20. use Sonata\AdminBundle\Datagrid\DatagridInterface;
  21. use Sonata\AdminBundle\Datagrid\DatagridMapper;
  22. use Sonata\AdminBundle\Datagrid\ListMapper;
  23. use Sonata\AdminBundle\Datagrid\Pager;
  24. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  25. use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface;
  26. use Sonata\AdminBundle\Form\FormMapper;
  27. use Sonata\AdminBundle\Form\Type\ModelHiddenType;
  28. use Sonata\AdminBundle\Model\ModelManagerInterface;
  29. use Sonata\AdminBundle\Object\Metadata;
  30. use Sonata\AdminBundle\Route\RouteCollection;
  31. use Sonata\AdminBundle\Route\RouteGeneratorInterface;
  32. use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface;
  33. use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
  34. use Sonata\AdminBundle\Show\ShowMapper;
  35. use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
  36. use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
  37. use Sonata\Form\Validator\Constraints\InlineConstraint;
  38. use Sonata\Form\Validator\ErrorElement;
  39. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  40. use Symfony\Component\Form\Form;
  41. use Symfony\Component\Form\FormBuilderInterface;
  42. use Symfony\Component\Form\FormEvent;
  43. use Symfony\Component\Form\FormEvents;
  44. use Symfony\Component\HttpFoundation\Request;
  45. use Symfony\Component\PropertyAccess\PropertyPath;
  46. use Symfony\Component\Routing\Generator\UrlGeneratorInterface as RoutingUrlGeneratorInterface;
  47. use Symfony\Component\Security\Acl\Model\DomainObjectInterface;
  48. use Symfony\Component\Security\Core\Exception\AccessDeniedException;
  49. use Symfony\Component\Translation\TranslatorInterface;
  50. use Symfony\Component\Validator\Validator\ValidatorInterface;
  51. /**
  52.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  53.  */
  54. abstract class AbstractAdmin implements AdminInterfaceDomainObjectInterfaceAdminTreeInterface
  55. {
  56.     public const CONTEXT_MENU 'menu';
  57.     public const CONTEXT_DASHBOARD 'dashboard';
  58.     public const CLASS_REGEX =
  59.         '@
  60.         (?:([A-Za-z0-9]*)\\\)?        # vendor name / app name
  61.         (Bundle\\\)?                  # optional bundle directory
  62.         ([A-Za-z0-9]+?)(?:Bundle)?\\\ # bundle name, with optional suffix
  63.         (
  64.             Entity|Document|Model|PHPCR|CouchDocument|Phpcr|
  65.             Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB
  66.         )\\\(.*)@x';
  67.     public const MOSAIC_ICON_CLASS 'fa fa-th-large fa-fw';
  68.     /**
  69.      * The list FieldDescription constructed from the configureListField method.
  70.      *
  71.      * @var array
  72.      */
  73.     protected $listFieldDescriptions = [];
  74.     /**
  75.      * The show FieldDescription constructed from the configureShowFields method.
  76.      *
  77.      * @var array
  78.      */
  79.     protected $showFieldDescriptions = [];
  80.     /**
  81.      * The list FieldDescription constructed from the configureFormField method.
  82.      *
  83.      * @var array
  84.      */
  85.     protected $formFieldDescriptions = [];
  86.     /**
  87.      * The filter FieldDescription constructed from the configureFilterField method.
  88.      *
  89.      * @var array
  90.      */
  91.     protected $filterFieldDescriptions = [];
  92.     /**
  93.      * NEXT_MAJOR: Remove this property.
  94.      *
  95.      * The number of result to display in the list.
  96.      *
  97.      * @deprecated since sonata-project/admin-bundle 3.67.
  98.      *
  99.      * @var int
  100.      */
  101.     protected $maxPerPage 32;
  102.     /**
  103.      * The maximum number of page numbers to display in the list.
  104.      *
  105.      * @var int
  106.      */
  107.     protected $maxPageLinks 25;
  108.     /**
  109.      * The base route name used to generate the routing information.
  110.      *
  111.      * @var string
  112.      */
  113.     protected $baseRouteName;
  114.     /**
  115.      * The base route pattern used to generate the routing information.
  116.      *
  117.      * @var string
  118.      */
  119.     protected $baseRoutePattern;
  120.     /**
  121.      * The base name controller used to generate the routing information.
  122.      *
  123.      * @var string
  124.      */
  125.     protected $baseControllerName;
  126.     /**
  127.      * The label class name  (used in the title/breadcrumb ...).
  128.      *
  129.      * @var string
  130.      */
  131.     protected $classnameLabel;
  132.     /**
  133.      * The translation domain to be used to translate messages.
  134.      *
  135.      * @var string
  136.      */
  137.     protected $translationDomain 'messages';
  138.     /**
  139.      * Options to set to the form (ie, validation_groups).
  140.      *
  141.      * @var array
  142.      */
  143.     protected $formOptions = [];
  144.     /**
  145.      * NEXT_MAJOR: Remove this property.
  146.      *
  147.      * Default values to the datagrid.
  148.      *
  149.      * @deprecated since sonata-project/admin-bundle 3.67, use configureDefaultSortValues() instead.
  150.      *
  151.      * @var array
  152.      */
  153.     protected $datagridValues = [
  154.         '_page' => 1,
  155.         '_per_page' => 32,
  156.     ];
  157.     /**
  158.      * NEXT_MAJOR: Remove this property.
  159.      *
  160.      * Predefined per page options.
  161.      *
  162.      * @deprecated since sonata-project/admin-bundle 3.67.
  163.      *
  164.      * @var array
  165.      */
  166.     protected $perPageOptions = [163264128256];
  167.     /**
  168.      * Pager type.
  169.      *
  170.      * @var string
  171.      */
  172.     protected $pagerType Pager::TYPE_DEFAULT;
  173.     /**
  174.      * The code related to the admin.
  175.      *
  176.      * @var string
  177.      */
  178.     protected $code;
  179.     /**
  180.      * The label.
  181.      *
  182.      * @var string
  183.      */
  184.     protected $label;
  185.     /**
  186.      * Whether or not to persist the filters in the session.
  187.      *
  188.      * NEXT_MAJOR: remove this property
  189.      *
  190.      * @var bool
  191.      *
  192.      * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0.
  193.      */
  194.     protected $persistFilters false;
  195.     /**
  196.      * Array of routes related to this admin.
  197.      *
  198.      * @var RouteCollection
  199.      */
  200.     protected $routes;
  201.     /**
  202.      * The subject only set in edit/update/create mode.
  203.      *
  204.      * @var object|null
  205.      */
  206.     protected $subject;
  207.     /**
  208.      * Define a Collection of child admin, ie /admin/order/{id}/order-element/{childId}.
  209.      *
  210.      * @var array
  211.      */
  212.     protected $children = [];
  213.     /**
  214.      * Reference the parent admin.
  215.      *
  216.      * @var AdminInterface|null
  217.      */
  218.     protected $parent;
  219.     /**
  220.      * The base code route refer to the prefix used to generate the route name.
  221.      *
  222.      * NEXT_MAJOR: remove this attribute.
  223.      *
  224.      * @deprecated This attribute is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0
  225.      *
  226.      * @var string
  227.      */
  228.     protected $baseCodeRoute '';
  229.     /**
  230.      * NEXT_MAJOR: should be default array and private.
  231.      *
  232.      * @var string|array
  233.      */
  234.     protected $parentAssociationMapping;
  235.     /**
  236.      * Reference the parent FieldDescription related to this admin
  237.      * only set for FieldDescription which is associated to an Sub Admin instance.
  238.      *
  239.      * @var FieldDescriptionInterface
  240.      */
  241.     protected $parentFieldDescription;
  242.     /**
  243.      * If true then the current admin is part of the nested admin set (from the url).
  244.      *
  245.      * @var bool
  246.      */
  247.     protected $currentChild false;
  248.     /**
  249.      * The uniqid is used to avoid clashing with 2 admin related to the code
  250.      * ie: a Block linked to a Block.
  251.      *
  252.      * @var string
  253.      */
  254.     protected $uniqid;
  255.     /**
  256.      * The Entity or Document manager.
  257.      *
  258.      * @var ModelManagerInterface
  259.      */
  260.     protected $modelManager;
  261.     /**
  262.      * The current request object.
  263.      *
  264.      * @var Request|null
  265.      */
  266.     protected $request;
  267.     /**
  268.      * The translator component.
  269.      *
  270.      * NEXT_MAJOR: remove this property
  271.      *
  272.      * @var \Symfony\Component\Translation\TranslatorInterface
  273.      *
  274.      * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0
  275.      */
  276.     protected $translator;
  277.     /**
  278.      * The related form contractor.
  279.      *
  280.      * @var FormContractorInterface
  281.      */
  282.     protected $formContractor;
  283.     /**
  284.      * The related list builder.
  285.      *
  286.      * @var ListBuilderInterface
  287.      */
  288.     protected $listBuilder;
  289.     /**
  290.      * The related view builder.
  291.      *
  292.      * @var ShowBuilderInterface
  293.      */
  294.     protected $showBuilder;
  295.     /**
  296.      * The related datagrid builder.
  297.      *
  298.      * @var DatagridBuilderInterface
  299.      */
  300.     protected $datagridBuilder;
  301.     /**
  302.      * @var RouteBuilderInterface
  303.      */
  304.     protected $routeBuilder;
  305.     /**
  306.      * The datagrid instance.
  307.      *
  308.      * @var DatagridInterface|null
  309.      */
  310.     protected $datagrid;
  311.     /**
  312.      * The router instance.
  313.      *
  314.      * @var RouteGeneratorInterface|null
  315.      */
  316.     protected $routeGenerator;
  317.     /**
  318.      * The generated breadcrumbs.
  319.      *
  320.      * NEXT_MAJOR : remove this property
  321.      *
  322.      * @var array
  323.      */
  324.     protected $breadcrumbs = [];
  325.     /**
  326.      * @var SecurityHandlerInterface
  327.      */
  328.     protected $securityHandler;
  329.     /**
  330.      * @var ValidatorInterface
  331.      */
  332.     protected $validator;
  333.     /**
  334.      * The configuration pool.
  335.      *
  336.      * @var Pool
  337.      */
  338.     protected $configurationPool;
  339.     /**
  340.      * @var ItemInterface
  341.      */
  342.     protected $menu;
  343.     /**
  344.      * @var FactoryInterface
  345.      */
  346.     protected $menuFactory;
  347.     /**
  348.      * @var array<string, bool>
  349.      */
  350.     protected $loaded = [
  351.         'view_fields' => false,
  352.         'view_groups' => false,
  353.         'routes' => false,
  354.         'tab_menu' => false,
  355.     ];
  356.     /**
  357.      * @var string[]
  358.      */
  359.     protected $formTheme = [];
  360.     /**
  361.      * @var string[]
  362.      */
  363.     protected $filterTheme = [];
  364.     /**
  365.      * @var array<string, string>
  366.      *
  367.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead
  368.      */
  369.     protected $templates = [];
  370.     /**
  371.      * @var AdminExtensionInterface[]
  372.      */
  373.     protected $extensions = [];
  374.     /**
  375.      * @var LabelTranslatorStrategyInterface
  376.      */
  377.     protected $labelTranslatorStrategy;
  378.     /**
  379.      * Setting to true will enable preview mode for
  380.      * the entity and show a preview button in the
  381.      * edit/create forms.
  382.      *
  383.      * @var bool
  384.      */
  385.     protected $supportsPreviewMode false;
  386.     /**
  387.      * Roles and permissions per role.
  388.      *
  389.      * @var array 'role' => ['permission', 'permission']
  390.      */
  391.     protected $securityInformation = [];
  392.     protected $cacheIsGranted = [];
  393.     /**
  394.      * Action list for the search result.
  395.      *
  396.      * @var string[]
  397.      */
  398.     protected $searchResultActions = ['edit''show'];
  399.     protected $listModes = [
  400.         'list' => [
  401.             'class' => 'fa fa-list fa-fw',
  402.         ],
  403.         'mosaic' => [
  404.             'class' => self::MOSAIC_ICON_CLASS,
  405.         ],
  406.     ];
  407.     /**
  408.      * The Access mapping.
  409.      *
  410.      * @var array [action1 => requiredRole1, action2 => [requiredRole2, requiredRole3]]
  411.      */
  412.     protected $accessMapping = [];
  413.     /**
  414.      * @var MutableTemplateRegistryInterface
  415.      */
  416.     private $templateRegistry;
  417.     /**
  418.      * The class name managed by the admin class.
  419.      *
  420.      * @var string
  421.      */
  422.     private $class;
  423.     /**
  424.      * The subclasses supported by the admin class.
  425.      *
  426.      * @var array<string, string>
  427.      */
  428.     private $subClasses = [];
  429.     /**
  430.      * The list collection.
  431.      *
  432.      * @var FieldDescriptionCollection
  433.      */
  434.     private $list;
  435.     /**
  436.      * @var FieldDescriptionCollection|null
  437.      */
  438.     private $show;
  439.     /**
  440.      * @var Form|null
  441.      */
  442.     private $form;
  443.     /**
  444.      * The cached base route name.
  445.      *
  446.      * @var string
  447.      */
  448.     private $cachedBaseRouteName;
  449.     /**
  450.      * The cached base route pattern.
  451.      *
  452.      * @var string
  453.      */
  454.     private $cachedBaseRoutePattern;
  455.     /**
  456.      * The form group disposition.
  457.      *
  458.      * NEXT_MAJOR: must have `[]` as default value and remove the possibility to
  459.      * hold boolean values.
  460.      *
  461.      * @var array|bool
  462.      */
  463.     private $formGroups false;
  464.     /**
  465.      * The form tabs disposition.
  466.      *
  467.      * NEXT_MAJOR: must have `[]` as default value and remove the possibility to
  468.      * hold boolean values.
  469.      *
  470.      * @var array|bool
  471.      */
  472.     private $formTabs false;
  473.     /**
  474.      * The view group disposition.
  475.      *
  476.      * NEXT_MAJOR: must have `[]` as default value and remove the possibility to
  477.      * hold boolean values.
  478.      *
  479.      * @var array|bool
  480.      */
  481.     private $showGroups false;
  482.     /**
  483.      * The view tab disposition.
  484.      *
  485.      * NEXT_MAJOR: must have `[]` as default value and remove the possibility to
  486.      * hold boolean values.
  487.      *
  488.      * @var array|bool
  489.      */
  490.     private $showTabs false;
  491.     /**
  492.      * The manager type to use for the admin.
  493.      *
  494.      * @var string
  495.      */
  496.     private $managerType;
  497.     /**
  498.      * The breadcrumbsBuilder component.
  499.      *
  500.      * @var BreadcrumbsBuilderInterface
  501.      */
  502.     private $breadcrumbsBuilder;
  503.     /**
  504.      * Component responsible for persisting filters.
  505.      *
  506.      * @var FilterPersisterInterface|null
  507.      */
  508.     private $filterPersister;
  509.     /**
  510.      * @param string      $code
  511.      * @param string      $class
  512.      * @param string|null $baseControllerName
  513.      */
  514.     public function __construct($code$class$baseControllerName null)
  515.     {
  516.         if (!\is_string($code)) {
  517.             @trigger_error(sprintf(
  518.                 'Passing other type than string as argument 1 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string in version 4.0.',
  519.                 __METHOD__
  520.             ), E_USER_DEPRECATED);
  521.         }
  522.         $this->code $code;
  523.         if (!\is_string($class)) {
  524.             @trigger_error(sprintf(
  525.                 'Passing other type than string as argument 2 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string in version 4.0.',
  526.                 __METHOD__
  527.             ), E_USER_DEPRECATED);
  528.         }
  529.         $this->class $class;
  530.         if (null !== $baseControllerName && !\is_string($baseControllerName)) {
  531.             @trigger_error(sprintf(
  532.                 'Passing other type than string or null as argument 3 for method %s() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string and null in version 4.0.',
  533.                 __METHOD__
  534.             ), E_USER_DEPRECATED);
  535.         }
  536.         $this->baseControllerName $baseControllerName;
  537.         // NEXT_MAJOR: Remove this line.
  538.         $this->predefinePerPageOptions();
  539.         // NEXT_MAJOR: Remove this line.
  540.         $this->datagridValues['_per_page'] = $this->maxPerPage;
  541.     }
  542.     /**
  543.      * {@inheritdoc}
  544.      */
  545.     public function getExportFormats()
  546.     {
  547.         return [
  548.             'json''xml''csv''xls',
  549.         ];
  550.     }
  551.     /**
  552.      * @return array
  553.      */
  554.     public function getExportFields()
  555.     {
  556.         $fields $this->getModelManager()->getExportFields($this->getClass());
  557.         foreach ($this->getExtensions() as $extension) {
  558.             if (method_exists($extension'configureExportFields')) {
  559.                 $fields $extension->configureExportFields($this$fields);
  560.             }
  561.         }
  562.         return $fields;
  563.     }
  564.     public function getDataSourceIterator()
  565.     {
  566.         $datagrid $this->getDatagrid();
  567.         $datagrid->buildPager();
  568.         $fields = [];
  569.         foreach ($this->getExportFields() as $key => $field) {
  570.             $label $this->getTranslationLabel($field'export''label');
  571.             $transLabel $this->trans($label);
  572.             // NEXT_MAJOR: Remove this hack, because all field labels will be translated with the major release
  573.             // No translation key exists
  574.             if ($transLabel === $label) {
  575.                 $fields[$key] = $field;
  576.             } else {
  577.                 $fields[$transLabel] = $field;
  578.             }
  579.         }
  580.         return $this->getModelManager()->getDataSourceIterator($datagrid$fields);
  581.     }
  582.     public function validate(ErrorElement $errorElement$object)
  583.     {
  584.     }
  585.     /**
  586.      * define custom variable.
  587.      */
  588.     public function initialize()
  589.     {
  590.         if (!$this->classnameLabel) {
  591.             /* NEXT_MAJOR: remove cast to string, null is not supposed to be
  592.             supported but was documented as such */
  593.             $this->classnameLabel substr(
  594.                 (string) $this->getClass(),
  595.                 strrpos((string) $this->getClass(), '\\') + 1
  596.             );
  597.         }
  598.         // NEXT_MAJOR: Remove this line.
  599.         $this->baseCodeRoute $this->getCode();
  600.         $this->configure();
  601.     }
  602.     public function configure()
  603.     {
  604.     }
  605.     public function update($object)
  606.     {
  607.         $this->preUpdate($object);
  608.         foreach ($this->extensions as $extension) {
  609.             $extension->preUpdate($this$object);
  610.         }
  611.         $result $this->getModelManager()->update($object);
  612.         // BC compatibility
  613.         if (null !== $result) {
  614.             $object $result;
  615.         }
  616.         $this->postUpdate($object);
  617.         foreach ($this->extensions as $extension) {
  618.             $extension->postUpdate($this$object);
  619.         }
  620.         return $object;
  621.     }
  622.     public function create($object)
  623.     {
  624.         $this->prePersist($object);
  625.         foreach ($this->extensions as $extension) {
  626.             $extension->prePersist($this$object);
  627.         }
  628.         $result $this->getModelManager()->create($object);
  629.         // BC compatibility
  630.         if (null !== $result) {
  631.             $object $result;
  632.         }
  633.         $this->postPersist($object);
  634.         foreach ($this->extensions as $extension) {
  635.             $extension->postPersist($this$object);
  636.         }
  637.         $this->createObjectSecurity($object);
  638.         return $object;
  639.     }
  640.     public function delete($object)
  641.     {
  642.         $this->preRemove($object);
  643.         foreach ($this->extensions as $extension) {
  644.             $extension->preRemove($this$object);
  645.         }
  646.         $this->getSecurityHandler()->deleteObjectSecurity($this$object);
  647.         $this->getModelManager()->delete($object);
  648.         $this->postRemove($object);
  649.         foreach ($this->extensions as $extension) {
  650.             $extension->postRemove($this$object);
  651.         }
  652.     }
  653.     /**
  654.      * @param object $object
  655.      */
  656.     public function preValidate($object)
  657.     {
  658.     }
  659.     public function preUpdate($object)
  660.     {
  661.     }
  662.     public function postUpdate($object)
  663.     {
  664.     }
  665.     public function prePersist($object)
  666.     {
  667.     }
  668.     public function postPersist($object)
  669.     {
  670.     }
  671.     public function preRemove($object)
  672.     {
  673.     }
  674.     public function postRemove($object)
  675.     {
  676.     }
  677.     public function preBatchAction($actionNameProxyQueryInterface $query, array &$idx$allElements)
  678.     {
  679.     }
  680.     public function getFilterParameters()
  681.     {
  682.         $parameters = [];
  683.         // build the values array
  684.         if ($this->hasRequest()) {
  685.             $filters $this->request->query->get('filter', []);
  686.             if (isset($filters['_page'])) {
  687.                 $filters['_page'] = (int) $filters['_page'];
  688.             }
  689.             if (isset($filters['_per_page'])) {
  690.                 $filters['_per_page'] = (int) $filters['_per_page'];
  691.             }
  692.             // if filter persistence is configured
  693.             // NEXT_MAJOR: remove `$this->persistFilters !== false` from the condition
  694.             if (false !== $this->persistFilters && null !== $this->filterPersister) {
  695.                 // if reset filters is asked, remove from storage
  696.                 if ('reset' === $this->request->query->get('filters')) {
  697.                     $this->filterPersister->reset($this->getCode());
  698.                 }
  699.                 // if no filters, fetch from storage
  700.                 // otherwise save to storage
  701.                 if (empty($filters)) {
  702.                     $filters $this->filterPersister->get($this->getCode());
  703.                 } else {
  704.                     $this->filterPersister->set($this->getCode(), $filters);
  705.                 }
  706.             }
  707.             $parameters array_merge(
  708.                 $this->getModelManager()->getDefaultSortValues($this->getClass()),
  709.                 $this->datagridValues// NEXT_MAJOR: Remove this line.
  710.                 $this->getDefaultSortValues(),
  711.                 $this->getDefaultFilterValues(),
  712.                 $filters
  713.             );
  714.             if (!$this->determinedPerPageValue($parameters['_per_page'])) {
  715.                 $parameters['_per_page'] = $this->getMaxPerPage();
  716.             }
  717.             // always force the parent value
  718.             if ($this->isChild() && $this->getParentAssociationMapping()) {
  719.                 $name str_replace('.''__'$this->getParentAssociationMapping());
  720.                 $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())];
  721.             }
  722.         }
  723.         return $parameters;
  724.     }
  725.     public function buildDatagrid()
  726.     {
  727.         if ($this->datagrid) {
  728.             return;
  729.         }
  730.         $filterParameters $this->getFilterParameters();
  731.         // transform _sort_by from a string to a FieldDescriptionInterface for the datagrid.
  732.         if (isset($filterParameters['_sort_by']) && \is_string($filterParameters['_sort_by'])) {
  733.             if ($this->hasListFieldDescription($filterParameters['_sort_by'])) {
  734.                 $filterParameters['_sort_by'] = $this->getListFieldDescription($filterParameters['_sort_by']);
  735.             } else {
  736.                 $filterParameters['_sort_by'] = $this->getModelManager()->getNewFieldDescriptionInstance(
  737.                     $this->getClass(),
  738.                     $filterParameters['_sort_by'],
  739.                     []
  740.                 );
  741.                 $this->getListBuilder()->buildField(null$filterParameters['_sort_by'], $this);
  742.             }
  743.         }
  744.         // initialize the datagrid
  745.         $this->datagrid $this->getDatagridBuilder()->getBaseDatagrid($this$filterParameters);
  746.         $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks);
  747.         $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid$this);
  748.         // build the datagrid filter
  749.         $this->configureDatagridFilters($mapper);
  750.         // ok, try to limit to add parent filter
  751.         if ($this->isChild() && $this->getParentAssociationMapping() && !$mapper->has($this->getParentAssociationMapping())) {
  752.             $mapper->add($this->getParentAssociationMapping(), null, [
  753.                 'show_filter' => false,
  754.                 'label' => false,
  755.                 'field_type' => ModelHiddenType::class,
  756.                 'field_options' => [
  757.                     'model_manager' => $this->getModelManager(),
  758.                 ],
  759.                 'operator_type' => HiddenType::class,
  760.             ], nullnull, [
  761.                 'admin_code' => $this->getParent()->getCode(),
  762.             ]);
  763.         }
  764.         foreach ($this->getExtensions() as $extension) {
  765.             $extension->configureDatagridFilters($mapper);
  766.         }
  767.     }
  768.     /**
  769.      * Returns the name of the parent related field, so the field can be use to set the default
  770.      * value (ie the parent object) or to filter the object.
  771.      *
  772.      * @throws \InvalidArgumentException
  773.      *
  774.      * @return string|null
  775.      */
  776.     public function getParentAssociationMapping()
  777.     {
  778.         // NEXT_MAJOR: remove array check
  779.         if (\is_array($this->parentAssociationMapping) && $this->isChild()) {
  780.             $parent $this->getParent()->getCode();
  781.             if (\array_key_exists($parent$this->parentAssociationMapping)) {
  782.                 return $this->parentAssociationMapping[$parent];
  783.             }
  784.             throw new \InvalidArgumentException(sprintf(
  785.                 "There's no association between %s and %s.",
  786.                 $this->getCode(),
  787.                 $this->getParent()->getCode()
  788.             ));
  789.         }
  790.         // NEXT_MAJOR: remove this line
  791.         return $this->parentAssociationMapping;
  792.     }
  793.     /**
  794.      * @param string $code
  795.      * @param string $value
  796.      */
  797.     final public function addParentAssociationMapping($code$value)
  798.     {
  799.         $this->parentAssociationMapping[$code] = $value;
  800.     }
  801.     /**
  802.      * Returns the baseRoutePattern used to generate the routing information.
  803.      *
  804.      * @throws \RuntimeException
  805.      *
  806.      * @return string the baseRoutePattern used to generate the routing information
  807.      */
  808.     public function getBaseRoutePattern()
  809.     {
  810.         if (null !== $this->cachedBaseRoutePattern) {
  811.             return $this->cachedBaseRoutePattern;
  812.         }
  813.         if ($this->isChild()) { // the admin class is a child, prefix it with the parent route pattern
  814.             $baseRoutePattern $this->baseRoutePattern;
  815.             if (!$this->baseRoutePattern) {
  816.                 preg_match(self::CLASS_REGEX$this->class$matches);
  817.                 if (!$matches) {
  818.                     throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class));
  819.                 }
  820.                 $baseRoutePattern $this->urlize($matches[5], '-');
  821.             }
  822.             $this->cachedBaseRoutePattern sprintf(
  823.                 '%s/%s/%s',
  824.                 $this->getParent()->getBaseRoutePattern(),
  825.                 $this->getParent()->getRouterIdParameter(),
  826.                 $baseRoutePattern
  827.             );
  828.         } elseif ($this->baseRoutePattern) {
  829.             $this->cachedBaseRoutePattern $this->baseRoutePattern;
  830.         } else {
  831.             preg_match(self::CLASS_REGEX$this->class$matches);
  832.             if (!$matches) {
  833.                 throw new \RuntimeException(sprintf('Please define a default `baseRoutePattern` value for the admin class `%s`', static::class));
  834.             }
  835.             $this->cachedBaseRoutePattern sprintf(
  836.                 '/%s%s/%s',
  837.                 empty($matches[1]) ? '' $this->urlize($matches[1], '-').'/',
  838.                 $this->urlize($matches[3], '-'),
  839.                 $this->urlize($matches[5], '-')
  840.             );
  841.         }
  842.         return $this->cachedBaseRoutePattern;
  843.     }
  844.     /**
  845.      * Returns the baseRouteName used to generate the routing information.
  846.      *
  847.      * @throws \RuntimeException
  848.      *
  849.      * @return string the baseRouteName used to generate the routing information
  850.      */
  851.     public function getBaseRouteName()
  852.     {
  853.         if (null !== $this->cachedBaseRouteName) {
  854.             return $this->cachedBaseRouteName;
  855.         }
  856.         if ($this->isChild()) { // the admin class is a child, prefix it with the parent route name
  857.             $baseRouteName $this->baseRouteName;
  858.             if (!$this->baseRouteName) {
  859.                 preg_match(self::CLASS_REGEX$this->class$matches);
  860.                 if (!$matches) {
  861.                     throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class));
  862.                 }
  863.                 $baseRouteName $this->urlize($matches[5]);
  864.             }
  865.             $this->cachedBaseRouteName sprintf(
  866.                 '%s_%s',
  867.                 $this->getParent()->getBaseRouteName(),
  868.                 $baseRouteName
  869.             );
  870.         } elseif ($this->baseRouteName) {
  871.             $this->cachedBaseRouteName $this->baseRouteName;
  872.         } else {
  873.             preg_match(self::CLASS_REGEX$this->class$matches);
  874.             if (!$matches) {
  875.                 throw new \RuntimeException(sprintf('Cannot automatically determine base route name, please define a default `baseRouteName` value for the admin class `%s`', static::class));
  876.             }
  877.             $this->cachedBaseRouteName sprintf(
  878.                 'admin_%s%s_%s',
  879.                 empty($matches[1]) ? '' $this->urlize($matches[1]).'_',
  880.                 $this->urlize($matches[3]),
  881.                 $this->urlize($matches[5])
  882.             );
  883.         }
  884.         return $this->cachedBaseRouteName;
  885.     }
  886.     /**
  887.      * urlize the given word.
  888.      *
  889.      * @param string $word
  890.      * @param string $sep  the separator
  891.      *
  892.      * @return string
  893.      */
  894.     public function urlize($word$sep '_')
  895.     {
  896.         return strtolower(preg_replace('/[^a-z0-9_]/i'$sep.'$1'$word));
  897.     }
  898.     public function getClass()
  899.     {
  900.         if ($this->hasActiveSubClass()) {
  901.             if ($this->hasParentFieldDescription()) {
  902.                 throw new \RuntimeException('Feature not implemented: an embedded admin cannot have subclass');
  903.             }
  904.             $subClass $this->getRequest()->query->get('subclass');
  905.             if (!$this->hasSubClass($subClass)) {
  906.                 throw new \RuntimeException(sprintf('Subclass "%s" is not defined.'$subClass));
  907.             }
  908.             return $this->getSubClass($subClass);
  909.         }
  910.         // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4
  911.         if ($this->subject && \is_object($this->subject)) {
  912.             return ClassUtils::getClass($this->subject);
  913.         }
  914.         return $this->class;
  915.     }
  916.     public function getSubClasses()
  917.     {
  918.         return $this->subClasses;
  919.     }
  920.     /**
  921.      * NEXT_MAJOR: remove this method.
  922.      */
  923.     public function addSubClass($subClass)
  924.     {
  925.         @trigger_error(sprintf(
  926.             'Method "%s" is deprecated since sonata-project/admin-bundle 3.30 and will be removed in 4.0.',
  927.             __METHOD__
  928.         ), E_USER_DEPRECATED);
  929.         if (!\in_array($subClass$this->subClassestrue)) {
  930.             $this->subClasses[] = $subClass;
  931.         }
  932.     }
  933.     public function setSubClasses(array $subClasses)
  934.     {
  935.         $this->subClasses $subClasses;
  936.     }
  937.     public function hasSubClass($name)
  938.     {
  939.         return isset($this->subClasses[$name]);
  940.     }
  941.     public function hasActiveSubClass()
  942.     {
  943.         if (\count($this->subClasses) > && $this->request) {
  944.             return null !== $this->getRequest()->query->get('subclass');
  945.         }
  946.         return false;
  947.     }
  948.     public function getActiveSubClass()
  949.     {
  950.         if (!$this->hasActiveSubClass()) {
  951.             @trigger_error(sprintf(
  952.                 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
  953.                 'Use %s::hasActiveSubClass() to know if there is an active subclass.',
  954.                 __METHOD__,
  955.                 __CLASS__
  956.             ), E_USER_DEPRECATED);
  957.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type
  958.             // throw new \LogicException(sprintf(
  959.             //    'Admin "%s" has no active subclass.',
  960.             //    static::class
  961.             // ));
  962.             return null;
  963.         }
  964.         return $this->getSubClass($this->getActiveSubclassCode());
  965.     }
  966.     public function getActiveSubclassCode()
  967.     {
  968.         if (!$this->hasActiveSubClass()) {
  969.             @trigger_error(sprintf(
  970.                 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
  971.                 'Use %s::hasActiveSubClass() to know if there is an active subclass.',
  972.                 __METHOD__,
  973.                 __CLASS__
  974.             ), E_USER_DEPRECATED);
  975.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type
  976.             // throw new \LogicException(sprintf(
  977.             //    'Admin "%s" has no active subclass.',
  978.             //    static::class
  979.             // ));
  980.             return null;
  981.         }
  982.         $subClass $this->getRequest()->query->get('subclass');
  983.         if (!$this->hasSubClass($subClass)) {
  984.             @trigger_error(sprintf(
  985.                 'Calling %s() when there is no active subclass is deprecated since sonata-project/admin-bundle 3.52 and will throw an exception in 4.0. '.
  986.                 'Use %s::hasActiveSubClass() to know if there is an active subclass.',
  987.                 __METHOD__,
  988.                 __CLASS__
  989.             ), E_USER_DEPRECATED);
  990.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare string as return type
  991.             // throw new \LogicException(sprintf(
  992.             //    'Admin "%s" has no active subclass.',
  993.             //    static::class
  994.             // ));
  995.             return null;
  996.         }
  997.         return $subClass;
  998.     }
  999.     public function getBatchActions()
  1000.     {
  1001.         $actions = [];
  1002.         if ($this->hasRoute('delete') && $this->hasAccess('delete')) {
  1003.             $actions['delete'] = [
  1004.                 'label' => 'action_delete',
  1005.                 'translation_domain' => 'SonataAdminBundle',
  1006.                 'ask_confirmation' => true// by default always true
  1007.             ];
  1008.         }
  1009.         $actions $this->configureBatchActions($actions);
  1010.         foreach ($this->getExtensions() as $extension) {
  1011.             // NEXT_MAJOR: remove method check
  1012.             if (method_exists($extension'configureBatchActions')) {
  1013.                 $actions $extension->configureBatchActions($this$actions);
  1014.             }
  1015.         }
  1016.         foreach ($actions  as $name => &$action) {
  1017.             if (!\array_key_exists('label'$action)) {
  1018.                 $action['label'] = $this->getTranslationLabel($name'batch''label');
  1019.             }
  1020.             if (!\array_key_exists('translation_domain'$action)) {
  1021.                 $action['translation_domain'] = $this->getTranslationDomain();
  1022.             }
  1023.         }
  1024.         return $actions;
  1025.     }
  1026.     public function getRoutes()
  1027.     {
  1028.         $this->buildRoutes();
  1029.         return $this->routes;
  1030.     }
  1031.     public function getRouterIdParameter()
  1032.     {
  1033.         return '{'.$this->getIdParameter().'}';
  1034.     }
  1035.     public function getIdParameter()
  1036.     {
  1037.         $parameter 'id';
  1038.         for ($i 0$i $this->getChildDepth(); ++$i) {
  1039.             $parameter 'child'.ucfirst($parameter);
  1040.         }
  1041.         return $parameter;
  1042.     }
  1043.     public function hasRoute($name)
  1044.     {
  1045.         if (!$this->routeGenerator) {
  1046.             throw new \RuntimeException('RouteGenerator cannot be null');
  1047.         }
  1048.         return $this->routeGenerator->hasAdminRoute($this$name);
  1049.     }
  1050.     /**
  1051.      * @param string      $name
  1052.      * @param string|null $adminCode
  1053.      *
  1054.      * @return bool
  1055.      */
  1056.     public function isCurrentRoute($name$adminCode null)
  1057.     {
  1058.         if (!$this->hasRequest()) {
  1059.             return false;
  1060.         }
  1061.         $request $this->getRequest();
  1062.         $route $request->get('_route');
  1063.         if ($adminCode) {
  1064.             $admin $this->getConfigurationPool()->getAdminByAdminCode($adminCode);
  1065.         } else {
  1066.             $admin $this;
  1067.         }
  1068.         if (!$admin) {
  1069.             return false;
  1070.         }
  1071.         return ($admin->getBaseRouteName().'_'.$name) === $route;
  1072.     }
  1073.     public function generateObjectUrl($name$object, array $parameters = [], $referenceType RoutingUrlGeneratorInterface::ABSOLUTE_PATH)
  1074.     {
  1075.         $parameters['id'] = $this->getUrlSafeIdentifier($object);
  1076.         return $this->generateUrl($name$parameters$referenceType);
  1077.     }
  1078.     public function generateUrl($name, array $parameters = [], $referenceType RoutingUrlGeneratorInterface::ABSOLUTE_PATH)
  1079.     {
  1080.         return $this->routeGenerator->generateUrl($this$name$parameters$referenceType);
  1081.     }
  1082.     public function generateMenuUrl($name, array $parameters = [], $referenceType RoutingUrlGeneratorInterface::ABSOLUTE_PATH)
  1083.     {
  1084.         return $this->routeGenerator->generateMenuUrl($this$name$parameters$referenceType);
  1085.     }
  1086.     final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry)
  1087.     {
  1088.         $this->templateRegistry $templateRegistry;
  1089.     }
  1090.     /**
  1091.      * @param array<string, string> $templates
  1092.      */
  1093.     public function setTemplates(array $templates)
  1094.     {
  1095.         // NEXT_MAJOR: Remove this line
  1096.         $this->templates $templates;
  1097.         $this->getTemplateRegistry()->setTemplates($templates);
  1098.     }
  1099.     /**
  1100.      * @param string $name
  1101.      * @param string $template
  1102.      */
  1103.     public function setTemplate($name$template)
  1104.     {
  1105.         // NEXT_MAJOR: Remove this line
  1106.         $this->templates[$name] = $template;
  1107.         $this->getTemplateRegistry()->setTemplate($name$template);
  1108.     }
  1109.     /**
  1110.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead
  1111.      *
  1112.      * @return array<string, string>
  1113.      */
  1114.     public function getTemplates()
  1115.     {
  1116.         return $this->getTemplateRegistry()->getTemplates();
  1117.     }
  1118.     /**
  1119.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry services instead
  1120.      *
  1121.      * @param string $name
  1122.      *
  1123.      * @return string|null
  1124.      */
  1125.     public function getTemplate($name)
  1126.     {
  1127.         return $this->getTemplateRegistry()->getTemplate($name);
  1128.     }
  1129.     public function getNewInstance()
  1130.     {
  1131.         $object $this->getModelManager()->getModelInstance($this->getClass());
  1132.         foreach ($this->getExtensions() as $extension) {
  1133.             $extension->alterNewInstance($this$object);
  1134.         }
  1135.         return $object;
  1136.     }
  1137.     public function getFormBuilder()
  1138.     {
  1139.         $this->formOptions['data_class'] = $this->getClass();
  1140.         $formBuilder $this->getFormContractor()->getFormBuilder(
  1141.             $this->getUniqid(),
  1142.             $this->formOptions
  1143.         );
  1144.         $this->defineFormBuilder($formBuilder);
  1145.         return $formBuilder;
  1146.     }
  1147.     /**
  1148.      * This method is being called by the main admin class and the child class,
  1149.      * the getFormBuilder is only call by the main admin class.
  1150.      */
  1151.     public function defineFormBuilder(FormBuilderInterface $formBuilder)
  1152.     {
  1153.         if (!$this->hasSubject()) {
  1154.             @trigger_error(sprintf(
  1155.                 'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.65 and will throw an exception in 4.0. '.
  1156.                 'Use %s::setSubject() to set the subject.',
  1157.                 __METHOD__,
  1158.                 __CLASS__
  1159.             ), E_USER_DEPRECATED);
  1160.             // NEXT_MAJOR : remove the previous `trigger_error()` call and uncomment the following exception
  1161.             // throw new \LogicException(sprintf(
  1162.             //    'Admin "%s" has no subject.',
  1163.             //    static::class
  1164.             // ));
  1165.         }
  1166.         $mapper = new FormMapper($this->getFormContractor(), $formBuilder$this);
  1167.         $this->configureFormFields($mapper);
  1168.         foreach ($this->getExtensions() as $extension) {
  1169.             $extension->configureFormFields($mapper);
  1170.         }
  1171.         $this->attachInlineValidator();
  1172.     }
  1173.     public function attachAdminClass(FieldDescriptionInterface $fieldDescription)
  1174.     {
  1175.         $pool $this->getConfigurationPool();
  1176.         $adminCode $fieldDescription->getOption('admin_code');
  1177.         if (null !== $adminCode) {
  1178.             $admin $pool->getAdminByAdminCode($adminCode);
  1179.         } else {
  1180.             $admin $pool->getAdminByClass($fieldDescription->getTargetEntity());
  1181.         }
  1182.         if (!$admin) {
  1183.             return;
  1184.         }
  1185.         if ($this->hasRequest()) {
  1186.             $admin->setRequest($this->getRequest());
  1187.         }
  1188.         $fieldDescription->setAssociationAdmin($admin);
  1189.     }
  1190.     public function getObject($id)
  1191.     {
  1192.         $object $this->getModelManager()->find($this->getClass(), $id);
  1193.         foreach ($this->getExtensions() as $extension) {
  1194.             $extension->alterObject($this$object);
  1195.         }
  1196.         return $object;
  1197.     }
  1198.     public function getForm()
  1199.     {
  1200.         $this->buildForm();
  1201.         return $this->form;
  1202.     }
  1203.     public function getList()
  1204.     {
  1205.         $this->buildList();
  1206.         return $this->list;
  1207.     }
  1208.     /**
  1209.      * @final since sonata-project/admin-bundle 3.63.0
  1210.      */
  1211.     public function createQuery($context 'list')
  1212.     {
  1213.         if (\func_num_args() > 0) {
  1214.             @trigger_error(
  1215.                 'The $context argument of '.__METHOD__.' is deprecated since 3.3, to be removed in 4.0.',
  1216.                 E_USER_DEPRECATED
  1217.             );
  1218.         }
  1219.         $query $this->getModelManager()->createQuery($this->getClass());
  1220.         $query $this->configureQuery($query);
  1221.         foreach ($this->extensions as $extension) {
  1222.             $extension->configureQuery($this$query$context);
  1223.         }
  1224.         return $query;
  1225.     }
  1226.     public function getDatagrid()
  1227.     {
  1228.         $this->buildDatagrid();
  1229.         return $this->datagrid;
  1230.     }
  1231.     public function buildTabMenu($action, ?AdminInterface $childAdmin null)
  1232.     {
  1233.         if ($this->loaded['tab_menu']) {
  1234.             return $this->menu;
  1235.         }
  1236.         $this->loaded['tab_menu'] = true;
  1237.         $menu $this->menuFactory->createItem('root');
  1238.         $menu->setChildrenAttribute('class''nav navbar-nav');
  1239.         $menu->setExtra('translation_domain'$this->translationDomain);
  1240.         // Prevents BC break with KnpMenuBundle v1.x
  1241.         if (method_exists($menu'setCurrentUri')) {
  1242.             $menu->setCurrentUri($this->getRequest()->getBaseUrl().$this->getRequest()->getPathInfo());
  1243.         }
  1244.         $this->configureTabMenu($menu$action$childAdmin);
  1245.         foreach ($this->getExtensions() as $extension) {
  1246.             $extension->configureTabMenu($this$menu$action$childAdmin);
  1247.         }
  1248.         $this->menu $menu;
  1249.         return $this->menu;
  1250.     }
  1251.     public function buildSideMenu($action, ?AdminInterface $childAdmin null)
  1252.     {
  1253.         return $this->buildTabMenu($action$childAdmin);
  1254.     }
  1255.     /**
  1256.      * @param string $action
  1257.      *
  1258.      * @return ItemInterface
  1259.      */
  1260.     public function getSideMenu($action, ?AdminInterface $childAdmin null)
  1261.     {
  1262.         if ($this->isChild()) {
  1263.             return $this->getParent()->getSideMenu($action$this);
  1264.         }
  1265.         $this->buildSideMenu($action$childAdmin);
  1266.         return $this->menu;
  1267.     }
  1268.     /**
  1269.      * Returns the root code.
  1270.      *
  1271.      * @return string the root code
  1272.      */
  1273.     public function getRootCode()
  1274.     {
  1275.         return $this->getRoot()->getCode();
  1276.     }
  1277.     /**
  1278.      * Returns the master admin.
  1279.      *
  1280.      * @return AbstractAdmin the root admin class
  1281.      */
  1282.     public function getRoot()
  1283.     {
  1284.         if (!$this->hasParentFieldDescription()) {
  1285.             return $this;
  1286.         }
  1287.         return $this->getParentFieldDescription()->getAdmin()->getRoot();
  1288.     }
  1289.     public function setBaseControllerName($baseControllerName)
  1290.     {
  1291.         $this->baseControllerName $baseControllerName;
  1292.     }
  1293.     public function getBaseControllerName()
  1294.     {
  1295.         return $this->baseControllerName;
  1296.     }
  1297.     /**
  1298.      * @param string $label
  1299.      */
  1300.     public function setLabel($label)
  1301.     {
  1302.         $this->label $label;
  1303.     }
  1304.     public function getLabel()
  1305.     {
  1306.         return $this->label;
  1307.     }
  1308.     /**
  1309.      * @param bool $persist
  1310.      *
  1311.      * NEXT_MAJOR: remove this method
  1312.      *
  1313.      * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0.
  1314.      */
  1315.     public function setPersistFilters($persist)
  1316.     {
  1317.         @trigger_error(
  1318.             'The '.__METHOD__.' method is deprecated since version 3.34 and will be removed in 4.0.',
  1319.             E_USER_DEPRECATED
  1320.         );
  1321.         $this->persistFilters $persist;
  1322.     }
  1323.     public function setFilterPersister(?FilterPersisterInterface $filterPersister null)
  1324.     {
  1325.         $this->filterPersister $filterPersister;
  1326.         // NEXT_MAJOR remove the deprecated property will be removed. Needed for persisted filter condition.
  1327.         $this->persistFilters true;
  1328.     }
  1329.     /**
  1330.      * NEXT_MAJOR: Remove this method.
  1331.      *
  1332.      * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0.
  1333.      *
  1334.      * @param int $maxPerPage
  1335.      */
  1336.     public function setMaxPerPage($maxPerPage)
  1337.     {
  1338.         @trigger_error(sprintf(
  1339.             'The method %s is deprecated since sonata-project/admin-bundle 3.67 and will be removed in 4.0.',
  1340.             __METHOD__
  1341.         ), E_USER_DEPRECATED);
  1342.         $this->maxPerPage $maxPerPage;
  1343.     }
  1344.     /**
  1345.      * @return int
  1346.      */
  1347.     public function getMaxPerPage()
  1348.     {
  1349.         // NEXT_MAJOR: Remove this line and uncomment the following.
  1350.         return $this->maxPerPage;
  1351.         // $sortValues = $this->getModelManager()->getDefaultSortValues($this->class);
  1352.         // return $sortValues['_per_page'] ?? 25;
  1353.     }
  1354.     /**
  1355.      * @param int $maxPageLinks
  1356.      */
  1357.     public function setMaxPageLinks($maxPageLinks)
  1358.     {
  1359.         $this->maxPageLinks $maxPageLinks;
  1360.     }
  1361.     /**
  1362.      * @return int
  1363.      */
  1364.     public function getMaxPageLinks()
  1365.     {
  1366.         return $this->maxPageLinks;
  1367.     }
  1368.     public function getFormGroups()
  1369.     {
  1370.         if (!\is_array($this->formGroups) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
  1371.             @trigger_error(sprintf(
  1372.                 'Returning other type than array in method %s() is deprecated since sonata-project/admin-bundle 3.65. It will return only array in version 4.0.',
  1373.                 __METHOD__
  1374.             ), E_USER_DEPRECATED);
  1375.         }
  1376.         return $this->formGroups;
  1377.     }
  1378.     public function setFormGroups(array $formGroups)
  1379.     {
  1380.         $this->formGroups $formGroups;
  1381.     }
  1382.     public function removeFieldFromFormGroup($key)
  1383.     {
  1384.         foreach ($this->formGroups as $name => $formGroup) {
  1385.             unset($this->formGroups[$name]['fields'][$key]);
  1386.             if (empty($this->formGroups[$name]['fields'])) {
  1387.                 unset($this->formGroups[$name]);
  1388.             }
  1389.         }
  1390.     }
  1391.     /**
  1392.      * @param string $group
  1393.      */
  1394.     public function reorderFormGroup($group, array $keys)
  1395.     {
  1396.         // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call.
  1397.         $formGroups $this->getFormGroups('sonata_deprecation_mute');
  1398.         $formGroups[$group]['fields'] = array_merge(array_flip($keys), $formGroups[$group]['fields']);
  1399.         $this->setFormGroups($formGroups);
  1400.     }
  1401.     public function getFormTabs()
  1402.     {
  1403.         if (!\is_array($this->formTabs) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
  1404.             @trigger_error(sprintf(
  1405.                 'Returning other type than array in method %s() is deprecated since sonata-project/admin-bundle 3.65. It will return only array in version 4.0.',
  1406.                 __METHOD__
  1407.             ), E_USER_DEPRECATED);
  1408.         }
  1409.         return $this->formTabs;
  1410.     }
  1411.     public function setFormTabs(array $formTabs)
  1412.     {
  1413.         $this->formTabs $formTabs;
  1414.     }
  1415.     public function getShowTabs()
  1416.     {
  1417.         if (!\is_array($this->showTabs) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
  1418.             @trigger_error(sprintf(
  1419.                 'Returning other type than array in method %s() is deprecated since sonata-project/admin-bundle 3.65. It will return only array in version 4.0.',
  1420.                 __METHOD__
  1421.             ), E_USER_DEPRECATED);
  1422.         }
  1423.         return $this->showTabs;
  1424.     }
  1425.     public function setShowTabs(array $showTabs)
  1426.     {
  1427.         $this->showTabs $showTabs;
  1428.     }
  1429.     public function getShowGroups()
  1430.     {
  1431.         if (!\is_array($this->showGroups) && 'sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
  1432.             @trigger_error(sprintf(
  1433.                 'Returning other type than array in method %s() is deprecated since sonata-project/admin-bundle 3.65. It will return only array in version 4.0.',
  1434.                 __METHOD__
  1435.             ), E_USER_DEPRECATED);
  1436.         }
  1437.         return $this->showGroups;
  1438.     }
  1439.     public function setShowGroups(array $showGroups)
  1440.     {
  1441.         $this->showGroups $showGroups;
  1442.     }
  1443.     public function reorderShowGroup($group, array $keys)
  1444.     {
  1445.         // NEXT_MAJOR: Remove the argument "sonata_deprecation_mute" in the following call.
  1446.         $showGroups $this->getShowGroups('sonata_deprecation_mute');
  1447.         $showGroups[$group]['fields'] = array_merge(array_flip($keys), $showGroups[$group]['fields']);
  1448.         $this->setShowGroups($showGroups);
  1449.     }
  1450.     public function setParentFieldDescription(FieldDescriptionInterface $parentFieldDescription)
  1451.     {
  1452.         $this->parentFieldDescription $parentFieldDescription;
  1453.     }
  1454.     public function getParentFieldDescription()
  1455.     {
  1456.         if (!$this->hasParentFieldDescription()) {
  1457.             @trigger_error(sprintf(
  1458.                 'Calling %s() when there is no parent field description is deprecated since sonata-project/admin-bundle 3.66 and will throw an exception in 4.0. '.
  1459.                 'Use %s::hasParentFieldDescription() to know if there is a parent field description.',
  1460.                 __METHOD__,
  1461.                 __CLASS__
  1462.             ), E_USER_DEPRECATED);
  1463.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare FieldDescriptionInterface as return type
  1464.             // throw new \LogicException(sprintf(
  1465.             //    'Admin "%s" has no parent field description.',
  1466.             //    static::class
  1467.             // ));
  1468.             return null;
  1469.         }
  1470.         return $this->parentFieldDescription;
  1471.     }
  1472.     public function hasParentFieldDescription()
  1473.     {
  1474.         return $this->parentFieldDescription instanceof FieldDescriptionInterface;
  1475.     }
  1476.     public function setSubject($subject)
  1477.     {
  1478.         if (\is_object($subject) && !is_a($subject$this->getClass(), true)) {
  1479.             $message = <<<'EOT'
  1480. You are trying to set entity an instance of "%s",
  1481. which is not the one registered with this admin class ("%s").
  1482. This is deprecated since 3.5 and will no longer be supported in 4.0.
  1483. EOT;
  1484.             @trigger_error(
  1485.                 sprintf($message, \get_class($subject), $this->getClass()),
  1486.                 E_USER_DEPRECATED
  1487.             ); // NEXT_MAJOR : throw an exception instead
  1488.         }
  1489.         $this->subject $subject;
  1490.     }
  1491.     public function getSubject()
  1492.     {
  1493.         if (!$this->hasSubject()) {
  1494.             @trigger_error(sprintf(
  1495.                 'Calling %s() when there is no subject is deprecated since sonata-project/admin-bundle 3.66 and will throw an exception in 4.0. '.
  1496.                 'Use %s::hasSubject() to know if there is a subject.',
  1497.                 __METHOD__,
  1498.                 __CLASS__
  1499.             ), E_USER_DEPRECATED);
  1500.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and update the return type
  1501.             // throw new \LogicException(sprintf(
  1502.             //    'Admin "%s" has no subject.',
  1503.             //    static::class
  1504.             // ));
  1505.             return null;
  1506.         }
  1507.         return $this->subject;
  1508.     }
  1509.     public function hasSubject()
  1510.     {
  1511.         if (null === $this->subject && $this->hasRequest() && !$this->hasParentFieldDescription()) {
  1512.             $id $this->request->get($this->getIdParameter());
  1513.             if (null !== $id) {
  1514.                 $this->subject $this->getObject($id);
  1515.             }
  1516.         }
  1517.         return null !== $this->subject;
  1518.     }
  1519.     public function getFormFieldDescriptions()
  1520.     {
  1521.         $this->buildForm();
  1522.         return $this->formFieldDescriptions;
  1523.     }
  1524.     public function getFormFieldDescription($name)
  1525.     {
  1526.         return $this->hasFormFieldDescription($name) ? $this->formFieldDescriptions[$name] : null;
  1527.     }
  1528.     /**
  1529.      * Returns true if the admin has a FieldDescription with the given $name.
  1530.      *
  1531.      * @param string $name
  1532.      *
  1533.      * @return bool
  1534.      */
  1535.     public function hasFormFieldDescription($name)
  1536.     {
  1537.         return \array_key_exists($name$this->formFieldDescriptions) ? true false;
  1538.     }
  1539.     public function addFormFieldDescription($nameFieldDescriptionInterface $fieldDescription)
  1540.     {
  1541.         $this->formFieldDescriptions[$name] = $fieldDescription;
  1542.     }
  1543.     /**
  1544.      * remove a FieldDescription.
  1545.      *
  1546.      * @param string $name
  1547.      */
  1548.     public function removeFormFieldDescription($name)
  1549.     {
  1550.         unset($this->formFieldDescriptions[$name]);
  1551.     }
  1552.     /**
  1553.      * build and return the collection of form FieldDescription.
  1554.      *
  1555.      * @return array collection of form FieldDescription
  1556.      */
  1557.     public function getShowFieldDescriptions()
  1558.     {
  1559.         $this->buildShow();
  1560.         return $this->showFieldDescriptions;
  1561.     }
  1562.     /**
  1563.      * Returns the form FieldDescription with the given $name.
  1564.      *
  1565.      * @param string $name
  1566.      *
  1567.      * @return FieldDescriptionInterface
  1568.      */
  1569.     public function getShowFieldDescription($name)
  1570.     {
  1571.         $this->buildShow();
  1572.         return $this->hasShowFieldDescription($name) ? $this->showFieldDescriptions[$name] : null;
  1573.     }
  1574.     public function hasShowFieldDescription($name)
  1575.     {
  1576.         return \array_key_exists($name$this->showFieldDescriptions);
  1577.     }
  1578.     public function addShowFieldDescription($nameFieldDescriptionInterface $fieldDescription)
  1579.     {
  1580.         $this->showFieldDescriptions[$name] = $fieldDescription;
  1581.     }
  1582.     public function removeShowFieldDescription($name)
  1583.     {
  1584.         unset($this->showFieldDescriptions[$name]);
  1585.     }
  1586.     public function getListFieldDescriptions()
  1587.     {
  1588.         $this->buildList();
  1589.         return $this->listFieldDescriptions;
  1590.     }
  1591.     public function getListFieldDescription($name)
  1592.     {
  1593.         if (!$this->hasListFieldDescription($name)) {
  1594.             @trigger_error(sprintf(
  1595.                 'Calling %s() when there is no list field description is deprecated since sonata-project/admin-bundle 3.66 and will throw an exception in 4.0. '.
  1596.                 'Use %s::hasListFieldDescription(\'%s\') to know if there is a list field description.',
  1597.                 __METHOD__,
  1598.                 __CLASS__,
  1599.                 $name
  1600.             ), E_USER_DEPRECATED);
  1601.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare FieldDescriptionInterface as return type
  1602.             // throw new \LogicException(sprintf(
  1603.             //    'Admin "%s" has no list field description for %s.',
  1604.             //    static::class,
  1605.             //    $name
  1606.             // ));
  1607.             return null;
  1608.         }
  1609.         return $this->listFieldDescriptions[$name];
  1610.     }
  1611.     public function hasListFieldDescription($name)
  1612.     {
  1613.         $this->buildList();
  1614.         return \array_key_exists($name$this->listFieldDescriptions) ? true false;
  1615.     }
  1616.     public function addListFieldDescription($nameFieldDescriptionInterface $fieldDescription)
  1617.     {
  1618.         $this->listFieldDescriptions[$name] = $fieldDescription;
  1619.     }
  1620.     public function removeListFieldDescription($name)
  1621.     {
  1622.         unset($this->listFieldDescriptions[$name]);
  1623.     }
  1624.     public function getFilterFieldDescription($name)
  1625.     {
  1626.         return $this->hasFilterFieldDescription($name) ? $this->filterFieldDescriptions[$name] : null;
  1627.     }
  1628.     public function hasFilterFieldDescription($name)
  1629.     {
  1630.         return \array_key_exists($name$this->filterFieldDescriptions) ? true false;
  1631.     }
  1632.     public function addFilterFieldDescription($nameFieldDescriptionInterface $fieldDescription)
  1633.     {
  1634.         $this->filterFieldDescriptions[$name] = $fieldDescription;
  1635.     }
  1636.     public function removeFilterFieldDescription($name)
  1637.     {
  1638.         unset($this->filterFieldDescriptions[$name]);
  1639.     }
  1640.     public function getFilterFieldDescriptions()
  1641.     {
  1642.         $this->buildDatagrid();
  1643.         return $this->filterFieldDescriptions;
  1644.     }
  1645.     public function addChild(AdminInterface $child)
  1646.     {
  1647.         $parentAdmin $this;
  1648.         while ($parentAdmin->isChild() && $parentAdmin->getCode() !== $child->getCode()) {
  1649.             $parentAdmin $parentAdmin->getParent();
  1650.         }
  1651.         if ($parentAdmin->getCode() === $child->getCode()) {
  1652.             throw new \RuntimeException(sprintf(
  1653.                 'Circular reference detected! The child admin `%s` is already in the parent tree of the `%s` admin.',
  1654.                 $child->getCode(),
  1655.                 $this->getCode()
  1656.             ));
  1657.         }
  1658.         $this->children[$child->getCode()] = $child;
  1659.         $child->setParent($this);
  1660.         // NEXT_MAJOR: remove $args and add $field parameter to this function on next Major
  1661.         $args = \func_get_args();
  1662.         if (isset($args[1])) {
  1663.             $child->addParentAssociationMapping($this->getCode(), $args[1]);
  1664.         } else {
  1665.             @trigger_error(
  1666.                 'Calling "addChild" without second argument is deprecated since'
  1667.                 .' sonata-project/admin-bundle 3.35 and will not be allowed in 4.0.',
  1668.                 E_USER_DEPRECATED
  1669.             );
  1670.         }
  1671.     }
  1672.     public function hasChild($code)
  1673.     {
  1674.         return isset($this->children[$code]);
  1675.     }
  1676.     public function getChildren()
  1677.     {
  1678.         return $this->children;
  1679.     }
  1680.     public function getChild($code)
  1681.     {
  1682.         return $this->hasChild($code) ? $this->children[$code] : null;
  1683.     }
  1684.     public function setParent(AdminInterface $parent)
  1685.     {
  1686.         $this->parent $parent;
  1687.     }
  1688.     public function getParent()
  1689.     {
  1690.         if (!$this->isChild()) {
  1691.             @trigger_error(sprintf(
  1692.                 'Calling %s() when there is no parent is deprecated since sonata-project/admin-bundle 3.66 and will throw an exception in 4.0. '.
  1693.                 'Use %s::isChild() to know if there is a parent.',
  1694.                 __METHOD__,
  1695.                 __CLASS__
  1696.             ), E_USER_DEPRECATED);
  1697.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement, uncomment the following exception and declare AdminInterface as return type
  1698.             // throw new \LogicException(sprintf(
  1699.             //    'Admin "%s" has no parent.',
  1700.             //    static::class
  1701.             // ));
  1702.             return null;
  1703.         }
  1704.         return $this->parent;
  1705.     }
  1706.     final public function getRootAncestor()
  1707.     {
  1708.         $parent $this;
  1709.         while ($parent->isChild()) {
  1710.             $parent $parent->getParent();
  1711.         }
  1712.         return $parent;
  1713.     }
  1714.     final public function getChildDepth()
  1715.     {
  1716.         $parent $this;
  1717.         $depth 0;
  1718.         while ($parent->isChild()) {
  1719.             $parent $parent->getParent();
  1720.             ++$depth;
  1721.         }
  1722.         return $depth;
  1723.     }
  1724.     final public function getCurrentLeafChildAdmin()
  1725.     {
  1726.         $child $this->getCurrentChildAdmin();
  1727.         if (null === $child) {
  1728.             return null;
  1729.         }
  1730.         for ($c $childnull !== $c$c $child->getCurrentChildAdmin()) {
  1731.             $child $c;
  1732.         }
  1733.         return $child;
  1734.     }
  1735.     public function isChild()
  1736.     {
  1737.         return $this->parent instanceof AdminInterface;
  1738.     }
  1739.     /**
  1740.      * Returns true if the admin has children, false otherwise.
  1741.      *
  1742.      * @return bool if the admin has children
  1743.      */
  1744.     public function hasChildren()
  1745.     {
  1746.         return \count($this->children) > 0;
  1747.     }
  1748.     public function setUniqid($uniqid)
  1749.     {
  1750.         $this->uniqid $uniqid;
  1751.     }
  1752.     public function getUniqid()
  1753.     {
  1754.         if (!$this->uniqid) {
  1755.             $this->uniqid 's'.uniqid();
  1756.         }
  1757.         return $this->uniqid;
  1758.     }
  1759.     /**
  1760.      * Returns the classname label.
  1761.      *
  1762.      * @return string the classname label
  1763.      */
  1764.     public function getClassnameLabel()
  1765.     {
  1766.         return $this->classnameLabel;
  1767.     }
  1768.     public function getPersistentParameters()
  1769.     {
  1770.         $parameters = [];
  1771.         foreach ($this->getExtensions() as $extension) {
  1772.             $params $extension->getPersistentParameters($this);
  1773.             if (!\is_array($params)) {
  1774.                 throw new \RuntimeException(sprintf('The %s::getPersistentParameters must return an array', \get_class($extension)));
  1775.             }
  1776.             $parameters array_merge($parameters$params);
  1777.         }
  1778.         return $parameters;
  1779.     }
  1780.     /**
  1781.      * @param string $name
  1782.      *
  1783.      * @return mixed|null
  1784.      */
  1785.     public function getPersistentParameter($name)
  1786.     {
  1787.         $parameters $this->getPersistentParameters();
  1788.         return $parameters[$name] ?? null;
  1789.     }
  1790.     public function getBreadcrumbs($action)
  1791.     {
  1792.         @trigger_error(
  1793.             'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
  1794.             ' Use Sonata\AdminBundle\Admin\BreadcrumbsBuilder::getBreadcrumbs instead.',
  1795.             E_USER_DEPRECATED
  1796.         );
  1797.         return $this->getBreadcrumbsBuilder()->getBreadcrumbs($this$action);
  1798.     }
  1799.     /**
  1800.      * Generates the breadcrumbs array.
  1801.      *
  1802.      * Note: the method will be called by the top admin instance (parent => child)
  1803.      *
  1804.      * @param string $action
  1805.      *
  1806.      * @return array
  1807.      */
  1808.     public function buildBreadcrumbs($action, ?ItemInterface $menu null)
  1809.     {
  1810.         @trigger_error(
  1811.             'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.',
  1812.             E_USER_DEPRECATED
  1813.         );
  1814.         if (isset($this->breadcrumbs[$action])) {
  1815.             return $this->breadcrumbs[$action];
  1816.         }
  1817.         return $this->breadcrumbs[$action] = $this->getBreadcrumbsBuilder()
  1818.             ->buildBreadcrumbs($this$action$menu);
  1819.     }
  1820.     /**
  1821.      * NEXT_MAJOR : remove this method.
  1822.      *
  1823.      * @return BreadcrumbsBuilderInterface
  1824.      */
  1825.     final public function getBreadcrumbsBuilder()
  1826.     {
  1827.         @trigger_error(
  1828.             'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
  1829.             ' Use the sonata.admin.breadcrumbs_builder service instead.',
  1830.             E_USER_DEPRECATED
  1831.         );
  1832.         if (null === $this->breadcrumbsBuilder) {
  1833.             $this->breadcrumbsBuilder = new BreadcrumbsBuilder(
  1834.                 $this->getConfigurationPool()->getContainer()->getParameter('sonata.admin.configuration.breadcrumbs')
  1835.             );
  1836.         }
  1837.         return $this->breadcrumbsBuilder;
  1838.     }
  1839.     /**
  1840.      * NEXT_MAJOR : remove this method.
  1841.      *
  1842.      * @return AbstractAdmin
  1843.      */
  1844.     final public function setBreadcrumbsBuilder(BreadcrumbsBuilderInterface $value)
  1845.     {
  1846.         @trigger_error(
  1847.             'The '.__METHOD__.' method is deprecated since version 3.2 and will be removed in 4.0.'.
  1848.             ' Use the sonata.admin.breadcrumbs_builder service instead.',
  1849.             E_USER_DEPRECATED
  1850.         );
  1851.         $this->breadcrumbsBuilder $value;
  1852.         return $this;
  1853.     }
  1854.     public function setCurrentChild($currentChild)
  1855.     {
  1856.         $this->currentChild $currentChild;
  1857.     }
  1858.     /**
  1859.      * NEXT_MAJOR: Remove this method.
  1860.      *
  1861.      * @deprecated since sonata-project/admin-bundle 3.65, to be removed in 4.0
  1862.      */
  1863.     public function getCurrentChild()
  1864.     {
  1865.         @trigger_error(
  1866.             sprintf(
  1867.                 'The %s() method is deprecated since version 3.65 and will be removed in 4.0. Use %s::isCurrentChild() instead.',
  1868.                 __METHOD__,
  1869.                 __CLASS__
  1870.             ),
  1871.             E_USER_DEPRECATED
  1872.         );
  1873.         return $this->currentChild;
  1874.     }
  1875.     public function isCurrentChild(): bool
  1876.     {
  1877.         return $this->currentChild;
  1878.     }
  1879.     /**
  1880.      * Returns the current child admin instance.
  1881.      *
  1882.      * @return AdminInterface|null the current child admin instance
  1883.      */
  1884.     public function getCurrentChildAdmin()
  1885.     {
  1886.         foreach ($this->children as $children) {
  1887.             if ($children->isCurrentChild()) {
  1888.                 return $children;
  1889.             }
  1890.         }
  1891.         return null;
  1892.     }
  1893.     public function trans($id, array $parameters = [], $domain null$locale null)
  1894.     {
  1895.         @trigger_error(
  1896.             'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
  1897.             E_USER_DEPRECATED
  1898.         );
  1899.         $domain $domain ?: $this->getTranslationDomain();
  1900.         return $this->translator->trans($id$parameters$domain$locale);
  1901.     }
  1902.     /**
  1903.      * Translate a message id.
  1904.      *
  1905.      * NEXT_MAJOR: remove this method
  1906.      *
  1907.      * @param string      $id
  1908.      * @param int         $count
  1909.      * @param string|null $domain
  1910.      * @param string|null $locale
  1911.      *
  1912.      * @return string the translated string
  1913.      *
  1914.      * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0
  1915.      */
  1916.     public function transChoice($id$count, array $parameters = [], $domain null$locale null)
  1917.     {
  1918.         @trigger_error(
  1919.             'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
  1920.             E_USER_DEPRECATED
  1921.         );
  1922.         $domain $domain ?: $this->getTranslationDomain();
  1923.         return $this->translator->transChoice($id$count$parameters$domain$locale);
  1924.     }
  1925.     public function setTranslationDomain($translationDomain)
  1926.     {
  1927.         $this->translationDomain $translationDomain;
  1928.     }
  1929.     public function getTranslationDomain()
  1930.     {
  1931.         return $this->translationDomain;
  1932.     }
  1933.     /**
  1934.      * {@inheritdoc}
  1935.      *
  1936.      * NEXT_MAJOR: remove this method
  1937.      *
  1938.      * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0
  1939.      */
  1940.     public function setTranslator(TranslatorInterface $translator)
  1941.     {
  1942.         $args = \func_get_args();
  1943.         if (isset($args[1]) && $args[1]) {
  1944.             @trigger_error(
  1945.                 'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
  1946.                 E_USER_DEPRECATED
  1947.             );
  1948.         }
  1949.         $this->translator $translator;
  1950.     }
  1951.     /**
  1952.      * {@inheritdoc}
  1953.      *
  1954.      * NEXT_MAJOR: remove this method
  1955.      *
  1956.      * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0
  1957.      */
  1958.     public function getTranslator()
  1959.     {
  1960.         @trigger_error(
  1961.             'The '.__METHOD__.' method is deprecated since version 3.9 and will be removed in 4.0.',
  1962.             E_USER_DEPRECATED
  1963.         );
  1964.         return $this->translator;
  1965.     }
  1966.     public function getTranslationLabel($label$context ''$type '')
  1967.     {
  1968.         return $this->getLabelTranslatorStrategy()->getLabel($label$context$type);
  1969.     }
  1970.     public function setRequest(Request $request)
  1971.     {
  1972.         $this->request $request;
  1973.         foreach ($this->getChildren() as $children) {
  1974.             $children->setRequest($request);
  1975.         }
  1976.     }
  1977.     public function getRequest()
  1978.     {
  1979.         if (!$this->request) {
  1980.             // NEXT_MAJOR: Throw \LogicException instead.
  1981.             throw new \RuntimeException('The Request object has not been set');
  1982.         }
  1983.         return $this->request;
  1984.     }
  1985.     public function hasRequest()
  1986.     {
  1987.         return null !== $this->request;
  1988.     }
  1989.     public function setFormContractor(FormContractorInterface $formBuilder)
  1990.     {
  1991.         $this->formContractor $formBuilder;
  1992.     }
  1993.     /**
  1994.      * @return FormContractorInterface
  1995.      */
  1996.     public function getFormContractor()
  1997.     {
  1998.         return $this->formContractor;
  1999.     }
  2000.     public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder)
  2001.     {
  2002.         $this->datagridBuilder $datagridBuilder;
  2003.     }
  2004.     public function getDatagridBuilder()
  2005.     {
  2006.         return $this->datagridBuilder;
  2007.     }
  2008.     public function setListBuilder(ListBuilderInterface $listBuilder)
  2009.     {
  2010.         $this->listBuilder $listBuilder;
  2011.     }
  2012.     public function getListBuilder()
  2013.     {
  2014.         return $this->listBuilder;
  2015.     }
  2016.     public function setShowBuilder(ShowBuilderInterface $showBuilder)
  2017.     {
  2018.         $this->showBuilder $showBuilder;
  2019.     }
  2020.     /**
  2021.      * @return ShowBuilderInterface
  2022.      */
  2023.     public function getShowBuilder()
  2024.     {
  2025.         return $this->showBuilder;
  2026.     }
  2027.     public function setConfigurationPool(Pool $configurationPool)
  2028.     {
  2029.         $this->configurationPool $configurationPool;
  2030.     }
  2031.     /**
  2032.      * @return Pool
  2033.      */
  2034.     public function getConfigurationPool()
  2035.     {
  2036.         return $this->configurationPool;
  2037.     }
  2038.     public function setRouteGenerator(RouteGeneratorInterface $routeGenerator)
  2039.     {
  2040.         $this->routeGenerator $routeGenerator;
  2041.     }
  2042.     /**
  2043.      * @return RouteGeneratorInterface
  2044.      */
  2045.     public function getRouteGenerator()
  2046.     {
  2047.         return $this->routeGenerator;
  2048.     }
  2049.     public function getCode()
  2050.     {
  2051.         return $this->code;
  2052.     }
  2053.     /**
  2054.      * NEXT_MAJOR: Remove this function.
  2055.      *
  2056.      * @deprecated This method is deprecated since sonata-project/admin-bundle 3.24 and will be removed in 4.0
  2057.      *
  2058.      * @param string $baseCodeRoute
  2059.      */
  2060.     public function setBaseCodeRoute($baseCodeRoute)
  2061.     {
  2062.         @trigger_error(
  2063.             'The '.__METHOD__.' is deprecated since 3.24 and will be removed in 4.0.',
  2064.             E_USER_DEPRECATED
  2065.         );
  2066.         $this->baseCodeRoute $baseCodeRoute;
  2067.     }
  2068.     public function getBaseCodeRoute()
  2069.     {
  2070.         // NEXT_MAJOR: Uncomment the following lines.
  2071.         // if ($this->isChild()) {
  2072.         //     return $this->getParent()->getBaseCodeRoute().'|'.$this->getCode();
  2073.         // }
  2074.         //
  2075.         // return $this->getCode();
  2076.         // NEXT_MAJOR: Remove all the code below.
  2077.         if ($this->isChild()) {
  2078.             $parentCode $this->getParent()->getCode();
  2079.             if ($this->getParent()->isChild()) {
  2080.                 $parentCode $this->getParent()->getBaseCodeRoute();
  2081.             }
  2082.             return $parentCode.'|'.$this->getCode();
  2083.         }
  2084.         return $this->baseCodeRoute;
  2085.     }
  2086.     public function getModelManager()
  2087.     {
  2088.         return $this->modelManager;
  2089.     }
  2090.     public function setModelManager(ModelManagerInterface $modelManager)
  2091.     {
  2092.         $this->modelManager $modelManager;
  2093.     }
  2094.     public function getManagerType()
  2095.     {
  2096.         return $this->managerType;
  2097.     }
  2098.     /**
  2099.      * @param string $type
  2100.      */
  2101.     public function setManagerType($type)
  2102.     {
  2103.         $this->managerType $type;
  2104.     }
  2105.     public function getObjectIdentifier()
  2106.     {
  2107.         return $this->getCode();
  2108.     }
  2109.     /**
  2110.      * Set the roles and permissions per role.
  2111.      */
  2112.     public function setSecurityInformation(array $information)
  2113.     {
  2114.         $this->securityInformation $information;
  2115.     }
  2116.     public function getSecurityInformation()
  2117.     {
  2118.         return $this->securityInformation;
  2119.     }
  2120.     /**
  2121.      * Return the list of permissions the user should have in order to display the admin.
  2122.      *
  2123.      * @param string $context
  2124.      *
  2125.      * @return array
  2126.      */
  2127.     public function getPermissionsShow($context)
  2128.     {
  2129.         switch ($context) {
  2130.             case self::CONTEXT_DASHBOARD:
  2131.             case self::CONTEXT_MENU:
  2132.             default:
  2133.                 return ['LIST'];
  2134.         }
  2135.     }
  2136.     public function showIn($context)
  2137.     {
  2138.         switch ($context) {
  2139.             case self::CONTEXT_DASHBOARD:
  2140.             case self::CONTEXT_MENU:
  2141.             default:
  2142.                 return $this->isGranted($this->getPermissionsShow($context));
  2143.         }
  2144.     }
  2145.     public function createObjectSecurity($object)
  2146.     {
  2147.         $this->getSecurityHandler()->createObjectSecurity($this$object);
  2148.     }
  2149.     public function setSecurityHandler(SecurityHandlerInterface $securityHandler)
  2150.     {
  2151.         $this->securityHandler $securityHandler;
  2152.     }
  2153.     public function getSecurityHandler()
  2154.     {
  2155.         return $this->securityHandler;
  2156.     }
  2157.     public function isGranted($name$object null)
  2158.     {
  2159.         $objectRef $object '/'.spl_object_hash($object).'#'.$this->id($object) : '';
  2160.         $key md5(json_encode($name).$objectRef);
  2161.         if (!\array_key_exists($key$this->cacheIsGranted)) {
  2162.             $this->cacheIsGranted[$key] = $this->securityHandler->isGranted($this$name$object ?: $this);
  2163.         }
  2164.         return $this->cacheIsGranted[$key];
  2165.     }
  2166.     public function getUrlSafeIdentifier($entity)
  2167.     {
  2168.         return $this->getModelManager()->getUrlSafeIdentifier($entity);
  2169.     }
  2170.     public function getNormalizedIdentifier($entity)
  2171.     {
  2172.         return $this->getModelManager()->getNormalizedIdentifier($entity);
  2173.     }
  2174.     public function id($entity)
  2175.     {
  2176.         return $this->getNormalizedIdentifier($entity);
  2177.     }
  2178.     public function setValidator($validator)
  2179.     {
  2180.         // NEXT_MAJOR: Move ValidatorInterface check to method signature
  2181.         if (!$validator instanceof ValidatorInterface) {
  2182.             throw new \InvalidArgumentException(
  2183.                 'Argument 1 must be an instance of Symfony\Component\Validator\Validator\ValidatorInterface'
  2184.             );
  2185.         }
  2186.         $this->validator $validator;
  2187.     }
  2188.     public function getValidator()
  2189.     {
  2190.         return $this->validator;
  2191.     }
  2192.     public function getShow()
  2193.     {
  2194.         $this->buildShow();
  2195.         return $this->show;
  2196.     }
  2197.     public function setFormTheme(array $formTheme)
  2198.     {
  2199.         $this->formTheme $formTheme;
  2200.     }
  2201.     public function getFormTheme()
  2202.     {
  2203.         return $this->formTheme;
  2204.     }
  2205.     public function setFilterTheme(array $filterTheme)
  2206.     {
  2207.         $this->filterTheme $filterTheme;
  2208.     }
  2209.     public function getFilterTheme()
  2210.     {
  2211.         return $this->filterTheme;
  2212.     }
  2213.     public function addExtension(AdminExtensionInterface $extension)
  2214.     {
  2215.         $this->extensions[] = $extension;
  2216.     }
  2217.     public function getExtensions()
  2218.     {
  2219.         return $this->extensions;
  2220.     }
  2221.     public function setMenuFactory(FactoryInterface $menuFactory)
  2222.     {
  2223.         $this->menuFactory $menuFactory;
  2224.     }
  2225.     public function getMenuFactory()
  2226.     {
  2227.         return $this->menuFactory;
  2228.     }
  2229.     public function setRouteBuilder(RouteBuilderInterface $routeBuilder)
  2230.     {
  2231.         $this->routeBuilder $routeBuilder;
  2232.     }
  2233.     public function getRouteBuilder()
  2234.     {
  2235.         return $this->routeBuilder;
  2236.     }
  2237.     public function toString($object)
  2238.     {
  2239.         if (!\is_object($object)) {
  2240.             return '';
  2241.         }
  2242.         if (method_exists($object'__toString') && null !== $object->__toString()) {
  2243.             return (string) $object;
  2244.         }
  2245.         return sprintf('%s:%s'ClassUtils::getClass($object), spl_object_hash($object));
  2246.     }
  2247.     public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy)
  2248.     {
  2249.         $this->labelTranslatorStrategy $labelTranslatorStrategy;
  2250.     }
  2251.     public function getLabelTranslatorStrategy()
  2252.     {
  2253.         return $this->labelTranslatorStrategy;
  2254.     }
  2255.     public function supportsPreviewMode()
  2256.     {
  2257.         return $this->supportsPreviewMode;
  2258.     }
  2259.     /**
  2260.      * NEXT_MAJOR: Remove this.
  2261.      *
  2262.      * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0.
  2263.      *
  2264.      * Set custom per page options.
  2265.      */
  2266.     public function setPerPageOptions(array $options)
  2267.     {
  2268.         @trigger_error(sprintf(
  2269.             'The method %s is deprecated since sonata-project/admin-bundle 3.67 and will be removed in 4.0.',
  2270.             __METHOD__
  2271.         ), E_USER_DEPRECATED);
  2272.         $this->perPageOptions $options;
  2273.     }
  2274.     /**
  2275.      * Returns predefined per page options.
  2276.      *
  2277.      * @return array
  2278.      */
  2279.     public function getPerPageOptions()
  2280.     {
  2281.         // NEXT_MAJOR: Remove this line and uncomment the following
  2282.         return $this->perPageOptions;
  2283. //        $perPageOptions = $this->getModelManager()->getDefaultPerPageOptions($this->class);
  2284. //        $perPageOptions[] = $this->getMaxPerPage();
  2285. //
  2286. //        $perPageOptions = array_unique($perPageOptions);
  2287. //        sort($perPageOptions);
  2288. //
  2289. //        return $perPageOptions;
  2290.     }
  2291.     /**
  2292.      * Set pager type.
  2293.      *
  2294.      * @param string $pagerType
  2295.      */
  2296.     public function setPagerType($pagerType)
  2297.     {
  2298.         $this->pagerType $pagerType;
  2299.     }
  2300.     /**
  2301.      * Get pager type.
  2302.      *
  2303.      * @return string
  2304.      */
  2305.     public function getPagerType()
  2306.     {
  2307.         return $this->pagerType;
  2308.     }
  2309.     /**
  2310.      * Returns true if the per page value is allowed, false otherwise.
  2311.      *
  2312.      * @param int $perPage
  2313.      *
  2314.      * @return bool
  2315.      */
  2316.     public function determinedPerPageValue($perPage)
  2317.     {
  2318.         return \in_array($perPage$this->getPerPageOptions(), true);
  2319.     }
  2320.     public function isAclEnabled()
  2321.     {
  2322.         return $this->getSecurityHandler() instanceof AclSecurityHandlerInterface;
  2323.     }
  2324.     public function getObjectMetadata($object)
  2325.     {
  2326.         return new Metadata($this->toString($object));
  2327.     }
  2328.     public function getListModes()
  2329.     {
  2330.         return $this->listModes;
  2331.     }
  2332.     public function setListMode($mode)
  2333.     {
  2334.         if (!$this->hasRequest()) {
  2335.             throw new \RuntimeException(sprintf('No request attached to the current admin: %s'$this->getCode()));
  2336.         }
  2337.         $this->getRequest()->getSession()->set(sprintf('%s.list_mode'$this->getCode()), $mode);
  2338.     }
  2339.     public function getListMode()
  2340.     {
  2341.         if (!$this->hasRequest()) {
  2342.             return 'list';
  2343.         }
  2344.         return $this->getRequest()->getSession()->get(sprintf('%s.list_mode'$this->getCode()), 'list');
  2345.     }
  2346.     public function getAccessMapping()
  2347.     {
  2348.         return $this->accessMapping;
  2349.     }
  2350.     public function checkAccess($action$object null)
  2351.     {
  2352.         $access $this->getAccess();
  2353.         if (!\array_key_exists($action$access)) {
  2354.             throw new \InvalidArgumentException(sprintf(
  2355.                 'Action "%s" could not be found in access mapping.'
  2356.                 .' Please make sure your action is defined into your admin class accessMapping property.',
  2357.                 $action
  2358.             ));
  2359.         }
  2360.         if (!\is_array($access[$action])) {
  2361.             $access[$action] = [$access[$action]];
  2362.         }
  2363.         foreach ($access[$action] as $role) {
  2364.             if (false === $this->isGranted($role$object)) {
  2365.                 throw new AccessDeniedException(sprintf('Access Denied to the action %s and role %s'$action$role));
  2366.             }
  2367.         }
  2368.     }
  2369.     /**
  2370.      * Hook to handle access authorization, without throw Exception.
  2371.      *
  2372.      * @param string $action
  2373.      * @param object $object
  2374.      *
  2375.      * @return bool
  2376.      */
  2377.     public function hasAccess($action$object null)
  2378.     {
  2379.         $access $this->getAccess();
  2380.         if (!\array_key_exists($action$access)) {
  2381.             return false;
  2382.         }
  2383.         if (!\is_array($access[$action])) {
  2384.             $access[$action] = [$access[$action]];
  2385.         }
  2386.         foreach ($access[$action] as $role) {
  2387.             if (false === $this->isGranted($role$object)) {
  2388.                 return false;
  2389.             }
  2390.         }
  2391.         return true;
  2392.     }
  2393.     /**
  2394.      * @param string      $action
  2395.      * @param object|null $object
  2396.      *
  2397.      * @return array
  2398.      */
  2399.     public function configureActionButtons($action$object null)
  2400.     {
  2401.         $list = [];
  2402.         if (\in_array($action, ['tree''show''edit''delete''list''batch'], true)
  2403.             && $this->hasAccess('create')
  2404.             && $this->hasRoute('create')
  2405.         ) {
  2406.             $list['create'] = [
  2407.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2408.                 'template' => $this->getTemplate('button_create'),
  2409. //                'template' => $this->getTemplateRegistry()->getTemplate('button_create'),
  2410.             ];
  2411.         }
  2412.         if (\in_array($action, ['show''delete''acl''history'], true)
  2413.             && $this->canAccessObject('edit'$object)
  2414.             && $this->hasRoute('edit')
  2415.         ) {
  2416.             $list['edit'] = [
  2417.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2418.                 'template' => $this->getTemplate('button_edit'),
  2419.                 //'template' => $this->getTemplateRegistry()->getTemplate('button_edit'),
  2420.             ];
  2421.         }
  2422.         if (\in_array($action, ['show''edit''acl'], true)
  2423.             && $this->canAccessObject('history'$object)
  2424.             && $this->hasRoute('history')
  2425.         ) {
  2426.             $list['history'] = [
  2427.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2428.                 'template' => $this->getTemplate('button_history'),
  2429.                 // 'template' => $this->getTemplateRegistry()->getTemplate('button_history'),
  2430.             ];
  2431.         }
  2432.         if (\in_array($action, ['edit''history'], true)
  2433.             && $this->isAclEnabled()
  2434.             && $this->canAccessObject('acl'$object)
  2435.             && $this->hasRoute('acl')
  2436.         ) {
  2437.             $list['acl'] = [
  2438.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2439.                 'template' => $this->getTemplate('button_acl'),
  2440.                 // 'template' => $this->getTemplateRegistry()->getTemplate('button_acl'),
  2441.             ];
  2442.         }
  2443.         if (\in_array($action, ['edit''history''acl'], true)
  2444.             && $this->canAccessObject('show'$object)
  2445.             && \count($this->getShow()) > 0
  2446.             && $this->hasRoute('show')
  2447.         ) {
  2448.             $list['show'] = [
  2449.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2450.                 'template' => $this->getTemplate('button_show'),
  2451.                 // 'template' => $this->getTemplateRegistry()->getTemplate('button_show'),
  2452.             ];
  2453.         }
  2454.         if (\in_array($action, ['show''edit''delete''acl''batch'], true)
  2455.             && $this->hasAccess('list')
  2456.             && $this->hasRoute('list')
  2457.         ) {
  2458.             $list['list'] = [
  2459.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2460.                 'template' => $this->getTemplate('button_list'),
  2461.                 // 'template' => $this->getTemplateRegistry()->getTemplate('button_list'),
  2462.             ];
  2463.         }
  2464.         return $list;
  2465.     }
  2466.     /**
  2467.      * @param string $action
  2468.      * @param object $object
  2469.      *
  2470.      * @return array
  2471.      */
  2472.     public function getActionButtons($action$object null)
  2473.     {
  2474.         $list $this->configureActionButtons($action$object);
  2475.         foreach ($this->getExtensions() as $extension) {
  2476.             // NEXT_MAJOR: remove method check
  2477.             if (method_exists($extension'configureActionButtons')) {
  2478.                 $list $extension->configureActionButtons($this$list$action$object);
  2479.             }
  2480.         }
  2481.         return $list;
  2482.     }
  2483.     /**
  2484.      * Get the list of actions that can be accessed directly from the dashboard.
  2485.      *
  2486.      * @return array
  2487.      */
  2488.     public function getDashboardActions()
  2489.     {
  2490.         $actions = [];
  2491.         if ($this->hasRoute('create') && $this->hasAccess('create')) {
  2492.             $actions['create'] = [
  2493.                 'label' => 'link_add',
  2494.                 'translation_domain' => 'SonataAdminBundle',
  2495.                 // NEXT_MAJOR: Remove this line and use commented line below it instead
  2496.                 'template' => $this->getTemplate('action_create'),
  2497.                 // 'template' => $this->getTemplateRegistry()->getTemplate('action_create'),
  2498.                 'url' => $this->generateUrl('create'),
  2499.                 'icon' => 'plus-circle',
  2500.             ];
  2501.         }
  2502.         if ($this->hasRoute('list') && $this->hasAccess('list')) {
  2503.             $actions['list'] = [
  2504.                 'label' => 'link_list',
  2505.                 'translation_domain' => 'SonataAdminBundle',
  2506.                 'url' => $this->generateUrl('list'),
  2507.                 'icon' => 'list',
  2508.             ];
  2509.         }
  2510.         return $actions;
  2511.     }
  2512.     /**
  2513.      * Setting to true will enable mosaic button for the admin screen.
  2514.      * Setting to false will hide mosaic button for the admin screen.
  2515.      *
  2516.      * @param bool $isShown
  2517.      */
  2518.     final public function showMosaicButton($isShown)
  2519.     {
  2520.         if ($isShown) {
  2521.             $this->listModes['mosaic'] = ['class' => static::MOSAIC_ICON_CLASS];
  2522.         } else {
  2523.             unset($this->listModes['mosaic']);
  2524.         }
  2525.     }
  2526.     /**
  2527.      * @param object $object
  2528.      */
  2529.     final public function getSearchResultLink($object)
  2530.     {
  2531.         foreach ($this->searchResultActions as $action) {
  2532.             if ($this->hasRoute($action) && $this->hasAccess($action$object)) {
  2533.                 return $this->generateObjectUrl($action$object);
  2534.             }
  2535.         }
  2536.         return null;
  2537.     }
  2538.     /**
  2539.      * Checks if a filter type is set to a default value.
  2540.      *
  2541.      * @param string $name
  2542.      *
  2543.      * @return bool
  2544.      */
  2545.     final public function isDefaultFilter($name)
  2546.     {
  2547.         $filter $this->getFilterParameters();
  2548.         $default $this->getDefaultFilterValues();
  2549.         if (!\array_key_exists($name$filter) || !\array_key_exists($name$default)) {
  2550.             return false;
  2551.         }
  2552.         return $filter[$name] === $default[$name];
  2553.     }
  2554.     /**
  2555.      * Check object existence and access, without throw Exception.
  2556.      *
  2557.      * @param string $action
  2558.      * @param object $object
  2559.      *
  2560.      * @return bool
  2561.      */
  2562.     public function canAccessObject($action$object)
  2563.     {
  2564.         return $object && $this->id($object) && $this->hasAccess($action$object);
  2565.     }
  2566.     protected function configureQuery(ProxyQueryInterface $query): ProxyQueryInterface
  2567.     {
  2568.         return $query;
  2569.     }
  2570.     /**
  2571.      * @return MutableTemplateRegistryInterface
  2572.      */
  2573.     final protected function getTemplateRegistry()
  2574.     {
  2575.         return $this->templateRegistry;
  2576.     }
  2577.     /**
  2578.      * Returns a list of default sort values.
  2579.      *
  2580.      * @return array{_page?: int, _per_page?: int, _sort_by?: string, _sort_order?: string}
  2581.      */
  2582.     final protected function getDefaultSortValues(): array
  2583.     {
  2584.         $defaultSortValues = [];
  2585.         $this->configureDefaultSortValues($defaultSortValues);
  2586.         foreach ($this->getExtensions() as $extension) {
  2587.             // NEXT_MAJOR: remove method check
  2588.             if (method_exists($extension'configureDefaultSortValues')) {
  2589.                 $extension->configureDefaultSortValues($this$defaultSortValues);
  2590.             }
  2591.         }
  2592.         return $defaultSortValues;
  2593.     }
  2594.     /**
  2595.      * Returns a list of default filters.
  2596.      *
  2597.      * @return array
  2598.      */
  2599.     final protected function getDefaultFilterValues()
  2600.     {
  2601.         $defaultFilterValues = [];
  2602.         $this->configureDefaultFilterValues($defaultFilterValues);
  2603.         foreach ($this->getExtensions() as $extension) {
  2604.             // NEXT_MAJOR: remove method check
  2605.             if (method_exists($extension'configureDefaultFilterValues')) {
  2606.                 $extension->configureDefaultFilterValues($this$defaultFilterValues);
  2607.             }
  2608.         }
  2609.         return $defaultFilterValues;
  2610.     }
  2611.     protected function configureFormFields(FormMapper $form)
  2612.     {
  2613.     }
  2614.     protected function configureListFields(ListMapper $list)
  2615.     {
  2616.     }
  2617.     protected function configureDatagridFilters(DatagridMapper $filter)
  2618.     {
  2619.     }
  2620.     protected function configureShowFields(ShowMapper $show)
  2621.     {
  2622.     }
  2623.     protected function configureRoutes(RouteCollection $collection)
  2624.     {
  2625.     }
  2626.     /**
  2627.      * Allows you to customize batch actions.
  2628.      *
  2629.      * @param array $actions List of actions
  2630.      *
  2631.      * @return array
  2632.      */
  2633.     protected function configureBatchActions($actions)
  2634.     {
  2635.         return $actions;
  2636.     }
  2637.     /**
  2638.      * NEXT_MAJOR: remove this method.
  2639.      *
  2640.      * @deprecated Use configureTabMenu instead
  2641.      */
  2642.     protected function configureSideMenu(ItemInterface $menu$action, ?AdminInterface $childAdmin null)
  2643.     {
  2644.     }
  2645.     /**
  2646.      * Configures the tab menu in your admin.
  2647.      *
  2648.      * @param string $action
  2649.      */
  2650.     protected function configureTabMenu(ItemInterface $menu$action, ?AdminInterface $childAdmin null)
  2651.     {
  2652.         // Use configureSideMenu not to mess with previous overrides
  2653.         // NEXT_MAJOR: remove this line
  2654.         $this->configureSideMenu($menu$action$childAdmin);
  2655.     }
  2656.     /**
  2657.      * build the view FieldDescription array.
  2658.      */
  2659.     protected function buildShow()
  2660.     {
  2661.         if ($this->show) {
  2662.             return;
  2663.         }
  2664.         $this->show = new FieldDescriptionCollection();
  2665.         $mapper = new ShowMapper($this->showBuilder$this->show$this);
  2666.         $this->configureShowFields($mapper);
  2667.         foreach ($this->getExtensions() as $extension) {
  2668.             $extension->configureShowFields($mapper);
  2669.         }
  2670.     }
  2671.     /**
  2672.      * build the list FieldDescription array.
  2673.      */
  2674.     protected function buildList()
  2675.     {
  2676.         if ($this->list) {
  2677.             return;
  2678.         }
  2679.         $this->list $this->getListBuilder()->getBaseList();
  2680.         $mapper = new ListMapper($this->getListBuilder(), $this->list$this);
  2681.         if (\count($this->getBatchActions()) > && $this->hasRequest() && !$this->getRequest()->isXmlHttpRequest()) {
  2682.             $fieldDescription $this->getModelManager()->getNewFieldDescriptionInstance(
  2683.                 $this->getClass(),
  2684.                 'batch',
  2685.                 [
  2686.                     'label' => 'batch',
  2687.                     'code' => '_batch',
  2688.                     'sortable' => false,
  2689.                     'virtual_field' => true,
  2690.                 ]
  2691.             );
  2692.             $fieldDescription->setAdmin($this);
  2693.             // NEXT_MAJOR: Remove this line and use commented line below it instead
  2694.             $fieldDescription->setTemplate($this->getTemplate('batch'));
  2695.             // $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('batch'));
  2696.             $mapper->add($fieldDescription'batch');
  2697.         }
  2698.         $this->configureListFields($mapper);
  2699.         foreach ($this->getExtensions() as $extension) {
  2700.             $extension->configureListFields($mapper);
  2701.         }
  2702.         if ($this->hasRequest() && $this->getRequest()->isXmlHttpRequest()) {
  2703.             $fieldDescription $this->getModelManager()->getNewFieldDescriptionInstance(
  2704.                 $this->getClass(),
  2705.                 'select',
  2706.                 [
  2707.                     'label' => false,
  2708.                     'code' => '_select',
  2709.                     'sortable' => false,
  2710.                     'virtual_field' => false,
  2711.                 ]
  2712.             );
  2713.             $fieldDescription->setAdmin($this);
  2714.             // NEXT_MAJOR: Remove this line and use commented line below it instead
  2715.             $fieldDescription->setTemplate($this->getTemplate('select'));
  2716.             // $fieldDescription->setTemplate($this->getTemplateRegistry()->getTemplate('select'));
  2717.             $mapper->add($fieldDescription'select');
  2718.         }
  2719.     }
  2720.     /**
  2721.      * Build the form FieldDescription collection.
  2722.      */
  2723.     protected function buildForm()
  2724.     {
  2725.         if ($this->form) {
  2726.             return;
  2727.         }
  2728.         // append parent object if any
  2729.         // todo : clean the way the Admin class can retrieve set the object
  2730.         if ($this->isChild() && $this->getParentAssociationMapping()) {
  2731.             $parent $this->getParent()->getObject($this->request->get($this->getParent()->getIdParameter()));
  2732.             $propertyAccessor $this->getConfigurationPool()->getPropertyAccessor();
  2733.             $propertyPath = new PropertyPath($this->getParentAssociationMapping());
  2734.             $object $this->getSubject();
  2735.             $value $propertyAccessor->getValue($object$propertyPath);
  2736.             if (\is_array($value) || $value instanceof \ArrayAccess) {
  2737.                 $value[] = $parent;
  2738.                 $propertyAccessor->setValue($object$propertyPath$value);
  2739.             } else {
  2740.                 $propertyAccessor->setValue($object$propertyPath$parent);
  2741.             }
  2742.         }
  2743.         $formBuilder $this->getFormBuilder();
  2744.         $formBuilder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
  2745.             $this->preValidate($event->getData());
  2746.         }, 100);
  2747.         $this->form $formBuilder->getForm();
  2748.     }
  2749.     /**
  2750.      * Gets the subclass corresponding to the given name.
  2751.      *
  2752.      * @param string $name The name of the sub class
  2753.      *
  2754.      * @return string the subclass
  2755.      */
  2756.     protected function getSubClass($name)
  2757.     {
  2758.         if ($this->hasSubClass($name)) {
  2759.             return $this->subClasses[$name];
  2760.         }
  2761.         // NEXT_MAJOR: Throw \LogicException instead.
  2762.         throw new \RuntimeException(sprintf(
  2763.             'Unable to find the subclass `%s` for admin `%s`',
  2764.             $name,
  2765.             static::class
  2766.         ));
  2767.     }
  2768.     /**
  2769.      * Attach the inline validator to the model metadata, this must be done once per admin.
  2770.      */
  2771.     protected function attachInlineValidator()
  2772.     {
  2773.         $admin $this;
  2774.         // add the custom inline validation option
  2775.         $metadata $this->validator->getMetadataFor($this->getClass());
  2776.         $metadata->addConstraint(new InlineConstraint([
  2777.             'service' => $this,
  2778.             'method' => static function (ErrorElement $errorElement$object) use ($admin) {
  2779.                 /* @var \Sonata\AdminBundle\Admin\AdminInterface $admin */
  2780.                 // This avoid the main validation to be cascaded to children
  2781.                 // The problem occurs when a model Page has a collection of Page as property
  2782.                 if ($admin->hasSubject() && spl_object_hash($object) !== spl_object_hash($admin->getSubject())) {
  2783.                     return;
  2784.                 }
  2785.                 $admin->validate($errorElement$object);
  2786.                 foreach ($admin->getExtensions() as $extension) {
  2787.                     $extension->validate($admin$errorElement$object);
  2788.                 }
  2789.             },
  2790.             'serializingWarning' => true,
  2791.         ]));
  2792.     }
  2793.     /**
  2794.      * NEXT_MAJOR: Remove this function.
  2795.      *
  2796.      * @deprecated since sonata-project/admin-bundle 3.67, to be removed in 4.0.
  2797.      *
  2798.      * Predefine per page options.
  2799.      */
  2800.     protected function predefinePerPageOptions()
  2801.     {
  2802.         array_unshift($this->perPageOptions$this->maxPerPage);
  2803.         $this->perPageOptions array_unique($this->perPageOptions);
  2804.         sort($this->perPageOptions);
  2805.     }
  2806.     /**
  2807.      * Return list routes with permissions name.
  2808.      *
  2809.      * @return array<string, string>
  2810.      */
  2811.     protected function getAccess()
  2812.     {
  2813.         $access array_merge([
  2814.             'acl' => 'MASTER',
  2815.             'export' => 'EXPORT',
  2816.             'historyCompareRevisions' => 'EDIT',
  2817.             'historyViewRevision' => 'EDIT',
  2818.             'history' => 'EDIT',
  2819.             'edit' => 'EDIT',
  2820.             'show' => 'VIEW',
  2821.             'create' => 'CREATE',
  2822.             'delete' => 'DELETE',
  2823.             'batchDelete' => 'DELETE',
  2824.             'list' => 'LIST',
  2825.         ], $this->getAccessMapping());
  2826.         foreach ($this->extensions as $extension) {
  2827.             // NEXT_MAJOR: remove method check
  2828.             if (method_exists($extension'getAccessMapping')) {
  2829.                 $access array_merge($access$extension->getAccessMapping($this));
  2830.             }
  2831.         }
  2832.         return $access;
  2833.     }
  2834.     /**
  2835.      * Configures a list of default filters.
  2836.      */
  2837.     protected function configureDefaultFilterValues(array &$filterValues)
  2838.     {
  2839.     }
  2840.     /**
  2841.      * Configures a list of default sort values.
  2842.      *
  2843.      * Example:
  2844.      *   $sortValues['_sort_by'] = 'foo'
  2845.      *   $sortValues['_sort_order'] = 'DESC'
  2846.      */
  2847.     protected function configureDefaultSortValues(array &$sortValues)
  2848.     {
  2849.     }
  2850.     /**
  2851.      * Build all the related urls to the current admin.
  2852.      */
  2853.     private function buildRoutes(): void
  2854.     {
  2855.         if ($this->loaded['routes']) {
  2856.             return;
  2857.         }
  2858.         $this->loaded['routes'] = true;
  2859.         $this->routes = new RouteCollection(
  2860.             $this->getBaseCodeRoute(),
  2861.             $this->getBaseRouteName(),
  2862.             $this->getBaseRoutePattern(),
  2863.             $this->getBaseControllerName()
  2864.         );
  2865.         $this->routeBuilder->build($this$this->routes);
  2866.         $this->configureRoutes($this->routes);
  2867.         foreach ($this->getExtensions() as $extension) {
  2868.             $extension->configureRoutes($this$this->routes);
  2869.         }
  2870.     }
  2871. }
  2872. class_exists(\Sonata\Form\Validator\ErrorElement::class);