From 6596b2db428908c0504f4481309431e6af31e2ae Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Tue, 15 Dec 2020 11:41:41 +0100 Subject: [PATCH 01/30] Use sonata_config instead of admin_pool (#6677) --- src/Resources/views/Pager/base_links.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/Pager/base_links.html.twig b/src/Resources/views/Pager/base_links.html.twig index 504db97db3..2a0314a78c 100644 --- a/src/Resources/views/Pager/base_links.html.twig +++ b/src/Resources/views/Pager/base_links.html.twig @@ -24,7 +24,7 @@ file that was distributed with this source code. {% endif %} {# Set the number of pages to display in the pager #} - {% for page in admin.datagrid.pager.getLinks(admin_pool.getOption('pager_links')) %} + {% for page in admin.datagrid.pager.getLinks(sonata_config.getOption('pager_links')) %} {% if page == admin.datagrid.pager.page %} {# NEXT_MAJOR: Remove next line and uncomment the other one #}
  • {{ page }}
  • From bcc06ac13c9c33c458c27ba04a408c76ba81299c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:19:38 +0100 Subject: [PATCH 02/30] Improve NEXT_MAJOR comment for export This way it will avoid extra translations --- src/Admin/AbstractAdmin.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 0d78d1a599..7702983bb4 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -695,20 +695,20 @@ public function getDataSourceIterator() $fields = []; foreach ($this->getExportFields() as $key => $field) { - $label = $this->getTranslationLabel($field, 'export', 'label'); - - // NEXT_MAJOR: We have to find another way to have a translated label or stop deprecating the translator. - $transLabel = $this->trans($label); - // NEXT_MAJOR: Remove the following code in favor of the commented one. - // If a key is provided we use it otherwise we use the generated label. - // $fieldKey = \is_string($key) ? $key : $transLabel; - // $fields[$fieldKey] = $field; + $label = $this->getTranslationLabel($field, 'export', 'label'); + $transLabel = $this->getTranslator()->trans($label, [], $this->getTranslationDomain()); if ($transLabel === $label) { $fields[$key] = $field; } else { $fields[$transLabel] = $field; } +// if (!\is_string($key)) { +// $label = $this->getTranslationLabel($field, 'export', 'label'); +// $key = $this->getTranslator()->trans($label, [], $this->getTranslationDomain()); +// } +// +// $fields[$key] = $field; } if ($this->getDataSource()) { From ca03072f8542277a0b91d858263940614f6fbb96 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:22:31 +0100 Subject: [PATCH 03/30] Prefer usage of getter This way we can move property to another class --- src/Admin/AbstractAdmin.php | 69 +++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 37 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 7702983bb4..5f0efab979 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -741,7 +741,7 @@ public function validate(ErrorElement $errorElement, $object) } /** - * define custom variable. + * @final since sonata-admin/admin-bundle 3.x */ public function initialize() { @@ -760,6 +760,9 @@ public function initialize() $this->configure(); } + /** + * NEXT_MAJOR: Restrict visibility to protected. + */ public function configure() { } @@ -767,7 +770,7 @@ public function configure() public function update($object) { $this->preUpdate($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->preUpdate($this, $object); } @@ -778,7 +781,7 @@ public function update($object) } $this->postUpdate($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->postUpdate($this, $object); } @@ -788,7 +791,7 @@ public function update($object) public function create($object) { $this->prePersist($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->prePersist($this, $object); } @@ -799,7 +802,7 @@ public function create($object) } $this->postPersist($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->postPersist($this, $object); } @@ -811,7 +814,7 @@ public function create($object) public function delete($object) { $this->preRemove($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->preRemove($this, $object); } @@ -819,7 +822,7 @@ public function delete($object) $this->getModelManager()->delete($object); $this->postRemove($object); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->postRemove($this, $object); } } @@ -883,7 +886,7 @@ public function getFilterParameters() // build the values array if ($this->hasRequest()) { /** @var InputBag|ParameterBag $bag */ - $bag = $this->request->query; + $bag = $this->getRequest()->query; if ($bag instanceof InputBag) { // symfony 5.1+ $filters = $bag->all('filter'); @@ -919,7 +922,7 @@ public function getFilterParameters() // always force the parent value if ($this->isChild() && $this->getParentAssociationMapping()) { $name = str_replace('.', '__', $this->getParentAssociationMapping()); - $parameters[$name] = ['value' => $this->request->get($this->getParent()->getIdParameter())]; + $parameters[$name] = ['value' => $this->getRequest()->get($this->getParent()->getIdParameter())]; } } @@ -961,7 +964,7 @@ public function buildDatagrid() // initialize the datagrid $this->datagrid = $this->getDatagridBuilder()->getBaseDatagrid($this, $filterParameters); - $this->datagrid->getPager()->setMaxPageLinks($this->maxPageLinks); + $this->datagrid->getPager()->setMaxPageLinks($this->getMaxPageLinks()); $mapper = new DatagridMapper($this->getDatagridBuilder(), $this->datagrid, $this); @@ -1175,8 +1178,9 @@ public function getClass() return $this->getSubClass($subClass); } - // see https://github.com/sonata-project/SonataCoreBundle/commit/247eeb0a7ca7211142e101754769d70bc402a5b4 - if ($this->subject && \is_object($this->subject)) { + // Do not use `$this->hasSubject()` and `$this->getSubject()` here to avoid infinite loop. + // `getSubject` use `hasSubject()` which use `getObject()` which use `getClass()`. + if (null !== $this->subject) { return ClassUtils::getClass($this->subject); } @@ -1215,7 +1219,7 @@ public function hasSubClass($name) public function hasActiveSubClass() { - if (\count($this->subClasses) > 0 && $this->request) { + if (\count($this->subClasses) > 0 && $this->hasRequest()) { return null !== $this->getRequest()->query->get('subclass'); } @@ -1344,11 +1348,12 @@ public function getIdParameter() public function hasRoute($name) { + // NEXT_MAJOR: Remove this check. if (!$this->routeGenerator) { throw new \RuntimeException('RouteGenerator cannot be null'); } - return $this->routeGenerator->hasAdminRoute($this, $name); + return $this->getRouteGenerator()->hasAdminRoute($this, $name); } /** @@ -1600,7 +1605,7 @@ public function createQuery($context = 'list') $query = $this->getModelManager()->createQuery($this->getClass()); $query = $this->configureQuery($query); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { $extension->configureQuery($this, $query, $context); } @@ -1622,9 +1627,9 @@ public function buildTabMenu($action, ?AdminInterface $childAdmin = null) $this->loaded['tab_menu'] = true; - $menu = $this->menuFactory->createItem('root'); + $menu = $this->getMenuFactory()->createItem('root'); $menu->setChildrenAttribute('class', 'nav navbar-nav'); - $menu->setExtra('translation_domain', $this->translationDomain); + $menu->setExtra('translation_domain', $this->getTranslationDomain()); // Prevents BC break with KnpMenuBundle v1.x if (method_exists($menu, 'setCurrentUri')) { @@ -1953,7 +1958,7 @@ public function getSubject() public function hasSubject() { if (null === $this->subject && $this->hasRequest() && !$this->hasParentFieldDescription()) { - $id = $this->request->get($this->getIdParameter()); + $id = $this->getRequest()->get($this->getIdParameter()); if (null !== $id) { $this->subject = $this->getObject($id); @@ -2246,7 +2251,7 @@ public function getChild($code) return null; } - return $this->children[$code]; + return $this->getChildren()[$code]; } public function setParent(AdminInterface $parent) @@ -2493,7 +2498,7 @@ public function isCurrentChild(): bool */ public function getCurrentChildAdmin() { - foreach ($this->children as $child) { + foreach ($this->getChildren() as $child) { // NEXT_MAJOR: Remove method_exists check and delete elseif case if (method_exists($child, 'isCurrentChild')) { if ($child->isCurrentChild()) { @@ -2518,7 +2523,7 @@ public function trans($id, array $parameters = [], $domain = null, $locale = nul $domain = $domain ?: $this->getTranslationDomain(); - return $this->translator->trans($id, $parameters, $domain, $locale); + return $this->getTranslator()->trans($id, $parameters, $domain, $locale); } /** @@ -2544,7 +2549,7 @@ public function transChoice($id, $count, array $parameters = [], $domain = null, $domain = $domain ?: $this->getTranslationDomain(); - return $this->translator->transChoice($id, $count, $parameters, $domain, $locale); + return $this->getTranslator()->transChoice($id, $count, $parameters, $domain, $locale); } public function setTranslationDomain($translationDomain) @@ -2816,23 +2821,13 @@ public function createObjectSecurity($object) $this->getSecurityHandler()->createObjectSecurity($this, $object); } - public function setSecurityHandler(SecurityHandlerInterface $securityHandler) - { - $this->securityHandler = $securityHandler; - } - - public function getSecurityHandler() - { - return $this->securityHandler; - } - public function isGranted($name, $object = null) { $objectRef = $object ? sprintf('/%s#%s', spl_object_hash($object), $this->id($object)) : ''; $key = md5(json_encode($name).$objectRef); if (!\array_key_exists($key, $this->cacheIsGranted)) { - $this->cacheIsGranted[$key] = $this->securityHandler->isGranted($this, $name, $object ?: $this); + $this->cacheIsGranted[$key] = $this->getSecurityHandler()->isGranted($this, $name, $object ?: $this); } return $this->cacheIsGranted[$key]; @@ -3698,7 +3693,7 @@ protected function getAccess() 'list' => 'LIST', ], $this->getAccessMapping()); - foreach ($this->extensions as $extension) { + foreach ($this->getExtensions() as $extension) { // NEXT_MAJOR: remove method check if (method_exists($extension, 'getAccessMapping')) { $access = array_merge($access, $extension->getAccessMapping($this)); @@ -3739,7 +3734,7 @@ final protected function appendParentObject(object $object): void { if ($this->isChild() && $this->getParentAssociationMapping()) { $parentAdmin = $this->getParent(); - $parentObject = $parentAdmin->getObject($this->request->get($parentAdmin->getIdParameter())); + $parentObject = $parentAdmin->getObject($this->getRequest()->get($parentAdmin->getIdParameter())); if (null !== $parentObject) { $propertyAccessor = PropertyAccess::createPropertyAccessor(); @@ -3756,7 +3751,7 @@ final protected function appendParentObject(object $object): void } } elseif ($this->hasParentFieldDescription()) { $parentAdmin = $this->getParentFieldDescription()->getAdmin(); - $parentObject = $parentAdmin->getObject($this->request->get($parentAdmin->getIdParameter())); + $parentObject = $parentAdmin->getObject($this->getRequest()->get($parentAdmin->getIdParameter())); if (null !== $parentObject) { ObjectManipulator::setObject($object, $parentObject, $this->getParentFieldDescription()); @@ -3782,7 +3777,7 @@ private function buildRoutes(): void $this->getBaseControllerName() ); - $this->routeBuilder->build($this, $this->routes); + $this->getRouteBuilder()->build($this, $this->routes); $this->configureRoutes($this->routes); From 36bd24553723f9d11c7175403c1833af3ebc444c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:23:21 +0100 Subject: [PATCH 04/30] Improve AddDependencyCallsCompilerPass --- .../AddDependencyCallsCompilerPass.php | 52 ++++++------------- 1 file changed, 17 insertions(+), 35 deletions(-) diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 2c4f025bfe..cc1d8f653e 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -233,7 +233,7 @@ public function applyConfigurationFromAttribute(Definition $definition, array $a 'translator', 'configuration_pool', 'router', - 'validator', //NEXT_MAJOR: Remove this line + 'validator', // NEXT_MAJOR: Remove this line 'security_handler', 'menu_factory', 'route_builder', @@ -281,7 +281,12 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at 'translator' => 'translator', 'configuration_pool' => 'sonata.admin.pool', 'route_generator' => 'sonata.admin.route.default_generator', +<<<<<<< HEAD 'validator' => 'validator', //NEXT_MAJOR: Remove this line +======= + // NEXT_MAJOR: Remove this line. + 'validator' => 'validator', +>>>>>>> e3f653f61... Improve AddDependencyCallsCompilerPass 'security_handler' => 'sonata.admin.security.handler', 'menu_factory' => 'knp_menu.factory', 'route_builder' => 'sonata.admin.route.path_info'. @@ -309,49 +314,26 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at } } - if (isset($overwriteAdminConfiguration['pager_type'])) { - $pagerType = $overwriteAdminConfiguration['pager_type']; - } elseif (isset($attributes['pager_type'])) { - $pagerType = $attributes['pager_type']; - } else { - $pagerType = Pager::TYPE_DEFAULT; - } - + $pagerType = $overwriteAdminConfiguration['pager_type'] ?? $attributes['pager_type'] ?? Pager::TYPE_DEFAULT; $definition->addMethodCall('setPagerType', [$pagerType]); - if (isset($overwriteAdminConfiguration['label'])) { - $label = $overwriteAdminConfiguration['label']; - } elseif (isset($attributes['label'])) { - $label = $attributes['label']; - } else { - $label = '-'; - } - + // NEXT_MAJOR: Default to null + $label = $overwriteAdminConfiguration['label'] ?? $attributes['label'] ?? '-'; $definition->addMethodCall('setLabel', [$label]); - $persistFilters = $container->getParameter('sonata.admin.configuration.filters.persist'); - // override default configuration with admin config if set - if (isset($attributes['persist_filters'])) { - $persistFilters = $attributes['persist_filters']; - } - $filtersPersister = $container->getParameter('sonata.admin.configuration.filters.persister'); - // override default configuration with admin config if set - if (isset($attributes['filter_persister'])) { - $filtersPersister = $attributes['filter_persister']; - } + $persistFilters = $attributes['persist_filters'] + ?? $container->getParameter('sonata.admin.configuration.filters.persist'); + $filtersPersister = $attributes['filter_persister'] + ?? $container->getParameter('sonata.admin.configuration.filters.persister'); + // configure filters persistence, if configured to if ($persistFilters) { $definition->addMethodCall('setFilterPersister', [new Reference($filtersPersister)]); } - if (isset($overwriteAdminConfiguration['show_mosaic_button'])) { - $showMosaicButton = $overwriteAdminConfiguration['show_mosaic_button']; - } elseif (isset($attributes['show_mosaic_button'])) { - $showMosaicButton = $attributes['show_mosaic_button']; - } else { - $showMosaicButton = $container->getParameter('sonata.admin.configuration.show.mosaic.button'); - } - + $showMosaicButton = $overwriteAdminConfiguration['show_mosaic_button'] + ?? $attributes['show_mosaic_button'] + ?? $container->getParameter('sonata.admin.configuration.show.mosaic.button'); $definition->addMethodCall('showMosaicButton', [$showMosaicButton]); $this->fixTemplates( From 18dfcc41a1d77d8ba337120a611198a5d5de77e1 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:24:13 +0100 Subject: [PATCH 05/30] Introduce AdminTag class and interface --- src/Admin/AbstractAdminTag.php | 753 ++++++++++++++++++ src/Admin/AdminTagInterface.php | 283 +++++++ .../AddDependencyCallsCompilerPass.php | 3 +- 3 files changed, 1038 insertions(+), 1 deletion(-) create mode 100644 src/Admin/AbstractAdminTag.php create mode 100644 src/Admin/AdminTagInterface.php diff --git a/src/Admin/AbstractAdminTag.php b/src/Admin/AbstractAdminTag.php new file mode 100644 index 0000000000..3667b83add --- /dev/null +++ b/src/Admin/AbstractAdminTag.php @@ -0,0 +1,753 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Admin; + +use Knp\Menu\FactoryInterface; +use Sonata\AdminBundle\Builder\DatagridBuilderInterface; +use Sonata\AdminBundle\Builder\FormContractorInterface; +use Sonata\AdminBundle\Builder\ListBuilderInterface; +use Sonata\AdminBundle\Builder\RouteBuilderInterface; +use Sonata\AdminBundle\Builder\ShowBuilderInterface; +use Sonata\AdminBundle\Datagrid\Pager; +use Sonata\AdminBundle\Exporter\DataSourceInterface; +use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface; +use Sonata\AdminBundle\Model\ModelManagerInterface; +use Sonata\AdminBundle\Route\RouteGeneratorInterface; +use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface; +use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Validator\Validator\ValidatorInterface; + +/** + * @phpstan-template T of object + * @phpstan-implements AdminTagInterface + */ +abstract class AbstractAdminTag implements AdminTagInterface +{ + public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; + + /** + * The code related to the admin. + * + * @var string + */ + protected $code; + + /** + * The class name managed by the admin class. + * + * @var string + * + * @phpstan-var class-string + */ + protected $class; + + /** + * The base name controller used to generate the routing information. + * + * @var string + */ + protected $baseControllerName; + + /** + * @var string|null + */ + protected $label; + + /** + * @var array> + */ + protected $listModes = [ + 'list' => ['class' => 'fa fa-list fa-fw'], + 'mosaic' => ['class' => self::MOSAIC_ICON_CLASS], + ]; + + /** + * @var string + */ + protected $pagerType = Pager::TYPE_DEFAULT; + + /** + * The manager type to use for the admin. + * + * @var string|null + */ + protected $managerType; + + /** + * Roles and permissions per role. + * + * @var array 'role' => ['permission1', 'permission2'] + */ + protected $securityInformation = []; + + /** + * Whether or not to persist the filters in the session. + * + * NEXT_MAJOR: remove this property + * + * @var bool + * + * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. + */ + protected $persistFilters = false; + + /** + * Component responsible for persisting filters. + * + * @var FilterPersisterInterface|null + */ + protected $filterPersister; + + /** + * The Entity or Document manager. + * + * @var ModelManagerInterface|null + */ + protected $modelManager; + + /** + * @var DataSourceInterface|null + */ + protected $dataSource; + + /** + * The related form contractor. + * + * @var FormContractorInterface|null + */ + protected $formContractor; + + /** + * The related view builder. + * + * @var ShowBuilderInterface|null + */ + protected $showBuilder; + + /** + * The related list builder. + * + * @var ListBuilderInterface|null + */ + protected $listBuilder; + + /** + * The related datagrid builder. + * + * @var DatagridBuilderInterface|null + */ + protected $datagridBuilder; + + /** + * The translator component. + * + * @var TranslatorInterface|null + */ + protected $translator; + + /** + * The configuration pool. + * + * @var Pool|null + */ + protected $configurationPool; + + /** + * The router instance. + * + * @var RouteGeneratorInterface|null + */ + protected $routeGenerator; + + /** + * @var ValidatorInterface|null + */ + protected $validator; + + /** + * @var SecurityHandlerInterface|null + */ + protected $securityHandler; + + /** + * @var FactoryInterface|null + */ + protected $menuFactory; + + /** + * @var RouteBuilderInterface|null + */ + protected $routeBuilder; + + /** + * @var LabelTranslatorStrategyInterface|null + */ + protected $labelTranslatorStrategy; + + /** + * NEXT_MAJOR: Change signature to __construct(string $code, string $class, string $baseControllerName). + */ + public function __construct($code, $class, $baseControllerName = null) + { + if (!\is_string($code)) { + @trigger_error(sprintf( + '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.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->code = $code; + + if (!\is_string($class)) { + @trigger_error(sprintf( + '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.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->class = $class; + + if (!\is_string($baseControllerName)) { + @trigger_error(sprintf( + 'Passing other type than string as argument 3 for method %s() is deprecated since' + .' sonata-project/admin-bundle 3.x. It will accept only string in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->baseControllerName = $baseControllerName; + } + + abstract public function initialize(); + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setLabel($label) + { + $this->label = $label; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getLabel() + { + return $this->label; + } + + final public function showMosaicButton($isShown) + { + if ($isShown) { + $this->listModes['mosaic'] = ['class' => static::MOSAIC_ICON_CLASS]; + } else { + unset($this->listModes['mosaic']); + } + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setPagerType($pagerType) + { + $this->pagerType = $pagerType; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + * + * @return string + */ + public function getPagerType() + { + return $this->pagerType; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setManagerType($type) + { + $this->managerType = $type; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getManagerType() + { + if (null === $this->managerType) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no manager type is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no manager type.', +// static::class +// )); + } + + return $this->managerType; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setSecurityInformation(array $information) + { + $this->securityInformation = $information; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getSecurityInformation() + { + return $this->securityInformation; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setFilterPersister(?FilterPersisterInterface $filterPersister = null) + { + $this->filterPersister = $filterPersister; + // NEXT_MAJOR remove the deprecated property will be removed. Needed for persisted filter condition. + $this->persistFilters = true; + } + + final public function getFilterPersister(): FilterPersisterInterface + { + if (!$this->hasFilterPersister()) { + throw new \LogicException(sprintf('Admin "%s" has no filter persister.', static::class)); + } + + return $this->filterPersister; + } + + final public function hasFilterPersister(): bool + { + return null !== $this->filterPersister; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setModelManager(ModelManagerInterface $modelManager) + { + $this->modelManager = $modelManager; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getModelManager() + { + if (null === $this->modelManager) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no model manager is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no model manager.', +// static::class +// )); + } + + return $this->modelManager; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setDataSource(DataSourceInterface $dataSource) + { + $this->dataSource = $dataSource; + } + + /** + * NEXT_MAJOR: Change typehint for DataSourceInterface. + */ + public function getDataSource(): ?DataSourceInterface + { + if (null === $this->dataSource) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no data source is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no data source.', +// static::class +// )); + } + + return $this->dataSource; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setFormContractor(FormContractorInterface $formBuilder) + { + $this->formContractor = $formBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getFormContractor() + { + if (null === $this->formContractor) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no form contractor is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no form contractor.', +// static::class +// )); + } + + return $this->formContractor; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setShowBuilder(ShowBuilderInterface $showBuilder) + { + $this->showBuilder = $showBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getShowBuilder() + { + if (null === $this->showBuilder) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no show builder is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no show builder.', +// static::class +// )); + } + + return $this->showBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setListBuilder(ListBuilderInterface $listBuilder) + { + $this->listBuilder = $listBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getListBuilder() + { + if (null === $this->listBuilder) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no list build is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no list builder.', +// static::class +// )); + } + + return $this->listBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) + { + $this->datagridBuilder = $datagridBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getDatagridBuilder() + { + if (null === $this->datagridBuilder) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no datagrid builder is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no datagrid builder.', +// static::class +// )); + } + + return $this->datagridBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setTranslator(TranslatorInterface $translator) + { + $this->translator = $translator; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getTranslator() + { + if (null === $this->translator) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no translator is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no translator.', +// static::class +// )); + } + + return $this->translator; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setConfigurationPool(Pool $configurationPool) + { + $this->configurationPool = $configurationPool; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getConfigurationPool() + { + if (null === $this->configurationPool) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { + @trigger_error(sprintf( + 'Calling %s() when no pool is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); + } +// throw new \LogicException(sprintf( +// 'Admin "%s" has no pool.', +// static::class +// )); + } + + return $this->configurationPool; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) + { + $this->routeGenerator = $routeGenerator; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getRouteGenerator() + { + if (null === $this->routeGenerator) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no route generator is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no route generator.', +// static::class +// )); + } + + return $this->routeGenerator; + } + + /** + * NEXT_MAJOR: Remove this method. + */ + public function setValidator($validator) + { + // NEXT_MAJOR: Move ValidatorInterface check to method signature + if (!$validator instanceof ValidatorInterface) { + throw new \InvalidArgumentException(sprintf( + 'Argument 1 must be an instance of %s', + ValidatorInterface::class + )); + } + + $this->validator = $validator; + } + + /** + * NEXT_MAJOR: Remove this method. + */ + public function getValidator() + { + @trigger_error(sprintf( + 'Calling %s() is deprecated since sonata-project/admin-bundle 3.x.', + __METHOD__, + ), E_USER_DEPRECATED); + + return $this->validator; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setSecurityHandler(SecurityHandlerInterface $securityHandler) + { + $this->securityHandler = $securityHandler; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getSecurityHandler() + { + if (null === $this->securityHandler) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no security handler.', +// static::class +// )); + } + + return $this->securityHandler; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setMenuFactory(FactoryInterface $menuFactory) + { + $this->menuFactory = $menuFactory; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getMenuFactory() + { + if (null === $this->menuFactory) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no security handler.', +// static::class +// )); + } + + return $this->menuFactory; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setRouteBuilder(RouteBuilderInterface $routeBuilder) + { + $this->routeBuilder = $routeBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getRouteBuilder() + { + if (null === $this->routeBuilder) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no route builder is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no route builder.', +// static::class +// )); + } + + return $this->routeBuilder; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy) + { + $this->labelTranslatorStrategy = $labelTranslatorStrategy; + } + + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getLabelTranslatorStrategy() + { + if (null === $this->labelTranslatorStrategy) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no label translator strategy is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no label translator strategy.', +// static::class +// )); + } + + return $this->labelTranslatorStrategy; + } +} diff --git a/src/Admin/AdminTagInterface.php b/src/Admin/AdminTagInterface.php new file mode 100644 index 0000000000..ebba728292 --- /dev/null +++ b/src/Admin/AdminTagInterface.php @@ -0,0 +1,283 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Admin; + +use Knp\Menu\FactoryInterface; +use Sonata\AdminBundle\Builder\DatagridBuilderInterface; +use Sonata\AdminBundle\Builder\FormContractorInterface; +use Sonata\AdminBundle\Builder\ListBuilderInterface; +use Sonata\AdminBundle\Builder\RouteBuilderInterface; +use Sonata\AdminBundle\Builder\ShowBuilderInterface; +use Sonata\AdminBundle\Exporter\DataSourceInterface; +use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface; +use Sonata\AdminBundle\Model\ModelManagerInterface; +use Sonata\AdminBundle\Route\RouteGeneratorInterface; +use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface; +use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; +use Symfony\Component\Translation\TranslatorInterface; +use Symfony\Component\Validator\Validator\ValidatorInterface; + +/** + * This interface should be implemented to work with the AddDependencyCallsCompilerPass. + * All the setter are called by this compiler pass. + * + * @phpstan-template T of object + * + * @method void __construct(string $code, string $class, string $controller) + * @method void initialize() + * @method void setLabel(?string $label) + * @method void showMosaicButton(bool $isShown) + * @method void setPagerType(string $pagerType) + * @method string getPagerType() + * @method void setManagerType(string $managerType) + * @method void setSecurityInformation(array $information) + * @method void setFilterPersister(?FilterPersisterInterface $filterPersister = null) + * @method FilterPersisterInterface|null getFilterPersister() + * @method bool hasFilterPersister() + * @method void setModelManager(ModelManagerInterface $modelManager) + * @method void setDataSource(DataSourceInterface $dataSource) + * @method DataSourceInterface getDataSource() + * @method FormContractorInterface getFormContractor() + * @method void setShowBuilder(ShowBuilderInterface $showBuilder) + * @method ShowBuilderInterface getShowBuilder() + * @method Pool getConfigurationPool() + * @method void setRouteGenerator(RouteGeneratorInterface $routeGenerator) + * @method RouteGeneratorInterface getRouteGenerator() + */ +interface AdminTagInterface +{ + public const ADMIN_TAG = 'sonata.admin'; + + /** + * NEXT_MAJOR: Uncomment this method. + * + * The first and third argument are automatically injected by the AddDependencyCallsCompilerPass. + * + * @phpstan-param class-string $class + */ +// public function __construct(string $code, string $class, string $controller); + + /** + * NEXT_MAJOR: Uncomment this method. + * + * Define custom variable. + */ +// public function initialize(): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setLabel(?string $label): void; + + /** + * @return string|null + */ + public function getLabel(); + + /** + * NEXT_MAJOR: Uncomment this method. + * + * Enable/Disable mosaic button for the admin screen. + */ +// public function showMosaicButton(bool $isShown): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setPagerType(string $pagerType): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getPagerType(): string; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setManagerType(string $managerType): void; + + /** + * @return string + */ + public function getManagerType(); + + /** + * NEXT_MAJOR: Uncomment this method. + * + * Set the roles and permissions per role. + */ +// public function setSecurityInformation(array $information): void; + + /** + * Return the roles and permissions per role + * - different permissions per role for the acl handler + * - one permission that has the same name as the role for the role handler + * This should be used by experimented users. + * + * @return array 'role' => ['permission', 'permission'] + */ + public function getSecurityInformation(); + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setFilterPersister(?FilterPersisterInterface $filterPersister = null): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getFilterPersister(): ?FilterPersisterInterface; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function hasFilterPersister(): bool; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setModelManager(ModelManagerInterface $modelManager): void; + + /** + * @return ModelManagerInterface + */ + public function getModelManager(); + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setDataSource(DataSourceInterface $dataSource): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getDataSource(): DataSourceInterface; + + /** + * @return void + */ + public function setFormContractor(FormContractorInterface $formContractor); + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getFormContractor(): FormContractorInterface; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setShowBuilder(ShowBuilderInterface $showBuilder): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getShowBuilder(): ShowBuilderInterface; + + /** + * @return void + */ + public function setListBuilder(ListBuilderInterface $listBuilder); + + /** + * @return ListBuilderInterface + */ + public function getListBuilder(); + + /** + * @return void + */ + public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder); + + /** + * @return DatagridBuilderInterface + */ + public function getDatagridBuilder(); + + /** + * @return void + */ + public function setTranslator(TranslatorInterface $translator); + + /** + * @return TranslatorInterface + */ + public function getTranslator(); + + /** + * @return void + */ + public function setConfigurationPool(Pool $pool); + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getConfigurationPool(): Pool; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function setRouteGenerator(RouteGeneratorInterface $routeGenerator): void; + + /** + * NEXT_MAJOR: Uncomment this method. + */ +// public function getRouteGenerator(): RouteGeneratorInterface; + + /** + * NEXT_MAJOR: Remove this method. + * + * @return ValidatorInterface + */ + public function getValidator(); + + /** + * @return void + */ + public function setSecurityHandler(SecurityHandlerInterface $securityHandler); + + /** + * @return SecurityHandlerInterface + */ + public function getSecurityHandler(); + + /** + * @return void + */ + public function setMenuFactory(FactoryInterface $menuFactory); + + /** + * @return FactoryInterface + */ + public function getMenuFactory(); + + /** + * @return void + */ + public function setRouteBuilder(RouteBuilderInterface $routeBuilder); + + /** + * @return RouteBuilderInterface + */ + public function getRouteBuilder(); + + /** + * @return void + */ + public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy); + + /** + * @return LabelTranslatorStrategyInterface + */ + public function getLabelTranslatorStrategy(); +} diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index cc1d8f653e..5baa7c750d 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -14,6 +14,7 @@ namespace Sonata\AdminBundle\DependencyInjection\Compiler; use Doctrine\Inflector\InflectorFactory; +use Sonata\AdminBundle\Admin\AdminTagInterface; use Sonata\AdminBundle\Controller\CRUDController; use Sonata\AdminBundle\Datagrid\Pager; use Sonata\AdminBundle\Templating\TemplateRegistry; @@ -56,7 +57,7 @@ public function process(ContainerBuilder $container) 'icon' => $container->getParameter('sonata.admin.configuration.default_icon'), ]; - foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $tags) { + foreach ($container->findTaggedServiceIds(AdminTagInterface::ADMIN_TAG) as $id => $tags) { foreach ($tags as $attributes) { $definition = $container->getDefinition($id); $parentDefinition = null; From 1578ead71b6fd24efe60e78d640a9ad14796919c Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:25:10 +0100 Subject: [PATCH 06/30] Backport bugfix from master --- src/Mapper/BaseGroupedMapper.php | 14 ++++++++++---- tests/Form/FormMapperTest.php | 2 ++ tests/Show/ShowMapperTest.php | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Mapper/BaseGroupedMapper.php b/src/Mapper/BaseGroupedMapper.php index 1e9d3fcf6d..dc3c5f3d51 100644 --- a/src/Mapper/BaseGroupedMapper.php +++ b/src/Mapper/BaseGroupedMapper.php @@ -329,10 +329,16 @@ protected function addFieldToCurrentGroup($fieldName) protected function getCurrentGroupName() { if (!$this->currentGroup) { - $this->with($this->admin->getLabel(), [ - 'auto_created' => true, - 'translation_domain' => $this->admin->getTranslationDomain(), - ]); + $label = $this->admin->getLabel(); + + if (null === $label) { + $this->with('default', ['auto_created' => true]); + } else { + $this->with($label, [ + 'auto_created' => true, + 'translation_domain' => $this->admin->getTranslationDomain(), + ]); + } } return $this->currentGroup; diff --git a/tests/Form/FormMapperTest.php b/tests/Form/FormMapperTest.php index 4c47c8537a..1094470314 100644 --- a/tests/Form/FormMapperTest.php +++ b/tests/Form/FormMapperTest.php @@ -534,6 +534,8 @@ public function testAddOptionRole(): void $this->assertTrue($this->formMapper->has('bar')); $this->assertFalse($this->formMapper->has('quux')); + $this->formMapper->end(); // Close default + $this->formMapper ->with('qux') ->add('foobar', 'bar', [], ['role' => self::DEFAULT_GRANTED_ROLE]) diff --git a/tests/Show/ShowMapperTest.php b/tests/Show/ShowMapperTest.php index cffbf599a0..333b82825f 100644 --- a/tests/Show/ShowMapperTest.php +++ b/tests/Show/ShowMapperTest.php @@ -533,6 +533,8 @@ public function testAddOptionRole(): void $this->assertTrue($this->showMapper->has('bar')); $this->assertFalse($this->showMapper->has('quux')); + $this->showMapper->end(); // Close default + $this->showMapper ->with('qux') ->add('foobar', 'bar', ['role' => self::DEFAULT_GRANTED_ROLE]) From 61caba0486c0e011b922b6e8d1da63d4ccb0c2b1 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:26:16 +0100 Subject: [PATCH 07/30] Avoid to translate an empty admin label --- .../views/Block/block_admin_list.html.twig | 26 ++++++++++--------- .../views/Block/block_search_result.html.twig | 4 ++- .../Association/edit_many_script.html.twig | 13 +++++++--- src/Resources/views/Core/add_block.html.twig | 10 +++++-- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/Resources/views/Block/block_admin_list.html.twig b/src/Resources/views/Block/block_admin_list.html.twig index f10ed521f1..2f32221724 100644 --- a/src/Resources/views/Block/block_admin_list.html.twig +++ b/src/Resources/views/Block/block_admin_list.html.twig @@ -25,18 +25,20 @@ file that was distributed with this source code. {% for admin in group.items %} {% if admin.dashboardActions|length > 0 %} - - - {{ admin.label|trans({}, admin.translationdomain) }} - - -
    - {% for action in admin.dashboardActions %} - {% include action.template|default('@SonataAdmin/CRUD/dashboard__action.html.twig') with {'action': action} %} - {% endfor %} -
    - - + + + {% if admin.label is not empty %} + {{ admin.label|trans({}, admin.translationdomain) }} + {% endif %} + + +
    + {% for action in admin.dashboardActions %} + {% include action.template|default('@SonataAdmin/CRUD/dashboard__action.html.twig') with {'action': action} %} + {% endfor %} +
    + + {% endif %} {% endfor %} diff --git a/src/Resources/views/Block/block_search_result.html.twig b/src/Resources/views/Block/block_search_result.html.twig index a80b3f9899..ce82728b36 100644 --- a/src/Resources/views/Block/block_search_result.html.twig +++ b/src/Resources/views/Block/block_search_result.html.twig @@ -25,7 +25,9 @@ file that was distributed with this source code. {% set icon = settings.icon|default('') %} {{ icon|raw }}

    - {{ admin.label|trans({}, admin.translationdomain) }} + {% if admin.label is not empty %} + {{ admin.label|trans({}, admin.translationdomain) }} + {% endif %}

    diff --git a/src/Resources/views/CRUD/Association/edit_many_script.html.twig b/src/Resources/views/CRUD/Association/edit_many_script.html.twig index aa8bf065a9..b33525ae05 100644 --- a/src/Resources/views/CRUD/Association/edit_many_script.html.twig +++ b/src/Resources/views/CRUD/Association/edit_many_script.html.twig @@ -131,8 +131,9 @@ This code manages the many-to-[one|many] association field popup // populate the popup container field_dialog_content_{{ id }}.html(html); - - field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% if admin.label is not empty %} + field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% endif %} Admin.shared_setup(field_dialog_{{ id }}); @@ -169,7 +170,9 @@ This code manages the many-to-[one|many] association field popup // populate the popup container field_dialog_content_{{ id }}.html(html); - field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% if admin.label is not empty %} + field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% endif %} Admin.shared_setup(field_dialog_{{ id }}); @@ -209,7 +212,9 @@ This code manages the many-to-[one|many] association field popup // populate the popup container field_dialog_content_{{ id }}.html(html); - field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% if admin.label is not empty %} + field_dialog_title_{{ id }}.html("{{ associationadmin.label|trans({}, associationadmin.translationdomain) }}"); + {% endif %} Admin.shared_setup(field_dialog_{{ id }}); diff --git a/src/Resources/views/Core/add_block.html.twig b/src/Resources/views/Core/add_block.html.twig index 27f9b80cfa..4477e6999c 100644 --- a/src/Resources/views/Core/add_block.html.twig +++ b/src/Resources/views/Core/add_block.html.twig @@ -38,12 +38,18 @@ {% if admin.hasRoute('create') and admin.hasAccess('create') %} {% if admin.subClasses is empty %}
  • - {{ admin.label|trans({}, admin.translationdomain) }} + + {% if admin.label is not empty %} + {{ admin.label|trans({}, admin.translationdomain) }} + {% endif %} +
  • {% else %} {% for subclass in admin.subclasses|keys %}
  • - {{ subclass|trans({}, admin.translationdomain) }} + + {{ subclass|trans({}, admin.translationdomain) }} +
  • {% endfor %} {% endif %} From 3984b809a7e70526dcf511653996a951ec2f828d Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:26:58 +0100 Subject: [PATCH 08/30] Prevent passing a null label to createItem This method requires a string --- src/Menu/Provider/GroupMenuProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Menu/Provider/GroupMenuProvider.php b/src/Menu/Provider/GroupMenuProvider.php index 16b71780a7..02ff38067e 100644 --- a/src/Menu/Provider/GroupMenuProvider.php +++ b/src/Menu/Provider/GroupMenuProvider.php @@ -179,7 +179,7 @@ private function generateMenuItem(array $item, array $group): ItemInterface 'admin' => $admin, ]; - return $this->menuFactory->createItem($admin->getLabel(), $options); + return $this->menuFactory->createItem($admin->getLabel() ?? '', $options); } return $this->menuFactory->createItem($item['label'], [ From ec8087005a331d5d45cef786625fa5b3d7911ac8 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:28:28 +0100 Subject: [PATCH 09/30] Split AbstractAdmin in order to use AbstractAdminTag --- src/Admin/AbstractAdmin.php | 546 ++------------------------------ src/Admin/AbstractAdminTag.php | 16 +- src/Admin/AdminInterface.php | 184 +---------- src/Admin/AdminTagInterface.php | 13 + 4 files changed, 71 insertions(+), 688 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 5f0efab979..6716b045fd 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -14,32 +14,20 @@ namespace Sonata\AdminBundle\Admin; use Doctrine\Common\Util\ClassUtils; -use Knp\Menu\FactoryInterface; use Knp\Menu\ItemInterface; -use Sonata\AdminBundle\Builder\DatagridBuilderInterface; -use Sonata\AdminBundle\Builder\FormContractorInterface; -use Sonata\AdminBundle\Builder\ListBuilderInterface; -use Sonata\AdminBundle\Builder\RouteBuilderInterface; -use Sonata\AdminBundle\Builder\ShowBuilderInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; -use Sonata\AdminBundle\Datagrid\Pager; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Exporter\DataSourceInterface; -use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\Type\ModelHiddenType; use Sonata\AdminBundle\Manipulator\ObjectManipulator; -use Sonata\AdminBundle\Model\ModelManagerInterface; use Sonata\AdminBundle\Object\Metadata; use Sonata\AdminBundle\Route\RouteCollection; -use Sonata\AdminBundle\Route\RouteGeneratorInterface; use Sonata\AdminBundle\Security\Handler\AclSecurityHandlerInterface; -use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface; use Sonata\AdminBundle\Show\ShowMapper; use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; -use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; use Sonata\Form\Validator\Constraints\InlineConstraint; use Sonata\Form\Validator\ErrorElement; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -55,17 +43,16 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface as RoutingUrlGeneratorInterface; use Symfony\Component\Security\Acl\Model\DomainObjectInterface; use Symfony\Component\Security\Core\Exception\AccessDeniedException; -use Symfony\Component\Translation\TranslatorInterface; use Symfony\Component\Validator\Mapping\GenericMetadata; -use Symfony\Component\Validator\Validator\ValidatorInterface; /** * @author Thomas Rabaix * * @phpstan-template T of object + * @phpstan-extends AbstractAdminTag * @phpstan-implements AdminInterface */ -abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface +abstract class AbstractAdmin extends AbstractAdminTag implements AdminInterface, DomainObjectInterface, AdminTreeInterface { public const CONTEXT_MENU = 'menu'; public const CONTEXT_DASHBOARD = 'dashboard'; @@ -80,8 +67,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A Doctrine\\\Orm|Doctrine\\\Phpcr|Doctrine\\\MongoDB|Doctrine\\\CouchDB )\\\(.*)@x'; - public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; - /** * The list FieldDescription constructed from the configureListField method. * @@ -131,28 +116,21 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A /** * The base route name used to generate the routing information. * - * @var string + * @var string|null */ protected $baseRouteName; /** * The base route pattern used to generate the routing information. * - * @var string + * @var string|null */ protected $baseRoutePattern; - /** - * The base name controller used to generate the routing information. - * - * @var string - */ - protected $baseControllerName; - /** * The label class name (used in the title/breadcrumb ...). * - * @var string + * @var string|null */ protected $classnameLabel; @@ -195,42 +173,10 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $perPageOptions = [16, 32, 64, 128, 256]; - /** - * Pager type. - * - * @var string - */ - protected $pagerType = Pager::TYPE_DEFAULT; - - /** - * The code related to the admin. - * - * @var string - */ - protected $code; - - /** - * The label. - * - * @var string - */ - protected $label; - - /** - * Whether or not to persist the filters in the session. - * - * NEXT_MAJOR: remove this property - * - * @var bool - * - * @deprecated since sonata-project/admin-bundle 3.34, to be removed in 4.0. - */ - protected $persistFilters = false; - /** * Array of routes related to this admin. * - * @var RouteCollection + * @var RouteCollection|null */ protected $routes; @@ -279,7 +225,7 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A * Reference the parent FieldDescription related to this admin * only set for FieldDescription which is associated to an Sub Admin instance. * - * @var FieldDescriptionInterface + * @var FieldDescriptionInterface|null */ protected $parentFieldDescription; @@ -294,24 +240,10 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A * The uniqid is used to avoid clashing with 2 admin related to the code * ie: a Block linked to a Block. * - * @var string + * @var string|null */ protected $uniqid; - /** - * The Entity or Document manager. - * - * @var ModelManagerInterface - */ - protected $modelManager; - - /** - * NEXT_MAJOR: Restrict to DataSourceInterface. - * - * @var DataSourceInterface|null - */ - protected $dataSource; - /** * The current request object. * @@ -319,50 +251,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $request; - /** - * The translator component. - * - * NEXT_MAJOR: remove this property - * - * @var \Symfony\Component\Translation\TranslatorInterface - * - * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 - */ - protected $translator; - - /** - * The related form contractor. - * - * @var FormContractorInterface - */ - protected $formContractor; - - /** - * The related list builder. - * - * @var ListBuilderInterface - */ - protected $listBuilder; - - /** - * The related view builder. - * - * @var ShowBuilderInterface - */ - protected $showBuilder; - - /** - * The related datagrid builder. - * - * @var DatagridBuilderInterface - */ - protected $datagridBuilder; - - /** - * @var RouteBuilderInterface - */ - protected $routeBuilder; - /** * The datagrid instance. * @@ -370,13 +258,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $datagrid; - /** - * The router instance. - * - * @var RouteGeneratorInterface|null - */ - protected $routeGenerator; - /** * The generated breadcrumbs. * @@ -387,36 +268,10 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A protected $breadcrumbs = []; /** - * @var SecurityHandlerInterface - */ - protected $securityHandler; - - /** - * NEXT_MAJOR: Remove this property. - * - * @var ValidatorInterface - * - * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 - */ - protected $validator; - - /** - * The configuration pool. - * - * @var Pool - */ - protected $configurationPool; - - /** - * @var ItemInterface + * @var ItemInterface|null */ protected $menu; - /** - * @var FactoryInterface - */ - protected $menuFactory; - /** * @var array */ @@ -453,11 +308,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $extensions = []; - /** - * @var LabelTranslatorStrategyInterface - */ - protected $labelTranslatorStrategy; - /** * Setting to true will enable preview mode for * the entity and show a preview button in the @@ -467,13 +317,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $supportsPreviewMode = false; - /** - * Roles and permissions per role. - * - * @var array 'role' => ['permission', 'permission'] - */ - protected $securityInformation = []; - /** * @var array */ @@ -486,18 +329,6 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ protected $searchResultActions = ['edit', 'show']; - /** - * @var array> - */ - protected $listModes = [ - 'list' => [ - 'class' => 'fa fa-list fa-fw', - ], - 'mosaic' => [ - 'class' => self::MOSAIC_ICON_CLASS, - ], - ]; - /** * The Access mapping. * @@ -506,19 +337,10 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A protected $accessMapping = []; /** - * @var MutableTemplateRegistryInterface + * @var MutableTemplateRegistryInterface|null */ private $templateRegistry; - /** - * The class name managed by the admin class. - * - * @var string - * - * @phpstan-var class-string - */ - private $class; - /** * The subclasses supported by the admin class. * @@ -546,14 +368,14 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A /** * The cached base route name. * - * @var string + * @var string|null */ private $cachedBaseRouteName; /** * The cached base route pattern. * - * @var string + * @var string|null */ private $cachedBaseRoutePattern; @@ -597,60 +419,21 @@ abstract class AbstractAdmin implements AdminInterface, DomainObjectInterface, A */ private $showTabs = false; - /** - * The manager type to use for the admin. - * - * @var string - */ - private $managerType; - /** * The breadcrumbsBuilder component. * - * @var BreadcrumbsBuilderInterface + * @var BreadcrumbsBuilderInterface|null */ private $breadcrumbsBuilder; /** - * Component responsible for persisting filters. - * - * @var FilterPersisterInterface|null - */ - private $filterPersister; - - /** - * @param string $code - * @param string $class - * @param string|null $baseControllerName + * NEXT_MAJOR: Remove the construct override. * * @phpstan-param class-string $class */ public function __construct($code, $class, $baseControllerName = null) { - if (!\is_string($code)) { - @trigger_error(sprintf( - '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.', - __METHOD__ - ), E_USER_DEPRECATED); - } - $this->code = $code; - if (!\is_string($class)) { - @trigger_error(sprintf( - '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.', - __METHOD__ - ), E_USER_DEPRECATED); - } - $this->class = $class; - if (null !== $baseControllerName && !\is_string($baseControllerName)) { - @trigger_error(sprintf( - '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.', - __METHOD__ - ), E_USER_DEPRECATED); - } - $this->baseControllerName = $baseControllerName; + parent::__construct($code, $class, $baseControllerName); // NEXT_MAJOR: Remove this line. $this->predefinePerPageOptions(); @@ -902,18 +685,18 @@ public function getFilterParameters() // if filter persistence is configured // NEXT_MAJOR: remove `$this->persistFilters !== false` from the condition - if (false !== $this->persistFilters && null !== $this->filterPersister) { + if (false !== $this->persistFilters && $this->hasFilterPersister()) { // if reset filters is asked, remove from storage - if ('reset' === $this->request->query->get('filters')) { - $this->filterPersister->reset($this->getCode()); + if ('reset' === $this->getRequest()->query->get('filters')) { + $this->getFilterPersister()->reset($this->getCode()); } // if no filters, fetch from storage // otherwise save to storage if (empty($filters)) { - $filters = $this->filterPersister->get($this->getCode()); + $filters = $this->getFilterPersister()->get($this->getCode()); } else { - $this->filterPersister->set($this->getCode(), $filters); + $this->getFilterPersister()->set($this->getCode(), $filters); } } @@ -1702,19 +1485,6 @@ public function getBaseControllerName() return $this->baseControllerName; } - /** - * @param string $label - */ - public function setLabel($label) - { - $this->label = $label; - } - - public function getLabel() - { - return $this->label; - } - /** * @param bool $persist * @@ -1732,13 +1502,6 @@ public function setPersistFilters($persist) $this->persistFilters = $persist; } - public function setFilterPersister(?FilterPersisterInterface $filterPersister = null) - { - $this->filterPersister = $filterPersister; - // NEXT_MAJOR remove the deprecated property will be removed. Needed for persisted filter condition. - $this->persistFilters = true; - } - /** * NEXT_MAJOR: Remove this method. * @@ -2355,6 +2118,19 @@ public function getUniqid() */ public function getClassnameLabel() { + if (null === $this->classnameLabel) { + // NEXT_MAJOR: Remove this deprecation and uncomment the following exception + @trigger_error(sprintf( + 'Calling %s() when no classname label is set is deprecated since sonata-project/admin-bundle 3.x' + .' and will throw a LogicException in 4.0', + __METHOD__, + ), E_USER_DEPRECATED); +// throw new \LogicException(sprintf( +// 'Admin "%s" has no classname label. Did you forgot to initialize the admin ?', +// static::class +// )); + } + return $this->classnameLabel; } @@ -2562,43 +2338,6 @@ public function getTranslationDomain() return $this->translationDomain; } - /** - * {@inheritdoc} - * - * NEXT_MAJOR: remove this method - * - * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 - */ - public function setTranslator(TranslatorInterface $translator) - { - $args = \func_get_args(); - if (isset($args[1]) && $args[1]) { - @trigger_error(sprintf( - 'The %s method is deprecated since version 3.9 and will be removed in 4.0.', - __METHOD__ - ), E_USER_DEPRECATED); - } - - $this->translator = $translator; - } - - /** - * {@inheritdoc} - * - * NEXT_MAJOR: remove this method - * - * @deprecated since sonata-project/admin-bundle 3.9, to be removed with 4.0 - */ - public function getTranslator() - { - @trigger_error(sprintf( - 'The %s method is deprecated since version 3.9 and will be removed in 4.0.', - __METHOD__ - ), E_USER_DEPRECATED); - - return $this->translator; - } - public function getTranslationLabel($label, $context = '', $type = '') { return $this->getLabelTranslatorStrategy()->getLabel($label, $context, $type); @@ -2628,78 +2367,6 @@ public function hasRequest() return null !== $this->request; } - public function setFormContractor(FormContractorInterface $formBuilder) - { - $this->formContractor = $formBuilder; - } - - /** - * @return FormContractorInterface - */ - public function getFormContractor() - { - return $this->formContractor; - } - - public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) - { - $this->datagridBuilder = $datagridBuilder; - } - - public function getDatagridBuilder() - { - return $this->datagridBuilder; - } - - public function setListBuilder(ListBuilderInterface $listBuilder) - { - $this->listBuilder = $listBuilder; - } - - public function getListBuilder() - { - return $this->listBuilder; - } - - public function setShowBuilder(ShowBuilderInterface $showBuilder) - { - $this->showBuilder = $showBuilder; - } - - /** - * @return ShowBuilderInterface - */ - public function getShowBuilder() - { - return $this->showBuilder; - } - - public function setConfigurationPool(Pool $configurationPool) - { - $this->configurationPool = $configurationPool; - } - - /** - * @return Pool - */ - public function getConfigurationPool() - { - return $this->configurationPool; - } - - public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) - { - $this->routeGenerator = $routeGenerator; - } - - /** - * @return RouteGeneratorInterface - */ - public function getRouteGenerator() - { - return $this->routeGenerator; - } - public function getCode() { return $this->code; @@ -2745,60 +2412,11 @@ public function getBaseCodeRoute() return $this->baseCodeRoute; } - public function getModelManager() - { - return $this->modelManager; - } - - public function setModelManager(ModelManagerInterface $modelManager) - { - $this->modelManager = $modelManager; - } - - /** - * NEXT_MAJOR: Change typehint for DataSourceInterface. - */ - public function getDataSource(): ?DataSourceInterface - { - return $this->dataSource; - } - - public function setDataSource(DataSourceInterface $dataSource) - { - $this->dataSource = $dataSource; - } - - public function getManagerType() - { - return $this->managerType; - } - - /** - * @param string $type - */ - public function setManagerType($type) - { - $this->managerType = $type; - } - public function getObjectIdentifier() { return $this->getCode(); } - /** - * Set the roles and permissions per role. - */ - public function setSecurityInformation(array $information) - { - $this->securityInformation = $information; - } - - public function getSecurityInformation() - { - return $this->securityInformation; - } - /** * Return the list of permissions the user should have in order to display the admin. * @@ -2848,39 +2466,6 @@ public function id($model) return $this->getNormalizedIdentifier($model); } - /** - * NEXT_MAJOR: Remove this method. - * - * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 - */ - public function setValidator($validator) - { - // NEXT_MAJOR: Move ValidatorInterface check to method signature - if (!$validator instanceof ValidatorInterface) { - throw new \InvalidArgumentException(sprintf( - 'Argument 1 must be an instance of %s', - ValidatorInterface::class - )); - } - - $this->validator = $validator; - } - - /** - * NEXT_MAJOR: Remove this method. - * - * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 - */ - public function getValidator() - { - @trigger_error(sprintf( - 'The %s method is deprecated since version 3.83 and will be removed in 4.0.', - __METHOD__ - ), E_USER_DEPRECATED); - - return $this->validator; - } - public function getShow() { $this->buildShow(); @@ -2918,26 +2503,6 @@ public function getExtensions() return $this->extensions; } - public function setMenuFactory(FactoryInterface $menuFactory) - { - $this->menuFactory = $menuFactory; - } - - public function getMenuFactory() - { - return $this->menuFactory; - } - - public function setRouteBuilder(RouteBuilderInterface $routeBuilder) - { - $this->routeBuilder = $routeBuilder; - } - - public function getRouteBuilder() - { - return $this->routeBuilder; - } - public function toString($object) { // NEXT_MAJOR: Remove this check and use object as param typehint. @@ -2959,16 +2524,6 @@ public function toString($object) return sprintf('%s:%s', ClassUtils::getClass($object), spl_object_hash($object)); } - public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy) - { - $this->labelTranslatorStrategy = $labelTranslatorStrategy; - } - - public function getLabelTranslatorStrategy() - { - return $this->labelTranslatorStrategy; - } - public function supportsPreviewMode() { return $this->supportsPreviewMode; @@ -3009,26 +2564,6 @@ public function getPerPageOptions() // return $perPageOptions; } - /** - * Set pager type. - * - * @param string $pagerType - */ - public function setPagerType($pagerType) - { - $this->pagerType = $pagerType; - } - - /** - * Get pager type. - * - * @return string - */ - public function getPagerType() - { - return $this->pagerType; - } - /** * Returns true if the per page value is allowed, false otherwise. * @@ -3271,21 +2806,6 @@ public function getDashboardActions() return $actions; } - /** - * Setting to true will enable mosaic button for the admin screen. - * Setting to false will hide mosaic button for the admin screen. - * - * @param bool $isShown - */ - final public function showMosaicButton($isShown) - { - if ($isShown) { - $this->listModes['mosaic'] = ['class' => static::MOSAIC_ICON_CLASS]; - } else { - unset($this->listModes['mosaic']); - } - } - /** * @param object $object * diff --git a/src/Admin/AbstractAdminTag.php b/src/Admin/AbstractAdminTag.php index 3667b83add..247bf8bd16 100644 --- a/src/Admin/AbstractAdminTag.php +++ b/src/Admin/AbstractAdminTag.php @@ -172,6 +172,10 @@ abstract class AbstractAdminTag implements AdminTagInterface protected $routeGenerator; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 + * * @var ValidatorInterface|null */ protected $validator; @@ -518,7 +522,7 @@ public function getDatagridBuilder() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.83 */ public function setTranslator(TranslatorInterface $translator) { @@ -526,7 +530,7 @@ public function setTranslator(TranslatorInterface $translator) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.83 */ public function getTranslator() { @@ -608,6 +612,8 @@ public function getRouteGenerator() /** * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 */ public function setValidator($validator) { @@ -624,12 +630,14 @@ public function setValidator($validator) /** * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 */ public function getValidator() { @trigger_error(sprintf( - 'Calling %s() is deprecated since sonata-project/admin-bundle 3.x.', - __METHOD__, + 'The %s method is deprecated since version 3.83 and will be removed in 4.0.', + __METHOD__ ), E_USER_DEPRECATED); return $this->validator; diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 5db32529f3..d47136b97f 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -13,37 +13,24 @@ namespace Sonata\AdminBundle\Admin; -use Knp\Menu\FactoryInterface as MenuFactoryInterface; use Knp\Menu\ItemInterface; -use Sonata\AdminBundle\Builder\DatagridBuilderInterface; -use Sonata\AdminBundle\Builder\FormContractorInterface; -use Sonata\AdminBundle\Builder\ListBuilderInterface; -use Sonata\AdminBundle\Builder\RouteBuilderInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; -use Sonata\AdminBundle\Exporter\DataSourceInterface; -use Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface; -use Sonata\AdminBundle\Model\ModelManagerInterface; use Sonata\AdminBundle\Object\MetadataInterface; -use Sonata\AdminBundle\Route\RouteGeneratorInterface; -use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface; use Sonata\AdminBundle\Templating\MutableTemplateRegistryAwareInterface; -use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface; use Sonata\Exporter\Source\SourceIteratorInterface; use Sonata\Form\Validator\ErrorElement; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Translation\TranslatorInterface; -use Symfony\Component\Validator\Validator\ValidatorInterface; /** * @author Thomas Rabaix * + * NEXT_MAJOR: Add all these methods to the interface by uncommenting them. + * * @method array configureActionButtons(string $action, ?object $object = null) * @method string getSearchResultLink(object $object) - * @method void showMosaicButton(bool $isShown) - * @method bool isDefaultFilter(string $name) // NEXT_MAJOR: Remove this * @method bool isCurrentRoute(string $name, ?string $adminCode) * @method bool canAccessObject(string $action, object $object) * @method mixed getPersistentParameter(string $name) @@ -53,82 +40,24 @@ * @method string getRootCode() * @method array getActionButtons(string $action, ?object $object) * @method FieldDescriptionCollection|null getList() - * @method void setFilterPersister(?FilterPersisterInterface $filterPersister = null) * @method string getBaseRoutePattern() * @method string getBaseRouteName() * @method ItemInterface getSideMenu(string $action, ?AdminInterface $childAdmin = null) * @method void addParentAssociationMapping(string $code, string $value) - * @method RouteGeneratorInterface getRouteGenerator() * @method string getClassnameLabel() * @method AdminInterface|null getCurrentChildAdmin() * @method string|null getParentAssociationMapping() * @method void reorderFormGroup(string $group, array $keys) * @method void defineFormBuilder(FormBuilderInterface $formBuilder) - * @method string getPagerType() - * @method DataSourceInterface|null getDataSource() * * @phpstan-template T of object + * @phpstan-extends AdminTagInterface * @phpstan-extends AccessRegistryInterface * @phpstan-extends UrlGeneratorInterface * @phpstan-extends LifecycleHookProviderInterface */ -interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface +interface AdminInterface extends AdminTagInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface { - /** - * @return void - */ - public function setMenuFactory(MenuFactoryInterface $menuFactory); - - /** - * @return MenuFactoryInterface - */ - public function getMenuFactory(); - - /** - * @return void - */ - public function setFormContractor(FormContractorInterface $formContractor); - - /** - * @return void - */ - public function setListBuilder(ListBuilderInterface $listBuilder); - - /** - * @return ListBuilderInterface - */ - public function getListBuilder(); - - /** - * @return void - */ - public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder); - - /** - * @return DatagridBuilderInterface - */ - public function getDatagridBuilder(); - - /** - * @return void - */ - public function setTranslator(TranslatorInterface $translator); - - /** - * @return TranslatorInterface - */ - public function getTranslator(); - - /** - * @return void - */ - public function setRequest(Request $request); - - /** - * @return void - */ - public function setConfigurationPool(Pool $pool); - /** * Returns subjectClass/class/subclass name managed * - subclass name if subclass parameter is defined @@ -146,9 +75,6 @@ public function getClass(); */ public function attachAdminClass(FieldDescriptionInterface $fieldDescription); - // NEXT_MAJOR: uncomment this method in 4.0 - //public function getPagerType(): string; - /** * @return DatagridInterface */ @@ -170,19 +96,6 @@ public function setBaseControllerName($baseControllerName); */ public function getBaseControllerName(); - /** - * @return ModelManagerInterface - */ - public function getModelManager(); - - // NEXT_MAJOR: Uncomment the next line. - // public function getDataSource(): DataSourceInterface; - - /** - * @return string the manager type of the admin - */ - public function getManagerType(); - /** * @param string $context NEXT_MAJOR: remove this argument * @@ -202,6 +115,11 @@ public function getFormBuilder(); */ public function getForm(); + /** + * @return void + */ + public function setRequest(Request $request); + /** * NEXT MAJOR: Remove the throws tag. * @@ -227,16 +145,6 @@ public function getCode(); */ public function getBaseCodeRoute(); - /** - * Return the roles and permissions per role - * - different permissions per role for the acl handler - * - one permission that has the same name as the role for the role handler - * This should be used by experimented users. - * - * @return array 'role' => ['permission', 'permission'] - */ - public function getSecurityInformation(); - /** * @return void */ @@ -287,16 +195,6 @@ public function getIdParameter(); */ public function hasRoute($name); - /** - * @return void - */ - public function setSecurityHandler(SecurityHandlerInterface $securityHandler); - - /** - * @return SecurityHandlerInterface|null - */ - public function getSecurityHandler(); - /** * @param string|array $name * @param object|null $object @@ -327,26 +225,6 @@ public function getNormalizedIdentifier($model); */ public function id($model); - /** - * NEXT_MAJOR: remove this method. - * - * @param ValidatorInterface $validator - * - * @return void - * - * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 - */ - public function setValidator($validator); - - /** - * NEXT_MAJOR: remove this method. - * - * @return ValidatorInterface - * - * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 - */ - public function getValidator(); - /** * @return FieldDescriptionCollection|null */ @@ -389,16 +267,6 @@ public function addExtension(AdminExtensionInterface $extension); */ public function getExtensions(); - /** - * @return void - */ - public function setRouteBuilder(RouteBuilderInterface $routeBuilder); - - /** - * @return RouteBuilderInterface - */ - public function getRouteBuilder(); - /** * @param object|null $object NEXT_MAJOR: Use `object` as type declaration for argument 1 * @@ -408,16 +276,6 @@ public function getRouteBuilder(); */ public function toString($object); - /** - * @return void - */ - public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy); - - /** - * @return LabelTranslatorStrategyInterface - */ - public function getLabelTranslatorStrategy(); - /** * Returning true will enable preview mode for * the target entity and show a preview button @@ -521,6 +379,10 @@ public function getExportFormats(); public function getDataSourceIterator(); /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-admin/admin-bundle 3.x + * * @return void */ public function configure(); @@ -780,13 +642,6 @@ public function getActiveSubclassCode(); */ public function getBatchActions(); - /** - * Returns Admin`s label. - * - * @return string - */ - public function getLabel(); - /** * Returns an array of persistent parameters. * @@ -882,16 +737,6 @@ public function getListMode(); */ //public function getSearchResultLink(object $object): ?string -// NEXT_MAJOR: uncomment this method in 4.0 -// /** -// * Setting to true will enable mosaic button for the admin screen. -// * Setting to false will hide mosaic button for the admin screen. -// */ -// public function showMosaicButton(bool $isShown): void; - -// NEXT_MAJOR: uncomment this method in 4.0 -// public function setFilterPersister(?\Sonata\AdminBundle\Filter\Persister\FilterPersisterInterface\FilterPersisterInterface $filterPersister = null): void; - // NEXT_MAJOR: uncomment this method in 4.0 // /** // * Returns the baseRoutePattern used to generate the routing information. @@ -910,9 +755,6 @@ public function getListMode(); // NEXT_MAJOR: uncomment this method in 4.0 // public function addParentAssociationMapping(string $code, string $value): void; -// NEXT_MAJOR: uncomment this method in 4.0 -// public function getRouteGenerator(): \Sonata\AdminBundle\Route\RouteGeneratorInterface; - // NEXT_MAJOR: uncomment this method in 4.0 // /** // * Returns the classname label. diff --git a/src/Admin/AdminTagInterface.php b/src/Admin/AdminTagInterface.php index ebba728292..92dd53cf11 100644 --- a/src/Admin/AdminTagInterface.php +++ b/src/Admin/AdminTagInterface.php @@ -234,10 +234,23 @@ public function setConfigurationPool(Pool $pool); */ // public function getRouteGenerator(): RouteGeneratorInterface; + /** + * NEXT_MAJOR: remove this method. + * + * @param ValidatorInterface $validator + * + * @return void + * + * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 + */ + public function setValidator($validator); + /** * NEXT_MAJOR: Remove this method. * * @return ValidatorInterface + * + * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0 */ public function getValidator(); From 6945b5aad61537303514ad37fa137845e64979b5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 22 Nov 2020 20:29:37 +0100 Subject: [PATCH 10/30] Fix tests --- phpstan-baseline.neon | 12 --- src/Mapper/BaseGroupedMapper.php | 2 +- tests/Admin/AdminTest.php | 91 ++++++------------- .../Compiler/ExtensionCompilerPassTest.php | 2 +- 4 files changed, 32 insertions(+), 75 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ad53b504af..446958d64d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -30,12 +30,6 @@ parameters: count: 1 path: src/Admin/AbstractAdmin.php - - - # will be fixed in v4. Code is marked as deprecated - message: "#^Result of \\&\\& is always false\\.$#" - count: 1 - path: src/Admin/AbstractAdmin.php - - # will be fixed in v4. Code is marked as deprecated message: "#^Strict comparison using \\!\\=\\= between 'Sonata\\\\\\\\AdminBundle\\\\\\\\Admin\\\\\\\\AdminHelper' and 'Sonata\\\\\\\\AdminBundle\\\\\\\\Admin\\\\\\\\AdminHelper' will always evaluate to false\\.$#" @@ -139,12 +133,6 @@ parameters: count: 1 path: src/Form/FormMapper.php - - - # will be fixed in v4. Code is marked as deprecated - message: "#^Right side of && is always true\\.$#" - count: 1 - path: src/Mapper/BaseGroupedMapper.php - - # will be fixed in v4. Currently BC break message: "#^Negated boolean expression is always false\\.$#" diff --git a/src/Mapper/BaseGroupedMapper.php b/src/Mapper/BaseGroupedMapper.php index dc3c5f3d51..531bde8ad7 100644 --- a/src/Mapper/BaseGroupedMapper.php +++ b/src/Mapper/BaseGroupedMapper.php @@ -87,7 +87,7 @@ public function with($name, array $options = []) ]; // NEXT_MAJOR: remove this code - if ($this->admin instanceof AbstractAdmin && $pool = $this->admin->getConfigurationPool()) { + if ($this->admin instanceof AbstractAdmin && $pool = $this->admin->getConfigurationPool('sonata_deprecation_mute')) { if ($pool->getContainer('sonata_deprecation_mute')->getParameter('sonata.admin.configuration.translate_group_label')) { $defaultOptions['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($name, $this->getName(), 'group'); } diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 0e152867d7..6fd3e844e7 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -735,6 +735,7 @@ public function testIsAclEnabled(): void { $postAdmin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); + $postAdmin->setSecurityHandler($this->createMock(SecurityHandlerInterface::class)); $this->assertFalse($postAdmin->isAclEnabled()); $commentAdmin = new CommentAdmin('sonata.post.admin.comment', 'Application\Sonata\NewsBundle\Entity\Comment', 'Sonata\NewsBundle\Controller\CommentAdminController'); @@ -890,8 +891,6 @@ public function testGetLabelTranslatorStrategy(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getLabelTranslatorStrategy()); - $labelTranslatorStrategy = $this->createMock(LabelTranslatorStrategyInterface::class); $admin->setLabelTranslatorStrategy($labelTranslatorStrategy); $this->assertSame($labelTranslatorStrategy, $admin->getLabelTranslatorStrategy()); @@ -901,8 +900,6 @@ public function testGetRouteBuilder(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getRouteBuilder()); - $routeBuilder = $this->createMock(RouteBuilderInterface::class); $admin->setRouteBuilder($routeBuilder); $this->assertSame($routeBuilder, $admin->getRouteBuilder()); @@ -912,8 +909,6 @@ public function testGetMenuFactory(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getMenuFactory()); - $menuFactory = $this->createMock(FactoryInterface::class); $admin->setMenuFactory($menuFactory); $this->assertSame($menuFactory, $admin->getMenuFactory()); @@ -963,13 +958,11 @@ public function testGetValidator(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getValidator()); - $validator = $this->getMockForAbstractClass(ValidatorInterface::class); $admin->setValidator($validator); - $this->expectDeprecation('The Sonata\AdminBundle\Admin\AbstractAdmin::getValidator method is deprecated since version 3.83 and will be removed in 4.0.'); + $this->expectDeprecation('The Sonata\AdminBundle\Admin\AbstractAdminTag::getValidator method is deprecated since version 3.83 and will be removed in 4.0.'); $this->assertSame($validator, $admin->getValidator()); } @@ -978,8 +971,6 @@ public function testGetSecurityHandler(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getSecurityHandler()); - $securityHandler = $this->createMock(SecurityHandlerInterface::class); $admin->setSecurityHandler($securityHandler); $this->assertSame($securityHandler, $admin->getSecurityHandler()); @@ -1004,8 +995,6 @@ public function testGetManagerType(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getManagerType()); - $admin->setManagerType('foo_orm'); $this->assertSame('foo_orm', $admin->getManagerType()); } @@ -1014,8 +1003,6 @@ public function testGetModelManager(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getModelManager()); - $modelManager = $this->createMock(ModelManagerInterface::class); $admin->setModelManager($modelManager); @@ -1065,8 +1052,6 @@ public function testGetRouteGenerator(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getRouteGenerator()); - $routeGenerator = $this->createMock(RouteGeneratorInterface::class); $admin->setRouteGenerator($routeGenerator); @@ -1077,8 +1062,6 @@ public function testGetConfigurationPool(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getConfigurationPool()); - $pool = $this->getMockBuilder(Pool::class) ->disableOriginalConstructor() ->getMock(); @@ -1091,8 +1074,6 @@ public function testGetShowBuilder(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getShowBuilder()); - $showBuilder = $this->createMock(ShowBuilderInterface::class); $admin->setShowBuilder($showBuilder); @@ -1103,8 +1084,6 @@ public function testGetListBuilder(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getListBuilder()); - $listBuilder = $this->createMock(ListBuilderInterface::class); $admin->setListBuilder($listBuilder); @@ -1115,8 +1094,6 @@ public function testGetDatagridBuilder(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getDatagridBuilder()); - $datagridBuilder = $this->createMock(DatagridBuilderInterface::class); $admin->setDatagridBuilder($datagridBuilder); @@ -1127,8 +1104,6 @@ public function testGetFormContractor(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getFormContractor()); - $formContractor = $this->createMock(FormContractorInterface::class); $admin->setFormContractor($formContractor); @@ -1167,15 +1142,10 @@ public function testGetTranslationDomain(): void $this->assertSame('foo', $admin->getTranslationDomain()); } - /** - * @group legacy - */ public function testGetTranslator(): void { $admin = new PostAdmin('sonata.post.admin.post', 'NewsBundle\Entity\Post', 'Sonata\NewsBundle\Controller\PostAdminController'); - $this->assertNull($admin->getTranslator()); - $translator = $this->createMock(TranslatorInterface::class); $admin->setTranslator($translator); @@ -2569,28 +2539,31 @@ public function testGetDataSourceIterator(): void 2 => 'bar', ]); + $translator = $this->createStub(TranslatorInterface::class); + $translator + ->method('trans') + ->willReturnCallback(static function (string $label): string { + if ('export.label_field' === $label) { + return 'Feld'; + } + + return $label; + }); + $admin = $this->getMockBuilder(AbstractAdmin::class) ->disableOriginalConstructor() - ->onlyMethods(['getDatagrid', 'getTranslationLabel', 'trans']) + ->onlyMethods(['getDatagrid', 'getTranslationLabel']) ->getMockForAbstractClass(); $admin->method('getDatagrid')->willReturn($datagrid); $admin->setModelManager($modelManager); $admin->setDataSource($dataSource); + $admin->setTranslator($translator); $admin ->method('getTranslationLabel') ->willReturnCallback(static function (string $label, string $context = '', string $type = ''): string { return sprintf('%s.%s_%s', $context, $type, $label); }); - $admin - ->method('trans') - ->willReturnCallback(static function (string $label): string { - if ('export.label_field' === $label) { - return 'Feld'; - } - - return $label; - }); $admin->getDataSourceIterator(); } @@ -2618,27 +2591,30 @@ public function testGetDataSourceIteratorWithoutDataSourceSet(): void 2 => 'bar', ])); + $translator = $this->createStub(TranslatorInterface::class); + $translator + ->method('trans') + ->willReturnCallback(static function (string $label): string { + if ('export.label_field' === $label) { + return 'Feld'; + } + + return $label; + }); + $admin = $this->getMockBuilder(AbstractAdmin::class) ->disableOriginalConstructor() - ->onlyMethods(['getDatagrid', 'getTranslationLabel', 'trans']) + ->onlyMethods(['getDatagrid', 'getTranslationLabel']) ->getMockForAbstractClass(); $admin->method('getDatagrid')->willReturn($datagrid); $admin->setModelManager($modelManager); + $admin->setTranslator($translator); $admin ->method('getTranslationLabel') ->willReturnCallback(static function (string $label, string $context = '', string $type = ''): string { return sprintf('%s.%s_%s', $context, $type, $label); }); - $admin - ->method('trans') - ->willReturnCallback(static function (string $label): string { - if ('export.label_field' === $label) { - return 'Feld'; - } - - return $label; - }); $this->expectDeprecation('Using "Sonata\AdminBundle\Admin\AbstractAdmin::getDataSourceIterator()" without setting a "Sonata\AdminBundle\Exporter\DataSourceInterface" instance in the admin is deprecated since sonata-project/admin-bundle 3.79 and won\'t be possible in 4.0.'); $admin->getDataSourceIterator(); @@ -2815,13 +2791,6 @@ public function testGetCurrentLeafChildAdmin(): void $this->assertNull($commentVoteAdmin->getCurrentLeafChildAdmin()); } - public function testAdminWithoutControllerName(): void - { - $admin = new PostAdmin('sonata.post.admin.post', 'Application\Sonata\NewsBundle\Entity\Post', null); - - $this->assertNull($admin->getBaseControllerName()); - } - public function testAdminAvoidInifiniteLoop(): void { $this->expectNotToPerformAssertions(); @@ -2832,7 +2801,7 @@ public function testAdminAvoidInifiniteLoop(): void ->method('getDefaultSortValues') ->willReturn([]); - $admin = new AvoidInfiniteLoopAdmin('code', \stdClass::class, null); + $admin = new AvoidInfiniteLoopAdmin('code', \stdClass::class, 'controller'); $admin->setSubject(new \stdClass()); $admin->setModelManager($modelManager); @@ -2867,7 +2836,7 @@ public function testAdminAvoidInifiniteLoop(): void * * @dataProvider getDeprecatedAbstractAdminConstructorArgs * - * @expectedDeprecation Passing other type than string%S as argument %d for method Sonata\AdminBundle\Admin\AbstractAdmin::__construct() is deprecated since sonata-project/admin-bundle 3.65. It will accept only string%S in version 4.0. + * @expectedDeprecation Passing other type than string as argument %d for method Sonata\AdminBundle\Admin\AbstractAdminTag::__construct() is deprecated since sonata-project/admin-bundle 3.%s. It will accept only string in version 4.0. * * @doesNotPerformAssertions */ diff --git a/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php b/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php index c00a4ca935..edcc35e4a5 100644 --- a/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/ExtensionCompilerPassTest.php @@ -475,7 +475,7 @@ class MockAbstractServiceAdmin extends AbstractAdmin { private $extraArgument; - public function __construct($code, $class, $baseControllerName, $extraArgument) + public function __construct($code, $class, $baseControllerName, $extraArgument = null) { $this->extraArgument = $extraArgument; From 3f4bb9959394d3d5cd62161b52467244ab52c84e Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 28 Nov 2020 12:34:33 +0100 Subject: [PATCH 11/30] Improve construct signature --- src/Admin/AdminTagInterface.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Admin/AdminTagInterface.php b/src/Admin/AdminTagInterface.php index 92dd53cf11..6b41b69f1e 100644 --- a/src/Admin/AdminTagInterface.php +++ b/src/Admin/AdminTagInterface.php @@ -32,9 +32,16 @@ * This interface should be implemented to work with the AddDependencyCallsCompilerPass. * All the setter are called by this compiler pass. * + * Note that the constructor should also have the following signature + * ``` + * public function __construct(string $code, string $class, string $controller, ...); + * ``` + * so that the admin class works correctly with the AddDependencyCallsCompilerPass. Indeed: + * - The first and third argument are automatically injected by the AddDependencyCallsCompilerPass. + * - The second one is used as a reference of the Admin in the Pool, with the `setAdminClasses` call. + * * @phpstan-template T of object * - * @method void __construct(string $code, string $class, string $controller) * @method void initialize() * @method void setLabel(?string $label) * @method void showMosaicButton(bool $isShown) @@ -59,15 +66,6 @@ interface AdminTagInterface { public const ADMIN_TAG = 'sonata.admin'; - /** - * NEXT_MAJOR: Uncomment this method. - * - * The first and third argument are automatically injected by the AddDependencyCallsCompilerPass. - * - * @phpstan-param class-string $class - */ -// public function __construct(string $code, string $class, string $controller); - /** * NEXT_MAJOR: Uncomment this method. * From 50606daf00a80883e817fe8057686784ee360774 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 1 Dec 2020 21:17:11 +0100 Subject: [PATCH 12/30] Move AdminTag into DependencyInjection directory --- src/Admin/AbstractAdmin.php | 1 + src/Admin/AdminInterface.php | 1 + src/{ => DependencyInjection}/Admin/AbstractAdminTag.php | 3 ++- src/{ => DependencyInjection}/Admin/AdminTagInterface.php | 3 ++- 4 files changed, 6 insertions(+), 2 deletions(-) rename src/{ => DependencyInjection}/Admin/AbstractAdminTag.php (99%) rename src/{ => DependencyInjection}/Admin/AdminTagInterface.php (98%) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 6716b045fd..550b4386a5 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -19,6 +19,7 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; +use Sonata\AdminBundle\DependencyInjection\Admin\AbstractAdminTag; use Sonata\AdminBundle\Exporter\DataSourceInterface; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\Type\ModelHiddenType; diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index d47136b97f..e2d4624194 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -16,6 +16,7 @@ use Knp\Menu\ItemInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; +use Sonata\AdminBundle\DependencyInjection\Admin\AdminTagInterface; use Sonata\AdminBundle\Object\MetadataInterface; use Sonata\AdminBundle\Templating\MutableTemplateRegistryAwareInterface; use Sonata\Exporter\Source\SourceIteratorInterface; diff --git a/src/Admin/AbstractAdminTag.php b/src/DependencyInjection/Admin/AbstractAdminTag.php similarity index 99% rename from src/Admin/AbstractAdminTag.php rename to src/DependencyInjection/Admin/AbstractAdminTag.php index 247bf8bd16..f03ae641c5 100644 --- a/src/Admin/AbstractAdminTag.php +++ b/src/DependencyInjection/Admin/AbstractAdminTag.php @@ -11,9 +11,10 @@ * file that was distributed with this source code. */ -namespace Sonata\AdminBundle\Admin; +namespace Sonata\AdminBundle\DependencyInjection\Admin; use Knp\Menu\FactoryInterface; +use Sonata\AdminBundle\Admin\Pool; use Sonata\AdminBundle\Builder\DatagridBuilderInterface; use Sonata\AdminBundle\Builder\FormContractorInterface; use Sonata\AdminBundle\Builder\ListBuilderInterface; diff --git a/src/Admin/AdminTagInterface.php b/src/DependencyInjection/Admin/AdminTagInterface.php similarity index 98% rename from src/Admin/AdminTagInterface.php rename to src/DependencyInjection/Admin/AdminTagInterface.php index 6b41b69f1e..5d765f15b9 100644 --- a/src/Admin/AdminTagInterface.php +++ b/src/DependencyInjection/Admin/AdminTagInterface.php @@ -11,9 +11,10 @@ * file that was distributed with this source code. */ -namespace Sonata\AdminBundle\Admin; +namespace Sonata\AdminBundle\DependencyInjection\Admin; use Knp\Menu\FactoryInterface; +use Sonata\AdminBundle\Admin\Pool; use Sonata\AdminBundle\Builder\DatagridBuilderInterface; use Sonata\AdminBundle\Builder\FormContractorInterface; use Sonata\AdminBundle\Builder\ListBuilderInterface; From a341743f80efb240471f062fbb934c44191b98f4 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 5 Dec 2020 00:23:15 +0100 Subject: [PATCH 13/30] Rename AdminTag to TaggedAdmin --- src/Admin/AbstractAdmin.php | 6 +++--- src/Admin/AdminInterface.php | 6 +++--- .../{AbstractAdminTag.php => AbstractTaggedAdmin.php} | 4 ++-- .../{AdminTagInterface.php => TaggedAdminInterface.php} | 2 +- .../Compiler/AddDependencyCallsCompilerPass.php | 4 ++-- .../Compiler/AdminSearchCompilerPass.php | 7 +++---- src/DependencyInjection/Compiler/ExtensionCompilerPass.php | 3 ++- tests/Admin/AdminTest.php | 4 ++-- 8 files changed, 18 insertions(+), 18 deletions(-) rename src/DependencyInjection/Admin/{AbstractAdminTag.php => AbstractTaggedAdmin.php} (99%) rename src/DependencyInjection/Admin/{AdminTagInterface.php => TaggedAdminInterface.php} (99%) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 550b4386a5..36af1fabc6 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -19,7 +19,7 @@ use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; -use Sonata\AdminBundle\DependencyInjection\Admin\AbstractAdminTag; +use Sonata\AdminBundle\DependencyInjection\Admin\AbstractTaggedAdmin; use Sonata\AdminBundle\Exporter\DataSourceInterface; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\Type\ModelHiddenType; @@ -50,10 +50,10 @@ * @author Thomas Rabaix * * @phpstan-template T of object - * @phpstan-extends AbstractAdminTag + * @phpstan-extends AbstractTaggedAdmin * @phpstan-implements AdminInterface */ -abstract class AbstractAdmin extends AbstractAdminTag implements AdminInterface, DomainObjectInterface, AdminTreeInterface +abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterface, DomainObjectInterface, AdminTreeInterface { public const CONTEXT_MENU = 'menu'; public const CONTEXT_DASHBOARD = 'dashboard'; diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index e2d4624194..1e131f020b 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -16,7 +16,7 @@ use Knp\Menu\ItemInterface; use Sonata\AdminBundle\Datagrid\DatagridInterface; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; -use Sonata\AdminBundle\DependencyInjection\Admin\AdminTagInterface; +use Sonata\AdminBundle\DependencyInjection\Admin\TaggedAdminInterface; use Sonata\AdminBundle\Object\MetadataInterface; use Sonata\AdminBundle\Templating\MutableTemplateRegistryAwareInterface; use Sonata\Exporter\Source\SourceIteratorInterface; @@ -52,12 +52,12 @@ * @method void defineFormBuilder(FormBuilderInterface $formBuilder) * * @phpstan-template T of object - * @phpstan-extends AdminTagInterface + * @phpstan-extends TaggedAdminInterface * @phpstan-extends AccessRegistryInterface * @phpstan-extends UrlGeneratorInterface * @phpstan-extends LifecycleHookProviderInterface */ -interface AdminInterface extends AdminTagInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface +interface AdminInterface extends TaggedAdminInterface, AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface, MutableTemplateRegistryAwareInterface { /** * Returns subjectClass/class/subclass name managed diff --git a/src/DependencyInjection/Admin/AbstractAdminTag.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php similarity index 99% rename from src/DependencyInjection/Admin/AbstractAdminTag.php rename to src/DependencyInjection/Admin/AbstractTaggedAdmin.php index f03ae641c5..4d26d42334 100644 --- a/src/DependencyInjection/Admin/AbstractAdminTag.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -32,9 +32,9 @@ /** * @phpstan-template T of object - * @phpstan-implements AdminTagInterface + * @phpstan-implements TaggedAdminInterface */ -abstract class AbstractAdminTag implements AdminTagInterface +abstract class AbstractTaggedAdmin implements TaggedAdminInterface { public const MOSAIC_ICON_CLASS = 'fa fa-th-large fa-fw'; diff --git a/src/DependencyInjection/Admin/AdminTagInterface.php b/src/DependencyInjection/Admin/TaggedAdminInterface.php similarity index 99% rename from src/DependencyInjection/Admin/AdminTagInterface.php rename to src/DependencyInjection/Admin/TaggedAdminInterface.php index 5d765f15b9..10f04574dc 100644 --- a/src/DependencyInjection/Admin/AdminTagInterface.php +++ b/src/DependencyInjection/Admin/TaggedAdminInterface.php @@ -63,7 +63,7 @@ * @method void setRouteGenerator(RouteGeneratorInterface $routeGenerator) * @method RouteGeneratorInterface getRouteGenerator() */ -interface AdminTagInterface +interface TaggedAdminInterface { public const ADMIN_TAG = 'sonata.admin'; diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 5baa7c750d..8c8cecb657 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -14,9 +14,9 @@ namespace Sonata\AdminBundle\DependencyInjection\Compiler; use Doctrine\Inflector\InflectorFactory; -use Sonata\AdminBundle\Admin\AdminTagInterface; use Sonata\AdminBundle\Controller\CRUDController; use Sonata\AdminBundle\Datagrid\Pager; +use Sonata\AdminBundle\DependencyInjection\Admin\TaggedAdminInterface; use Sonata\AdminBundle\Templating\TemplateRegistry; use Symfony\Component\DependencyInjection\ChildDefinition; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; @@ -57,7 +57,7 @@ public function process(ContainerBuilder $container) 'icon' => $container->getParameter('sonata.admin.configuration.default_icon'), ]; - foreach ($container->findTaggedServiceIds(AdminTagInterface::ADMIN_TAG) as $id => $tags) { + foreach ($container->findTaggedServiceIds(TaggedAdminInterface::ADMIN_TAG) as $id => $tags) { foreach ($tags as $attributes) { $definition = $container->getDefinition($id); $parentDefinition = null; diff --git a/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php b/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php index 4211dc3f41..61a0c521b3 100644 --- a/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php +++ b/src/DependencyInjection/Compiler/AdminSearchCompilerPass.php @@ -14,6 +14,7 @@ namespace Sonata\AdminBundle\DependencyInjection\Compiler; use Sonata\AdminBundle\Admin\AdminInterface; +use Sonata\AdminBundle\DependencyInjection\Admin\TaggedAdminInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Exception\LogicException; @@ -27,8 +28,6 @@ final class AdminSearchCompilerPass implements CompilerPassInterface { public const TAG_ATTRIBUTE_TOGGLE_SEARCH = 'global_search'; - private const TAG_ADMIN = 'sonata.admin'; - public function process(ContainerBuilder $container): void { if (!$container->hasDefinition('sonata.admin.search.handler')) { @@ -37,7 +36,7 @@ public function process(ContainerBuilder $container): void $adminSearch = []; - foreach ($container->findTaggedServiceIds(self::TAG_ADMIN) as $id => $tags) { + foreach ($container->findTaggedServiceIds(TaggedAdminInterface::ADMIN_TAG) as $id => $tags) { $this->validateAdminClass($container, $id); foreach ($tags as $attributes) { @@ -95,7 +94,7 @@ private function getGlobalSearchValue(array $attributes, string $id): ?bool throw new LogicException(sprintf( 'Attribute "%s" in tag "%s" at service "%s" must be of type boolean, "%s" given.', self::TAG_ATTRIBUTE_TOGGLE_SEARCH, - self::TAG_ADMIN, + TaggedAdminInterface::ADMIN_TAG, $id, \gettype($globalSearch) )); diff --git a/src/DependencyInjection/Compiler/ExtensionCompilerPass.php b/src/DependencyInjection/Compiler/ExtensionCompilerPass.php index 09fe97e9ed..916d8aff88 100644 --- a/src/DependencyInjection/Compiler/ExtensionCompilerPass.php +++ b/src/DependencyInjection/Compiler/ExtensionCompilerPass.php @@ -13,6 +13,7 @@ namespace Sonata\AdminBundle\DependencyInjection\Compiler; +use Sonata\AdminBundle\DependencyInjection\Admin\TaggedAdminInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; @@ -53,7 +54,7 @@ public function process(ContainerBuilder $container) $extensionConfig = $container->getParameter('sonata.admin.extension.map'); $extensionMap = $this->flattenExtensionConfiguration($extensionConfig); - foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) { + foreach ($container->findTaggedServiceIds(TaggedAdminInterface::ADMIN_TAG) as $id => $attributes) { $admin = $container->getDefinition($id); if (!isset($targets[$id])) { diff --git a/tests/Admin/AdminTest.php b/tests/Admin/AdminTest.php index 6fd3e844e7..2e37222d0d 100644 --- a/tests/Admin/AdminTest.php +++ b/tests/Admin/AdminTest.php @@ -962,7 +962,7 @@ public function testGetValidator(): void $admin->setValidator($validator); - $this->expectDeprecation('The Sonata\AdminBundle\Admin\AbstractAdminTag::getValidator method is deprecated since version 3.83 and will be removed in 4.0.'); + $this->expectDeprecation('The Sonata\AdminBundle\DependencyInjection\Admin\AbstractTaggedAdmin::getValidator method is deprecated since version 3.83 and will be removed in 4.0.'); $this->assertSame($validator, $admin->getValidator()); } @@ -2836,7 +2836,7 @@ public function testAdminAvoidInifiniteLoop(): void * * @dataProvider getDeprecatedAbstractAdminConstructorArgs * - * @expectedDeprecation Passing other type than string as argument %d for method Sonata\AdminBundle\Admin\AbstractAdminTag::__construct() is deprecated since sonata-project/admin-bundle 3.%s. It will accept only string in version 4.0. + * @expectedDeprecation Passing other type than string as argument %d for method Sonata\AdminBundle\DependencyInjection\Admin\AbstractTaggedAdmin::__construct() is deprecated since sonata-project/admin-bundle 3.%s. It will accept only string in version 4.0. * * @doesNotPerformAssertions */ From 3f991f07c33b1ddd283efaff4ec03e538b606cae Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sat, 5 Dec 2020 19:05:56 +0100 Subject: [PATCH 14/30] Fix conflict --- .../Compiler/AddDependencyCallsCompilerPass.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php index 8c8cecb657..5431c0f3dd 100644 --- a/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AddDependencyCallsCompilerPass.php @@ -282,12 +282,7 @@ public function applyDefaults(ContainerBuilder $container, $serviceId, array $at 'translator' => 'translator', 'configuration_pool' => 'sonata.admin.pool', 'route_generator' => 'sonata.admin.route.default_generator', -<<<<<<< HEAD 'validator' => 'validator', //NEXT_MAJOR: Remove this line -======= - // NEXT_MAJOR: Remove this line. - 'validator' => 'validator', ->>>>>>> e3f653f61... Improve AddDependencyCallsCompilerPass 'security_handler' => 'sonata.admin.security.handler', 'menu_factory' => 'knp_menu.factory', 'route_builder' => 'sonata.admin.route.path_info'. From 94b4faee9d520ddb78a4e8878fdb91699fa48e97 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 16 Dec 2020 12:07:01 +0100 Subject: [PATCH 15/30] Add some methods, coming from AbstractPager and used in twig to PagerInterface (#6541) * Add some methods to PagerInterface * Deprecate method from abstract pager --- src/Datagrid/Pager.php | 309 +++++++++++++++++- src/Datagrid/PagerInterface.php | 75 +++-- src/Datagrid/SimplePager.php | 29 +- .../views/Block/block_stats.html.twig | 4 +- tests/App/Datagrid/Pager.php | 59 +++- tests/Datagrid/PagerTest.php | 115 +++++++ 6 files changed, 555 insertions(+), 36 deletions(-) diff --git a/src/Datagrid/Pager.php b/src/Datagrid/Pager.php index 238b9e0d9b..6f5d32b4fc 100644 --- a/src/Datagrid/Pager.php +++ b/src/Datagrid/Pager.php @@ -14,6 +14,8 @@ namespace Sonata\AdminBundle\Datagrid; /** + * NEXT_MAJOR: Remove the \Iterator, \Countable and \Serializable implementation. + * * @author Fabien Potencier * @author Thomas Rabaix */ @@ -43,21 +45,37 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter protected $nbResults = 0; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var int */ protected $cursor = 1; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var array */ protected $parameters = []; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var int */ protected $currentMaxLink = 1; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var mixed bool|int */ protected $maxRecordLimit = false; @@ -67,13 +85,24 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter */ protected $maxPageLinks = 0; - // used by iterator interface /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * + * Used by iterator interface + * * @var object[]|null */ protected $results; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * + * Used by iterator interface + * * @var int */ protected $resultsCounter = 0; @@ -84,6 +113,10 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter protected $query; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @var string[] */ protected $countColumn = ['id']; @@ -97,32 +130,59 @@ public function __construct($maxPerPage = 10) } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the current pager's max link. * * @return int */ public function getCurrentMaxLink() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->currentMaxLink; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the current pager's max record limit. * * @return int */ public function getMaxRecordLimit() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->maxRecordLimit; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Sets the current pager's max record limit. * * @param int $limit */ public function setMaxRecordLimit($limit) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $this->maxRecordLimit = $limit; } @@ -149,6 +209,7 @@ public function getLinks($nbLinks = null) $links[] = $i++; } + // NEXT_MAJOR: Remove this line. $this->currentMaxLink = \count($links) ? $links[\count($links) - 1] : 1; return $links; @@ -165,22 +226,40 @@ public function haveToPaginate() } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the current cursor. * * @return int */ public function getCursor() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->cursor; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Sets the current cursor. * * @param int $pos */ public function setCursor($pos) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if ($pos < 1) { $this->cursor = 1; } else { @@ -193,6 +272,10 @@ public function setCursor($pos) } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns an object by cursor position. * * @param int $pos @@ -201,28 +284,51 @@ public function setCursor($pos) */ public function getObjectByCursor($pos) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $this->setCursor($pos); return $this->getCurrent(); } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the current object. * * @return object */ public function getCurrent() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->retrieveObject($this->cursor); } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the next object. * * @return object|null */ public function getNext() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if ($this->cursor + 1 > $this->nbResults) { return null; } @@ -231,12 +337,21 @@ public function getNext() } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the previous object. * * @return mixed|null */ public function getPrevious() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if ($this->cursor - 1 < 1) { return null; } @@ -245,12 +360,21 @@ public function getPrevious() } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the first index on the current page. * * @return int */ public function getFirstIndex() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (0 === $this->page) { return 1; } @@ -275,12 +399,21 @@ public function getFirstIndice() } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the last index on the current page. * * @return int */ public function getLastIndex() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (0 === $this->page) { return $this->nbResults; } @@ -421,16 +554,29 @@ public function isLastPage() } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns the current pager's parameter holder. * * @return array */ public function getParameters() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->parameters; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns a parameter. * * @param string $name @@ -440,10 +586,19 @@ public function getParameters() */ public function getParameter($name, $default = null) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->parameters[$name] ?? $default; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Checks whether a parameter has been set. * * @param string $name @@ -452,10 +607,19 @@ public function getParameter($name, $default = null) */ public function hasParameter($name) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return isset($this->parameters[$name]); } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Sets a parameter. * * @param string $name @@ -463,11 +627,26 @@ public function hasParameter($name) */ public function setParameter($name, $value) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $this->parameters[$name] = $value; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function current() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (!$this->isIteratorInitialized()) { $this->initializeIterator(); } @@ -475,8 +654,18 @@ public function current() return current($this->results); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function key() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (!$this->isIteratorInitialized()) { $this->initializeIterator(); } @@ -484,8 +673,18 @@ public function key() return key($this->results); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function next() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (!$this->isIteratorInitialized()) { $this->initializeIterator(); } @@ -496,8 +695,18 @@ public function next() return next($this->results); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function rewind() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (!$this->isIteratorInitialized()) { $this->initializeIterator(); } @@ -508,8 +717,18 @@ public function rewind() return reset($this->results); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function valid() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + if (!$this->isIteratorInitialized()) { $this->initializeIterator(); } @@ -517,21 +736,51 @@ public function valid() return $this->resultsCounter > 0; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x, use getNbResults instead + */ public function count() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->getNbResults(); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function serialize() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $vars = get_object_vars($this); unset($vars['query']); return serialize($vars); } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ public function unserialize($serialized) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $array = unserialize($serialized); foreach ($array as $name => $values) { @@ -540,18 +789,36 @@ public function unserialize($serialized) } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @return string[] */ public function getCountColumn() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->countColumn; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * @return string[] */ public function setCountColumn(array $countColumn) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return $this->countColumn = $countColumn; } @@ -594,38 +861,73 @@ protected function setLastPage($page) } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Returns true if the properties used for iteration have been initialized. * * @return bool */ protected function isIteratorInitialized() { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + return null !== $this->results; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Loads data into properties used for iteration. * * @return void */ protected function initializeIterator() { + if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->results = $this->getResults(); $this->resultsCounter = \count($this->results); } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Empties properties used for iteration. * * @return void */ protected function resetIterator() { + if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->results = null; $this->resultsCounter = 0; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + * * Retrieve the object for a certain offset. * * @param int $offset @@ -634,6 +936,11 @@ protected function resetIterator() */ protected function retrieveObject($offset) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + $queryForRetrieve = clone $this->getQuery(); $queryForRetrieve ->setFirstResult($offset - 1) diff --git a/src/Datagrid/PagerInterface.php b/src/Datagrid/PagerInterface.php index 13fd4d531a..c9b422c5e1 100644 --- a/src/Datagrid/PagerInterface.php +++ b/src/Datagrid/PagerInterface.php @@ -18,9 +18,17 @@ * * NEXT_MAJOR: Remove these comments and uncomment corresponding methods. * - * @method int getPage() - * @method bool isLastPage() - * @method int getNbResults() + * @method int getPage() + * @method int getFirstPage() + * @method int getLastPage() + * @method int getNextPage() + * @method int getPreviousPage() + * @method bool isFirstPage() + * @method bool isLastPage() + * @method int getNbResults() + * @method array getLinks(?int $nbLinks = null) + * @method bool haveToPaginate() + * @method ProxyQueryInterface getQuery() */ interface PagerInterface { @@ -43,20 +51,46 @@ public function getMaxPerPage(); */ public function setMaxPerPage($max); +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getPage(): int; + /** - * Sets the current page. - * * @param int $page */ public function setPage($page); +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getNextPage(): int; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getPreviousPage(): int; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getFirstPage(): int; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function isFirstPage(): bool; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getLastPage(): int; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function isLastPage(): bool; + +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getQuery(): ProxyQueryInterface; + /** - * Set query. - * * @param ProxyQueryInterface $query */ public function setQuery($query); +// NEXT_MAJOR: uncomment this method in 4.0 +// /** +// * Returns true if the current query requires pagination. +// */ +// public function haveToPaginate(): bool; + /** * Returns an array of results on the given page. * @@ -64,6 +98,19 @@ public function setQuery($query); */ public function getResults(); +// NEXT_MAJOR: uncomment this method in 4.0 +// public function getNbResults(): int; + +// NEXT_MAJOR: uncomment this method 4.0 +// /** +// * Returns an array of page numbers to use in pagination links. +// * +// * @param int $nbLinks The maximum number of page numbers to return +// * +// * @return int[] +// */ +// public function getLinks(?int $nbLinks = null): array + /** * Sets the maximum number of page numbers. * @@ -77,18 +124,4 @@ public function setMaxPageLinks($maxPageLinks); * @return int */ public function getMaxPageLinks(); - -// NEXT_MAJOR: uncomment this method in 4.0 -// /** -// * Returns true if on the last page. -// * -// * @return bool -// */ -// public function isLastPage(): bool; - -// NEXT_MAJOR: uncomment this method in 4.0 -// public function getNbResults(): int; -// -// NEXT_MAJOR: uncomment this method in 4.0 -// public function getPage(): int; } diff --git a/src/Datagrid/SimplePager.php b/src/Datagrid/SimplePager.php index 04039848da..d08e154c99 100644 --- a/src/Datagrid/SimplePager.php +++ b/src/Datagrid/SimplePager.php @@ -23,6 +23,11 @@ */ class SimplePager extends Pager { + /** + * @var object[]|null + */ + protected $results; + /** * @var bool */ @@ -106,7 +111,10 @@ public function init() if (!$this->getQuery()) { throw new \RuntimeException('Uninitialized query'); } - $this->resetIterator(); + + // NEXT_MAJOR: Remove this line and uncomment the following one instead. + $this->resetIterator('sonata_deprecation_mute'); +// $this->haveToPaginate = false; if (0 === $this->getPage() || 0 === $this->getMaxPerPage()) { $this->setLastPage(0); @@ -120,7 +128,10 @@ public function init() ? $this->getMaxPerPage() * $this->threshold + 1 : $this->getMaxPerPage() + 1; $this->getQuery()->setMaxResults($maxOffset); - $this->initializeIterator(); + + // NEXT_MAJOR: Remove this line and uncomment the following one instead. + $this->initializeIterator('sonata_deprecation_mute'); +// $this->results = $this->getResults(); $t = (int) ceil($this->thresholdCount / $this->getMaxPerPage()) + $this->getPage() - 1; $this->setLastPage(max(1, $t)); @@ -145,9 +156,21 @@ public function getThreshold() return $this->threshold; } + /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x + */ protected function resetIterator() { - parent::resetIterator(); + if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { + @trigger_error(sprintf( + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + } + + parent::resetIterator('sonata_deprecation_mute'); $this->haveToPaginate = false; } } diff --git a/src/Resources/views/Block/block_stats.html.twig b/src/Resources/views/Block/block_stats.html.twig index 9a59c1f73f..8f2d78b713 100644 --- a/src/Resources/views/Block/block_stats.html.twig +++ b/src/Resources/views/Block/block_stats.html.twig @@ -17,10 +17,10 @@ file that was distributed with this source code.
    -

    {{ pager.count() }}

    +

    {{ pager.getNbResults() }}

    {% if translation_domain %} - {{ settings.text|trans({'%count%': pager.count()}, translation_domain) }} + {{ settings.text|trans({'%count%': pager.getNbResults()}, translation_domain) }} {% else %} {{ settings.text }} {% endif %} diff --git a/tests/App/Datagrid/Pager.php b/tests/App/Datagrid/Pager.php index a69bae1fb6..62946036e2 100644 --- a/tests/App/Datagrid/Pager.php +++ b/tests/App/Datagrid/Pager.php @@ -14,6 +14,7 @@ namespace Sonata\AdminBundle\Tests\App\Datagrid; use Sonata\AdminBundle\Datagrid\PagerInterface; +use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\Tests\App\Model\FooRepository; final class Pager implements PagerInterface @@ -41,40 +42,80 @@ public function setMaxPerPage($max): void { } - public function setPage($page): void + public function getPage(): int { + return 1; } - public function setQuery($query): void + public function setPage($page): void { } - public function getResults(): array + public function getNextPage(): int { - return $this->repository->all(); + return 1; } - public function setMaxPageLinks($maxPageLinks): void + public function getPreviousPage(): int { + return 1; } - public function getMaxPageLinks() + public function getFirstPage(): int { return 1; } - public function getPage() + public function isFirstPage(): bool { - return 1; + return true; } - public function isLastPage() + public function getLastPage(): int + { + return 2; + } + + public function isLastPage(): bool { return true; } + public function getQuery($query): ProxyQueryInterface + { + return new ProxyQuery(); + } + + public function setQuery($query): void + { + } + + public function haveToPaginate(): bool + { + return false; + } + + public function getResults(): array + { + return $this->repository->all(); + } + public function getNbResults() { return \count($this->getResults()); } + + public function getLinks(?int $nbLinks = null): array + { + return []; + } + + public function setMaxPageLinks($maxPageLinks): void + { + } + + public function getMaxPageLinks() + { + return 1; + } } diff --git a/tests/Datagrid/PagerTest.php b/tests/Datagrid/PagerTest.php index 9d1a214102..a4d770977b 100644 --- a/tests/Datagrid/PagerTest.php +++ b/tests/Datagrid/PagerTest.php @@ -16,12 +16,15 @@ use PHPUnit\Framework\TestCase; use Sonata\AdminBundle\Datagrid\Pager; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * @author Andrej Hudec */ class PagerTest extends TestCase { + use ExpectDeprecationTrait; + /** * @var Pager */ @@ -97,8 +100,14 @@ public function testGetMaxPerPage3(): void $this->assertSame(1, $this->pager->getPage()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetCurrentMaxLink(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCurrentMaxLink()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCurrentMaxLink()); $this->pager->getLinks(); @@ -113,8 +122,14 @@ public function testGetCurrentMaxLink(): void $this->assertSame(10, $this->pager->getCurrentMaxLink()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetMaxRecordLimit(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getMaxRecordLimit()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertFalse($this->pager->getMaxRecordLimit()); $this->pager->setMaxRecordLimit(99); @@ -130,8 +145,14 @@ public function testGetNbResults(): void $this->assertSame(100, $this->pager->getNbResults()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testCount(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::count()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(0, $this->pager->count()); $this->callMethod($this->pager, 'setNbResults', [100]); @@ -147,21 +168,36 @@ public function testGetQuery(): void $this->assertSame($query, $this->pager->getQuery()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetCountColumn(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCountColumn()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(['id'], $this->pager->getCountColumn()); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setCountColumn()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->pager->setCountColumn(['foo']); $this->assertSame(['foo'], $this->pager->getCountColumn()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testParameters(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertNull($this->pager->getParameter('foo', null)); $this->assertSame('bar', $this->pager->getParameter('foo', 'bar')); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::hasParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertFalse($this->pager->hasParameter('foo')); $this->assertSame([], $this->pager->getParameters()); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->pager->setParameter('foo', 'foo_value'); $this->assertTrue($this->pager->hasParameter('foo')); @@ -261,6 +297,11 @@ public function testHaveToPaginate(): void $this->assertTrue($this->pager->haveToPaginate()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testIterator(): void { $this->assertInstanceOf(\Iterator::class, $this->pager); @@ -291,39 +332,63 @@ public function testIterator(): void $this->assertSame($object3, $value); $this->assertSame($expectedObjects, $values); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertFalse($this->pager->valid()); $this->callMethod($this->pager, 'resetIterator'); $this->assertTrue($this->pager->valid()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testValid(): void { $this->pager ->method('getResults') ->willReturn([]); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertFalse($this->pager->valid()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testNext(): void { $this->pager ->method('getResults') ->willReturn([]); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::next()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertFalse($this->pager->next()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testKey(): void { $this->pager ->method('getResults') ->willReturn([123 => new \stdClass()]); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::key()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(123, $this->pager->key()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testCurrent(): void { $object = new \stdClass(); @@ -332,11 +397,18 @@ public function testCurrent(): void ->method('getResults') ->willReturn([$object]); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::current()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame($object, $this->pager->current()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetCursor(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCursor()); $this->pager->setCursor(0); @@ -354,6 +426,11 @@ public function testGetCursor(): void $this->assertSame(100, $this->pager->getCursor()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetObjectByCursor(): void { $object1 = new \stdClass(); @@ -397,7 +474,9 @@ public function testGetObjectByCursor(): void $this->pager->setQuery($query); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getObjectByCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame($object1, $this->pager->getObjectByCursor(1)); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCursor()); $id = 1; @@ -441,8 +520,14 @@ public function testGetPreviousPage(): void $this->assertSame(20, $this->pager->getPreviousPage()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetFirstIndex(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getFirstIndex()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getFirstIndex()); $this->pager->setMaxPerPage(0); @@ -458,8 +543,14 @@ public function testGetFirstIndex(): void $this->assertSame(22, $this->pager->getFirstIndex()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetLastIndex(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getLastIndex()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertSame(0, $this->pager->getLastIndex()); $this->pager->setMaxPerPage(0); @@ -480,8 +571,14 @@ public function testGetLastIndex(): void $this->assertSame(100, $this->pager->getLastIndex()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetNext(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getNext()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertNull($this->pager->getNext()); $object1 = new \stdClass(); @@ -538,8 +635,14 @@ public function testGetNext(): void $this->assertNull($this->pager->getNext()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testGetPrevious(): void { + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getPrevious()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->assertNull($this->pager->getPrevious()); $object1 = new \stdClass(); @@ -596,9 +699,15 @@ public function testGetPrevious(): void $this->assertNull($this->pager->getPrevious()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testSerialize(): void { $pagerClone = clone $this->pager; + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::serialize()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $data = $this->pager->serialize(); $this->assertNotEmpty($data); @@ -612,6 +721,11 @@ public function testSerialize(): void $this->assertSame($pagerClone->getMaxPageLinks(), $this->pager->getMaxPageLinks()); } + /** + * NEXT_MAJOR: Remove this test. + * + * @group legacy + */ public function testUnserialize(): void { $serialized = [ @@ -632,6 +746,7 @@ public function testUnserialize(): void ->willReturn([]); $this->pager->current(); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::unserialize()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); $this->pager->unserialize(serialize($serialized)); $this->assertSame(7, $this->pager->getMaxPerPage()); From d4f8f034e20af3eb68f17fe6549086c95d652193 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 17 Dec 2020 00:13:57 +0100 Subject: [PATCH 16/30] Fix --- src/Admin/AbstractAdmin.php | 25 +++---------------- .../Admin/AbstractTaggedAdmin.php | 4 +-- .../Handler/AclSecurityHandlerInterface.php | 2 ++ .../Handler/SecurityHandlerInterface.php | 2 +- src/Util/AdminObjectAclData.php | 3 +++ 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 03fa318941..be238eeead 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -20,7 +20,6 @@ use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Datagrid\ProxyQueryInterface; use Sonata\AdminBundle\DependencyInjection\Admin\AbstractTaggedAdmin; -use Sonata\AdminBundle\Exporter\DataSourceInterface; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Form\Type\ModelHiddenType; use Sonata\AdminBundle\Manipulator\ObjectManipulator; @@ -381,20 +380,9 @@ public function getDataSourceIterator(): SourceIteratorInterface // $fields[$key] = $field; } - if ($this->getDataSource()) { - $query = $datagrid->getQuery(); + $query = $datagrid->getQuery(); - return $this->getDataSource()->createIterator($query, $fields); - } - - @trigger_error(sprintf( - 'Using "%s()" without setting a "%s" instance in the admin is deprecated since sonata-project/admin-bundle 3.79' - .' and won\'t be possible in 4.0.', - __METHOD__, - DataSourceInterface::class - ), E_USER_DEPRECATED); - - return $this->getModelManager()->getDataSourceIterator($datagrid, $fields); + return $this->getDataSource()->createIterator($query, $fields); } /** @@ -819,11 +807,6 @@ public function getIdParameter(): string public function hasRoute(string $name): bool { - // NEXT_MAJOR: Remove this check. - if (!$this->routeGenerator) { - throw new \RuntimeException('RouteGenerator cannot be null'); - } - return $this->getRouteGenerator()->hasAdminRoute($this, $name); } @@ -860,12 +843,12 @@ public function generateObjectUrl(string $name, object $object, array $parameter public function generateUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): string { - return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); + return $this->getRouteGenerator()->generateUrl($this, $name, $parameters, $referenceType); } public function generateMenuUrl(string $name, array $parameters = [], int $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH): array { - return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); + return $this->getRouteGenerator()->generateMenuUrl($this, $name, $parameters, $referenceType); } final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index 48a68f8cf4..3ab94d684d 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -254,7 +254,7 @@ public function getManagerType(): string /** * @final since sonata-admin/admin-bundle 3.x * - * @param array $information + * @param array $information */ public function setSecurityInformation(array $information): void { @@ -264,7 +264,7 @@ public function setSecurityInformation(array $information): void /** * @final since sonata-admin/admin-bundle 3.x * - * @return array + * @return array */ public function getSecurityInformation(): array { diff --git a/src/Security/Handler/AclSecurityHandlerInterface.php b/src/Security/Handler/AclSecurityHandlerInterface.php index 05b1a6d5b8..feca396062 100644 --- a/src/Security/Handler/AclSecurityHandlerInterface.php +++ b/src/Security/Handler/AclSecurityHandlerInterface.php @@ -66,6 +66,8 @@ public function addObjectOwner(MutableAclInterface $acl, ?UserSecurityIdentity $ /** * Add the object class ACE's to the object ACL. + * + * @param array $roleInformation */ public function addObjectClassAces(MutableAclInterface $acl, array $roleInformation = []): void; diff --git a/src/Security/Handler/SecurityHandlerInterface.php b/src/Security/Handler/SecurityHandlerInterface.php index 6751858a11..2b28d1b839 100644 --- a/src/Security/Handler/SecurityHandlerInterface.php +++ b/src/Security/Handler/SecurityHandlerInterface.php @@ -31,7 +31,7 @@ public function isGranted(AdminInterface $admin, $attributes, ?object $object = public function getBaseRole(AdminInterface $admin): string; /** - * @return array + * @return array */ public function buildSecurityInformation(AdminInterface $admin): array; diff --git a/src/Util/AdminObjectAclData.php b/src/Util/AdminObjectAclData.php index 8744942eef..20f89616ce 100644 --- a/src/Util/AdminObjectAclData.php +++ b/src/Util/AdminObjectAclData.php @@ -211,6 +211,9 @@ public function getSecurityHandler(): AclSecurityHandlerInterface return $securityHandler; } + /** + * @return array + */ public function getSecurityInformation(): array { return $this->getSecurityHandler()->buildSecurityInformation($this->admin); From 2cd08032fc9b348c6a9028835d5d670d71c7981a Mon Sep 17 00:00:00 2001 From: Sonata CI Date: Fri, 18 Dec 2020 07:26:25 +0000 Subject: [PATCH 17/30] DevKit updates (#6714) --- .github/workflows/lint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d222f447d0..b512335a1c 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -25,7 +25,7 @@ jobs: uses: actions/checkout@v2 - name: Run PHP-CS-Fixer - uses: docker://oskarstark/php-cs-fixer-ga:2.17.1 + uses: docker://oskarstark/php-cs-fixer-ga:2.17.2 with: args: --ansi --verbose --diff --dry-run From 2882754410e8623f676533c3512d0e3ea86f6b93 Mon Sep 17 00:00:00 2001 From: Jan Storm Date: Mon, 21 Dec 2020 15:20:48 +0100 Subject: [PATCH 18/30] Improves getting of first array element (#6722) When working with adding and removing entities from the CollectionType field, it can happen that the array index not starts with 0 but has an length > 0. This leads to an error since that index 0 is unset. So using twig first function here to handle this case. --- .../views/CRUD/Association/edit_many_to_many.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resources/views/CRUD/Association/edit_many_to_many.html.twig b/src/Resources/views/CRUD/Association/edit_many_to_many.html.twig index 329ea535c4..5312384c6e 100644 --- a/src/Resources/views/CRUD/Association/edit_many_to_many.html.twig +++ b/src/Resources/views/CRUD/Association/edit_many_to_many.html.twig @@ -17,7 +17,7 @@ file that was distributed with this source code. - {% for field_name, nested_field in form.children[0].children %} + {% for field_name, nested_field in (form.children|first).children %} {% if field_name == '_delete' %} {% else %} From 811b8e36e97f7fd2adeb99c8884591a46ddc10dc Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 23 Dec 2020 18:15:32 +0100 Subject: [PATCH 19/30] Deprecate field name setter from FieldDescriptionInterface (#6720) --- UPGRADE-3.x.md | 17 ++++++++++++++ src/Admin/BaseFieldDescription.php | 28 +++++++++++++++++++++--- src/Admin/FieldDescriptionInterface.php | 4 ++++ tests/Admin/BaseFieldDescriptionTest.php | 12 ++++++++++ 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 04fa786c6d..44201cb212 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -1,6 +1,23 @@ UPGRADE 3.x =========== +### Sonata\AdminBundle\Admin\BaseFieldDescription + +Method `__construct()` has been updated to receive the field name as argument 6: + +```php +public function __construct( + ?string $name = null, + array $options = [], + array $fieldMapping = [], + array $associationMapping = [], + array $parentAssociationMappings = [], + ?string $fieldName = null +) { +``` + +Deprecated `Sonata\AdminBundle\Admin\BaseFieldDescription::setFieldName()`. + UPGRADE FROM 3.82 to 3.83 ========================= diff --git a/src/Admin/BaseFieldDescription.php b/src/Admin/BaseFieldDescription.php index f87c888a0a..f9672e4e01 100644 --- a/src/Admin/BaseFieldDescription.php +++ b/src/Admin/BaseFieldDescription.php @@ -137,14 +137,15 @@ abstract class BaseFieldDescription implements FieldDescriptionInterface private static $fieldGetters = []; /** - * NEXT_MAJOR: Remove the null default value and restrict param type to `string`. + * NEXT_MAJOR: Remove the null default value for $name and restrict param type to `string`. */ public function __construct( ?string $name = null, array $options = [], array $fieldMapping = [], array $associationMapping = [], - array $parentAssociationMappings = [] + array $parentAssociationMappings = [], + ?string $fieldName = null ) { // NEXT_MAJOR: Remove this check and keep the else part. if (null === $name) { @@ -155,6 +156,15 @@ public function __construct( ), E_USER_DEPRECATED); } else { $this->setName($name); + + if (null === $fieldName) { + // NEXT_MAJOR: Remove this line and uncomment the following. + $fieldName = substr(strrchr('.'.$name, '.'), 1); +// $fieldName = $name; + } + + // NEXT_MAJOR: Remove 'sonata_deprecation_mute' and the phpstan-ignore. + $this->setFieldName($fieldName, 'sonata_deprecation_mute'); } $this->setOptions($options); @@ -177,8 +187,19 @@ public function __construct( // abstract protected function setAssociationMapping(array $associationMapping): void; // abstract protected function setParentAssociationMappings(array $parentAssociationMappings): void; + /** + * NEXT_MAJOR: Change the visibility to private. + */ public function setFieldName($fieldName) { + if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) { + @trigger_error(sprintf( + 'The %s() method is deprecated since sonata-project/admin-bundle 3.x' + .' and will become private in version 4.0.', + __METHOD__ + ), E_USER_DEPRECATED); + } + $this->fieldName = $fieldName; } @@ -191,8 +212,9 @@ public function setName($name) { $this->name = $name; + // NEXT_MAJOR: Remove this code since the field name will be set in the construct. if (!$this->getFieldName()) { - $this->setFieldName(substr(strrchr('.'.$name, '.'), 1)); + $this->setFieldName(substr(strrchr('.'.$name, '.'), 1), 'sonata_deprecation_mute'); } } diff --git a/src/Admin/FieldDescriptionInterface.php b/src/Admin/FieldDescriptionInterface.php index e15c484e27..698bd88b9b 100644 --- a/src/Admin/FieldDescriptionInterface.php +++ b/src/Admin/FieldDescriptionInterface.php @@ -24,6 +24,10 @@ interface FieldDescriptionInterface { /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0. + * * set the field name. * * @param string $fieldName diff --git a/tests/Admin/BaseFieldDescriptionTest.php b/tests/Admin/BaseFieldDescriptionTest.php index 486f44adf0..328df67a4a 100644 --- a/tests/Admin/BaseFieldDescriptionTest.php +++ b/tests/Admin/BaseFieldDescriptionTest.php @@ -27,6 +27,16 @@ class BaseFieldDescriptionTest extends TestCase { use ExpectDeprecationTrait; + public function testConstruct(): void + { + $description = new FieldDescription('foo.bar'); + + $this->assertSame('foo.bar', $description->getName()); + // NEXT_MAJOR: Remove this line and uncomment the following + $this->assertSame('bar', $description->getFieldName()); +// $this->assertSame('foo.bar', $description->getFieldName()); + } + public function testConstructingWithMapping(): void { $fieldMapping = ['field_name' => 'fieldName']; @@ -39,11 +49,13 @@ public function testConstructingWithMapping(): void $fieldMapping, $associationMapping, $parentAssociationMapping, + 'bar' ); $this->assertSame($fieldMapping, $description->getFieldMapping()); $this->assertSame($associationMapping, $description->getAssociationMapping()); $this->assertSame($parentAssociationMapping, $description->getParentAssociationMappings()); + $this->assertSame('bar', $description->getFieldName()); } public function testSetName(): void From 3ed173b5db86ae2b16065acd321f53c070abefe8 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 23 Dec 2020 18:37:11 +0100 Subject: [PATCH 20/30] Check for _per_page existence (#6702) --- src/Admin/AbstractAdmin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 36af1fabc6..5ae3f2ef3f 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -710,7 +710,7 @@ public function getFilterParameters() } } - if (!$this->determinedPerPageValue($parameters['_per_page'])) { + if (!isset($parameters['_per_page']) || !$this->determinedPerPageValue($parameters['_per_page'])) { $parameters['_per_page'] = $this->getMaxPerPage(); } From aeb396e9cfee095868691375dc3c353d391fdc5b Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Fri, 11 Dec 2020 01:20:21 +0100 Subject: [PATCH 21/30] Remove passing admin_pool to twig templates in next major version Since sonata-project/admin-bundle 3.83, Pool is just used as an Admin registry and for global options has been replaced by SonataConfiguration which holds those options. To access to these options from Twig, there is a global Twig sonata_config variable. So there is no need to pass an instance of Pool to Twig templates anymore, the pool is not supposed to be used directly in templates. --- src/Action/DashboardAction.php | 1 + src/Action/SearchAction.php | 1 + src/Block/AdminListBlockService.php | 1 + src/Block/AdminSearchBlockService.php | 1 + src/Block/AdminStatsBlockService.php | 1 + src/Controller/CRUDController.php | 1 + tests/Action/SearchActionTest.php | 1 + tests/Controller/CRUDControllerTest.php | 25 +++++++++++++++++++++++++ 8 files changed, 32 insertions(+) diff --git a/src/Action/DashboardAction.php b/src/Action/DashboardAction.php index a785af5760..0066e156a1 100644 --- a/src/Action/DashboardAction.php +++ b/src/Action/DashboardAction.php @@ -79,6 +79,7 @@ public function __invoke(Request $request): Response 'base_template' => $request->isXmlHttpRequest() ? $this->templateRegistry->getTemplate('ajax') : $this->templateRegistry->getTemplate('layout'), + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'blocks' => $blocks, ]; diff --git a/src/Action/SearchAction.php b/src/Action/SearchAction.php index fcab35072b..7a4a20acab 100644 --- a/src/Action/SearchAction.php +++ b/src/Action/SearchAction.php @@ -79,6 +79,7 @@ public function __invoke(Request $request): Response $this->templateRegistry->getTemplate('ajax') : $this->templateRegistry->getTemplate('layout'), 'breadcrumbs_builder' => $this->breadcrumbsBuilder, + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'query' => $request->get('q'), 'groups' => $this->pool->getDashboardGroups(), diff --git a/src/Block/AdminListBlockService.php b/src/Block/AdminListBlockService.php index 07d28d7505..60895b4028 100644 --- a/src/Block/AdminListBlockService.php +++ b/src/Block/AdminListBlockService.php @@ -125,6 +125,7 @@ public function execute(BlockContextInterface $blockContext, ?Response $response return $this->renderPrivateResponse($this->templateRegistry->getTemplate('list_block'), [ 'block' => $blockContext->getBlock(), 'settings' => $settings, + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'groups' => $visibleGroups, ], $response); diff --git a/src/Block/AdminSearchBlockService.php b/src/Block/AdminSearchBlockService.php index f87089c1e1..94d1633602 100644 --- a/src/Block/AdminSearchBlockService.php +++ b/src/Block/AdminSearchBlockService.php @@ -169,6 +169,7 @@ public function execute(BlockContextInterface $blockContext, ?Response $response return $this->renderPrivateResponse($admin->getTemplate('search_result_block'), [ 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'pager' => $pager, 'admin' => $admin, diff --git a/src/Block/AdminStatsBlockService.php b/src/Block/AdminStatsBlockService.php index d7e7d7f8f3..65d4c6cb55 100644 --- a/src/Block/AdminStatsBlockService.php +++ b/src/Block/AdminStatsBlockService.php @@ -108,6 +108,7 @@ public function execute(BlockContextInterface $blockContext, ?Response $response return $this->renderPrivateResponse($blockContext->getTemplate(), [ 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'admin' => $admin, 'pager' => $datagrid->getPager(), diff --git a/src/Controller/CRUDController.php b/src/Controller/CRUDController.php index 9538a1d017..e6a024d63f 100644 --- a/src/Controller/CRUDController.php +++ b/src/Controller/CRUDController.php @@ -1080,6 +1080,7 @@ protected function addRenderExtraParams(array $parameters = []): array $parameters['admin'] = $parameters['admin'] ?? $this->admin; $parameters['base_template'] = $parameters['base_template'] ?? $this->getBaseTemplate(); + // NEXT_MAJOR: Remove next line. $parameters['admin_pool'] = $this->get('sonata.admin.pool'); return $parameters; diff --git a/tests/Action/SearchActionTest.php b/tests/Action/SearchActionTest.php index e733a9abf4..b97ef99943 100644 --- a/tests/Action/SearchActionTest.php +++ b/tests/Action/SearchActionTest.php @@ -88,6 +88,7 @@ public function testGlobalPage(): void $this->twig->method('render')->with('search.html.twig', [ 'base_template' => 'layout.html.twig', 'breadcrumbs_builder' => $this->breadcrumbsBuilder, + // NEXT_MAJOR: Remove next line. 'admin_pool' => $this->pool, 'query' => 'some search', 'groups' => [], diff --git a/tests/Controller/CRUDControllerTest.php b/tests/Controller/CRUDControllerTest.php index a966d27b55..5e40a19cc0 100644 --- a/tests/Controller/CRUDControllerTest.php +++ b/tests/Controller/CRUDControllerTest.php @@ -544,6 +544,7 @@ public function testRender(): void ); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('@FooAdmin/foo.html.twig', $this->template); } @@ -559,6 +560,7 @@ public function testRenderWithResponse(): void $this->assertSame('bar', $responseResult->headers->get('X-foo')); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('@FooAdmin/foo.html.twig', $this->template); } @@ -576,6 +578,7 @@ public function testRenderCustomParams(): void ); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('bar', $this->parameters['foo']); $this->assertSame('@FooAdmin/foo.html.twig', $this->template); @@ -595,6 +598,7 @@ public function testRenderAjax(): void ); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('bar', $this->parameters['foo']); $this->assertSame('@FooAdmin/foo.html.twig', $this->template); @@ -667,6 +671,7 @@ public function testListAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('list', $this->parameters['action']); @@ -831,6 +836,7 @@ public function testShowAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('show', $this->parameters['action']); @@ -981,6 +987,7 @@ public function testDeleteAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('delete', $this->parameters['action']); @@ -1071,6 +1078,7 @@ public function testDeleteActionNoCsrfToken(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('delete', $this->parameters['action']); @@ -1329,6 +1337,7 @@ public function testDeleteActionWrongRequestMethod(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('delete', $this->parameters['action']); @@ -1482,6 +1491,7 @@ public function testEditAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('edit', $this->parameters['action']); @@ -1603,6 +1613,7 @@ public function testEditActionError(string $expectedToStringValue, string $toStr $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('edit', $this->parameters['action']); @@ -1764,6 +1775,7 @@ public function testEditActionAjaxErrorWithoutAcceptApplicationJson(): void $this->assertInstanceOf(Response::class, $response = $this->controller->editAction(null)); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('edit', $this->parameters['action']); $this->assertInstanceOf(FormView::class, $this->parameters['form']); @@ -1831,6 +1843,7 @@ public function testEditActionWithModelManagerException(string $expectedToString $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('edit', $this->parameters['action']); @@ -1885,6 +1898,7 @@ public function testEditActionWithPreview(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('edit', $this->parameters['action']); @@ -2027,6 +2041,7 @@ public function testCreateAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('create', $this->parameters['action']); @@ -2221,6 +2236,7 @@ public function testCreateActionError(string $expectedToStringValue, string $toS $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('create', $this->parameters['action']); @@ -2290,6 +2306,7 @@ public function testCreateActionWithModelManagerException(string $expectedToStri $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('create', $this->parameters['action']); @@ -2472,6 +2489,7 @@ public function testCreateActionAjaxErrorWithoutAcceptApplicationJson(): void $this->assertInstanceOf(Response::class, $response = $this->controller->createAction()); $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/ajax_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('create', $this->parameters['action']); $this->assertInstanceOf(FormView::class, $this->parameters['form']); @@ -2530,6 +2548,7 @@ public function testCreateActionWithPreview(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('create', $this->parameters['action']); @@ -2699,6 +2718,7 @@ public function testHistoryAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('history', $this->parameters['action']); @@ -2845,6 +2865,7 @@ public function testAclAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('acl', $this->parameters['action']); @@ -2933,6 +2954,7 @@ public function testAclActionInvalidUpdate(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('acl', $this->parameters['action']); @@ -3188,6 +3210,7 @@ public function testHistoryViewRevisionAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('show', $this->parameters['action']); @@ -3408,6 +3431,7 @@ public function testHistoryCompareRevisionsActionAction(): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('show', $this->parameters['action']); @@ -3661,6 +3685,7 @@ public function testBatchActionWithConfirmation(array $data): void $this->assertSame($this->admin, $this->parameters['admin']); $this->assertSame('@SonataAdmin/standard_layout.html.twig', $this->parameters['base_template']); + // NEXT_MAJOR: Remove next line. $this->assertSame($this->pool, $this->parameters['admin_pool']); $this->assertSame('list', $this->parameters['action']); From 434b1c3a5f51f5103c2684a11ddcbfcd5aafad18 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Thu, 24 Dec 2020 16:26:17 +0100 Subject: [PATCH 22/30] Add RouteCollectionInterface (#6699) This interface was added in 4.x branch, this commit imports it removing type and return declarations to make it compatible with RouteCollection which implements this interface. In sonata 4 AbstractAdmin::configureRoutes() method receives a RouteCollectionInterface, importing this interface in 3.x would allow users to update their code and define this method as in 4 easing the upgrading process. --- UPGRADE-3.x.md | 38 ++++++++ src/Route/RouteCollection.php | 2 +- src/Route/RouteCollectionInterface.php | 130 +++++++++++++++++++++++++ 3 files changed, 169 insertions(+), 1 deletion(-) create mode 100644 src/Route/RouteCollectionInterface.php diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 44201cb212..fb3181bda6 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -1,6 +1,44 @@ UPGRADE 3.x =========== +UPGRADE FROM 3.xx to 3.xx +========================= + +### `RouteCollection` now implements `RouteCollectionInterface` + +In 4.0, `AbstractAdmin::configureRoutes` and `AdminExtensionInterface::configureRoutes` will receive a +`RouteCollectionInterface` instance instead of a `RouteCollection` instance, you can update your code before ugprading +to 4.0. + +Before: +```php +use Sonata\AdminBundle\Admin\AbstractAdmin; +use Sonata\AdminBundle\Route\RouteCollection; + +final class MyAdmin extends AbstractAdmin +{ + protected function configureRoutes(RouteCollection $collection): void + { + $collection->add('my_route'); + } +} +``` + +After: +```php +use Sonata\AdminBundle\Admin\AbstractAdmin; +use Sonata\AdminBundle\Route\RouteCollectionInterface; + +final class MyAdmin extends AbstractAdmin +{ + protected function configureRoutes(RouteCollectionInterface $collection): void + { + $collection->add('my_route'); + } +} +``` +This only will work with PHP >= 7.4, where fully support to contravariance was added. + ### Sonata\AdminBundle\Admin\BaseFieldDescription Method `__construct()` has been updated to receive the field name as argument 6: diff --git a/src/Route/RouteCollection.php b/src/Route/RouteCollection.php index a0456b8dcf..bca5139280 100644 --- a/src/Route/RouteCollection.php +++ b/src/Route/RouteCollection.php @@ -20,7 +20,7 @@ * * @author Thomas Rabaix */ -class RouteCollection +class RouteCollection implements RouteCollectionInterface { /** * @var array diff --git a/src/Route/RouteCollectionInterface.php b/src/Route/RouteCollectionInterface.php new file mode 100644 index 0000000000..4986b71be3 --- /dev/null +++ b/src/Route/RouteCollectionInterface.php @@ -0,0 +1,130 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Route; + +use Symfony\Component\Routing\Route; + +/** + * @author Jordi Sala + */ +interface RouteCollectionInterface +{ + /** + * @param string $name + * @param string $pattern Pattern (will be automatically combined with @see $this->baseRoutePattern and $name + * @param string $host + * @param string $condition + * + * @return RouteCollection + */ + public function add( + $name, + $pattern = null, + array $defaults = [], + array $requirements = [], + array $options = [], + $host = '', + array $schemes = [], + array $methods = [], + $condition = '' + ); + + /** + * @return string + */ + public function getCode(string $name); + + /** + * @return $this + */ + public function addCollection(RouteCollection $collection); + + /** + * @return Route[] + */ + public function getElements(); + + /** + * @param string $name + * + * @return bool + */ + public function has($name); + + public function hasCached(string $name): bool; + + /** + * @param string $name + * + * @throws \InvalidArgumentException + * + * @return Route + */ + public function get($name); + + /** + * @return $this + */ + public function remove(string $name); + + /** + * @throws \InvalidArgumentException + * + * @return $this + */ + public function restore(string $name); + + /** + * Remove all routes except routes in $routeList. + * + * @param string[]|string $routeList + * + * @return $this + */ + public function clearExcept($routeList); + + /** + * @return $this + */ + public function clear(); + + /** + * Converts a word into the format required for a controller action. By instance, + * the argument "list_something" returns "listSomething" if the associated controller is not an action itself, + * otherwise, it will return "listSomethingAction". + * + * @return string + */ + public function actionify(string $action); + + /** + * @return string + */ + public function getBaseCodeRoute(); + + /** + * @return string + */ + public function getBaseControllerName(); + + /** + * @return string + */ + public function getBaseRouteName(); + + /** + * @return string + */ + public function getBaseRoutePattern(); +} From 3a68fcc8485617b1f8f2f848174a61b115dfada9 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 31 Dec 2020 17:51:44 +0100 Subject: [PATCH 23/30] Fix form label in next major (#6718) --- src/Form/FormMapper.php | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/Form/FormMapper.php b/src/Form/FormMapper.php index a2bda7372c..3f91bb099e 100644 --- a/src/Form/FormMapper.php +++ b/src/Form/FormMapper.php @@ -93,9 +93,7 @@ public function add($name, $type = null, array $options = [], array $fieldDescri $type = CollectionType::class; } - $label = $fieldName; - - $group = $this->addFieldToCurrentGroup($label); + $group = $this->addFieldToCurrentGroup($fieldName); // Try to autodetect type if ($name instanceof FormBuilderInterface && null === $type) { @@ -124,10 +122,11 @@ public function add($name, $type = null, array $options = [], array $fieldDescri } if ($name instanceof FormBuilderInterface) { + $child = $name; $type = null; $options = []; } else { - $name = $fieldDescription->getName(); + $child = $fieldDescription->getName(); // Note that the builder var is actually the formContractor: $options = array_replace_recursive( @@ -142,7 +141,17 @@ public function add($name, $type = null, array $options = [], array $fieldDescri } if (!isset($options['label'])) { - $options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($name, 'form', 'label'); + /* + * NEXT_MAJOR: Replace $child by $name in the next line. + * And add the following BC-break in the upgrade note: + * + * The form label are now correctly using the label translator strategy + * for field with `.` (which won't be replaced by `__`). For instance, + * with the underscore label strategy, the label `foo.barBaz` was + * previously `form.label_foo__bar_baz` and now is `form.label_foo_bar_baz` + * to be consistent with others labels like `show.label_foo_bar_baz`. + */ + $options['label'] = $this->admin->getLabelTranslatorStrategy()->getLabel($child, 'form', 'label'); } // NEXT_MAJOR: Remove this block. @@ -162,7 +171,7 @@ public function add($name, $type = null, array $options = [], array $fieldDescri } $this->admin->addFormFieldDescription($fieldName, $fieldDescription); - $this->formBuilder->add($name, $type, $options); + $this->formBuilder->add($child, $type, $options); return $this; } From 9dfe86385f6fef534534985ff33c78b8ab92112d Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Fri, 1 Jan 2021 14:14:44 +0100 Subject: [PATCH 24/30] Remove public access for getFieldValue (#6716) --- UPGRADE-3.x.md | 4 ++++ src/Admin/BaseFieldDescription.php | 10 ++++++++++ src/Admin/FieldDescriptionInterface.php | 10 +++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index fb3181bda6..813b48baa0 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -4,6 +4,10 @@ UPGRADE 3.x UPGRADE FROM 3.xx to 3.xx ========================= +### Deprecated `FieldDescriptionInterface::getFieldValue()` + +`BaseFieldDescription::getFieldValue()` will become protected. + ### `RouteCollection` now implements `RouteCollectionInterface` In 4.0, `AbstractAdmin::configureRoutes` and `AdminExtensionInterface::configureRoutes` will receive a diff --git a/src/Admin/BaseFieldDescription.php b/src/Admin/BaseFieldDescription.php index f9672e4e01..431babffa8 100644 --- a/src/Admin/BaseFieldDescription.php +++ b/src/Admin/BaseFieldDescription.php @@ -381,6 +381,16 @@ public function hasAssociationAdmin() return null !== $this->associationAdmin; } + /** + * NEXT_MAJOR: Change the visibility to protected. + * + * @param object|null $object + * @param string $fieldName + * + * @throws NoValueException + * + * @return mixed + */ public function getFieldValue($object, $fieldName) { if ($this->isVirtual() || null === $object) { diff --git a/src/Admin/FieldDescriptionInterface.php b/src/Admin/FieldDescriptionInterface.php index 698bd88b9b..bac91a7a0a 100644 --- a/src/Admin/FieldDescriptionInterface.php +++ b/src/Admin/FieldDescriptionInterface.php @@ -13,6 +13,8 @@ namespace Sonata\AdminBundle\Admin; +use Sonata\AdminBundle\Exception\NoValueException; + /** * @author Thomas Rabaix * @@ -228,7 +230,9 @@ public function isIdentifier(); * * @param object $object * - * @return bool|mixed + * @throws NoValueException if the value cannot be determined + * + * @return mixed */ public function getValue($object); @@ -314,6 +318,10 @@ public function getSortFieldMapping(); public function getSortParentAssociationMapping(); /** + * NEXT_MAJOR: Remove this method from the interface. + * + * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. + * * @param object|null $object * @param string $fieldName * From 1bcbbca17203c03e8358979febac0ba79c819634 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 16 Dec 2020 23:16:35 +0100 Subject: [PATCH 25/30] Move getListModes into TaggedAdminInterface --- src/Admin/AbstractAdmin.php | 5 ----- src/Admin/AdminInterface.php | 5 ----- src/DependencyInjection/Admin/AbstractTaggedAdmin.php | 8 ++++++++ src/DependencyInjection/Admin/TaggedAdminInterface.php | 5 +++++ 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 5ae3f2ef3f..322f464982 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -2587,11 +2587,6 @@ public function getObjectMetadata($object) return new Metadata($this->toString($object)); } - public function getListModes() - { - return $this->listModes; - } - public function setListMode($mode) { if (!$this->hasRequest()) { diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 1e131f020b..434b960af7 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -698,11 +698,6 @@ public function getTranslationLabel($label, $context = '', $type = ''); */ public function getObjectMetadata($object); - /** - * @return array> - */ - public function getListModes(); - /** * Check the current request is given route or not. * diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index 4d26d42334..d02f321b95 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -261,6 +261,14 @@ final public function showMosaicButton($isShown) } } + /** + * @final since sonata-admin/admin-bundle 3.x + */ + public function getListModes() + { + return $this->listModes; + } + /** * @final since sonata-admin/admin-bundle 3.x */ diff --git a/src/DependencyInjection/Admin/TaggedAdminInterface.php b/src/DependencyInjection/Admin/TaggedAdminInterface.php index 10f04574dc..9c394cc24f 100644 --- a/src/DependencyInjection/Admin/TaggedAdminInterface.php +++ b/src/DependencyInjection/Admin/TaggedAdminInterface.php @@ -91,6 +91,11 @@ public function getLabel(); */ // public function showMosaicButton(bool $isShown): void; + /** + * @return array> + */ + public function getListModes(); + /** * NEXT_MAJOR: Uncomment this method. */ From a4f187fe6097155c1e4d6db08958150a27c14e2f Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 16 Dec 2020 23:19:50 +0100 Subject: [PATCH 26/30] Update 3.x comments --- src/Admin/AbstractAdmin.php | 4 +- src/Admin/AdminInterface.php | 2 +- src/Datagrid/Pager.php | 130 +++++++++--------- src/Datagrid/SimplePager.php | 4 +- .../Admin/AbstractTaggedAdmin.php | 96 ++++++------- src/Filter/Filter.php | 10 +- src/Util/FormBuilderIterator.php | 2 +- tests/Datagrid/PagerTest.php | 44 +++--- tests/Util/FormBuilderIteratorTest.php | 2 +- 9 files changed, 147 insertions(+), 147 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 322f464982..0e4df15c26 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -525,7 +525,7 @@ public function validate(ErrorElement $errorElement, $object) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function initialize() { @@ -2122,7 +2122,7 @@ public function getClassnameLabel() if (null === $this->classnameLabel) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no classname label is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no classname label is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 434b960af7..5897a2d9e6 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -382,7 +382,7 @@ public function getDataSourceIterator(); /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-admin/admin-bundle 3.x + * @deprecated since sonata-admin/admin-bundle 3.84 * * @return void */ diff --git a/src/Datagrid/Pager.php b/src/Datagrid/Pager.php index 6f5d32b4fc..89b9862e8c 100644 --- a/src/Datagrid/Pager.php +++ b/src/Datagrid/Pager.php @@ -47,7 +47,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @var int */ @@ -56,7 +56,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @var array */ @@ -65,7 +65,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @var int */ @@ -74,7 +74,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @var mixed bool|int */ @@ -88,7 +88,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Used by iterator interface * @@ -99,7 +99,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Used by iterator interface * @@ -115,7 +115,7 @@ abstract class Pager implements \Iterator, \Countable, \Serializable, PagerInter /** * NEXT_MAJOR: Remove this property. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @var string[] */ @@ -132,7 +132,7 @@ public function __construct($maxPerPage = 10) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the current pager's max link. * @@ -141,7 +141,7 @@ public function __construct($maxPerPage = 10) public function getCurrentMaxLink() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -151,7 +151,7 @@ public function getCurrentMaxLink() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the current pager's max record limit. * @@ -160,7 +160,7 @@ public function getCurrentMaxLink() public function getMaxRecordLimit() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -170,7 +170,7 @@ public function getMaxRecordLimit() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Sets the current pager's max record limit. * @@ -179,7 +179,7 @@ public function getMaxRecordLimit() public function setMaxRecordLimit($limit) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -228,7 +228,7 @@ public function haveToPaginate() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the current cursor. * @@ -237,7 +237,7 @@ public function haveToPaginate() public function getCursor() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -247,7 +247,7 @@ public function getCursor() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Sets the current cursor. * @@ -256,7 +256,7 @@ public function getCursor() public function setCursor($pos) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -274,7 +274,7 @@ public function setCursor($pos) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns an object by cursor position. * @@ -285,7 +285,7 @@ public function setCursor($pos) public function getObjectByCursor($pos) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -297,7 +297,7 @@ public function getObjectByCursor($pos) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the current object. * @@ -306,7 +306,7 @@ public function getObjectByCursor($pos) public function getCurrent() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -316,7 +316,7 @@ public function getCurrent() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the next object. * @@ -325,7 +325,7 @@ public function getCurrent() public function getNext() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -339,7 +339,7 @@ public function getNext() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the previous object. * @@ -348,7 +348,7 @@ public function getNext() public function getPrevious() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -362,7 +362,7 @@ public function getPrevious() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the first index on the current page. * @@ -371,7 +371,7 @@ public function getPrevious() public function getFirstIndex() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -401,7 +401,7 @@ public function getFirstIndice() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the last index on the current page. * @@ -410,7 +410,7 @@ public function getFirstIndice() public function getLastIndex() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -556,7 +556,7 @@ public function isLastPage() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns the current pager's parameter holder. * @@ -565,7 +565,7 @@ public function isLastPage() public function getParameters() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -575,7 +575,7 @@ public function getParameters() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns a parameter. * @@ -587,7 +587,7 @@ public function getParameters() public function getParameter($name, $default = null) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -597,7 +597,7 @@ public function getParameter($name, $default = null) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Checks whether a parameter has been set. * @@ -608,7 +608,7 @@ public function getParameter($name, $default = null) public function hasParameter($name) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -618,7 +618,7 @@ public function hasParameter($name) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Sets a parameter. * @@ -628,7 +628,7 @@ public function hasParameter($name) public function setParameter($name, $value) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -638,12 +638,12 @@ public function setParameter($name, $value) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function current() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -657,12 +657,12 @@ public function current() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function key() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -676,12 +676,12 @@ public function key() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function next() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -698,12 +698,12 @@ public function next() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function rewind() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -720,12 +720,12 @@ public function rewind() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function valid() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -739,12 +739,12 @@ public function valid() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x, use getNbResults instead + * @deprecated since sonata-project/admin-bundle 3.84, use getNbResults instead */ public function count() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -754,12 +754,12 @@ public function count() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function serialize() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -772,12 +772,12 @@ public function serialize() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ public function unserialize($serialized) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -791,14 +791,14 @@ public function unserialize($serialized) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @return string[] */ public function getCountColumn() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -808,14 +808,14 @@ public function getCountColumn() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * @return string[] */ public function setCountColumn(array $countColumn) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -863,7 +863,7 @@ protected function setLastPage($page) /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Returns true if the properties used for iteration have been initialized. * @@ -872,7 +872,7 @@ protected function setLastPage($page) protected function isIteratorInitialized() { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); @@ -882,7 +882,7 @@ protected function isIteratorInitialized() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Loads data into properties used for iteration. * @@ -892,7 +892,7 @@ protected function initializeIterator() { if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); } @@ -904,7 +904,7 @@ protected function initializeIterator() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Empties properties used for iteration. * @@ -914,7 +914,7 @@ protected function resetIterator() { if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); } @@ -926,7 +926,7 @@ protected function resetIterator() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 * * Retrieve the object for a certain offset. * @@ -937,7 +937,7 @@ protected function resetIterator() protected function retrieveObject($offset) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); diff --git a/src/Datagrid/SimplePager.php b/src/Datagrid/SimplePager.php index d08e154c99..81e1617cb2 100644 --- a/src/Datagrid/SimplePager.php +++ b/src/Datagrid/SimplePager.php @@ -159,13 +159,13 @@ public function getThreshold() /** * NEXT_MAJOR: Remove this method. * - * @deprecated since sonata-project/admin-bundle 3.x + * @deprecated since sonata-project/admin-bundle 3.84 */ protected function resetIterator() { if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { @trigger_error(sprintf( - 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.', + 'The method "%s()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.', __METHOD__ ), E_USER_DEPRECATED); } diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index d02f321b95..31a885ecf2 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -227,7 +227,7 @@ public function __construct($code, $class, $baseControllerName = null) if (!\is_string($baseControllerName)) { @trigger_error(sprintf( 'Passing other type than string as argument 3 for method %s() is deprecated since' - .' sonata-project/admin-bundle 3.x. It will accept only string in version 4.0.', + .' sonata-project/admin-bundle 3.84. It will accept only string in version 4.0.', __METHOD__ ), E_USER_DEPRECATED); } @@ -237,7 +237,7 @@ public function __construct($code, $class, $baseControllerName = null) abstract public function initialize(); /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setLabel($label) { @@ -245,7 +245,7 @@ public function setLabel($label) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getLabel() { @@ -262,7 +262,7 @@ final public function showMosaicButton($isShown) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getListModes() { @@ -270,7 +270,7 @@ public function getListModes() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setPagerType($pagerType) { @@ -278,7 +278,7 @@ public function setPagerType($pagerType) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 * * @return string */ @@ -288,7 +288,7 @@ public function getPagerType() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setManagerType($type) { @@ -296,14 +296,14 @@ public function setManagerType($type) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getManagerType() { if (null === $this->managerType) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no manager type is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no manager type is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -317,7 +317,7 @@ public function getManagerType() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setSecurityInformation(array $information) { @@ -325,7 +325,7 @@ public function setSecurityInformation(array $information) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getSecurityInformation() { @@ -333,7 +333,7 @@ public function getSecurityInformation() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setFilterPersister(?FilterPersisterInterface $filterPersister = null) { @@ -357,7 +357,7 @@ final public function hasFilterPersister(): bool } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setModelManager(ModelManagerInterface $modelManager) { @@ -365,14 +365,14 @@ public function setModelManager(ModelManagerInterface $modelManager) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getModelManager() { if (null === $this->modelManager) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no model manager is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no model manager is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -386,7 +386,7 @@ public function getModelManager() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setDataSource(DataSourceInterface $dataSource) { @@ -401,7 +401,7 @@ public function getDataSource(): ?DataSourceInterface if (null === $this->dataSource) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no data source is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no data source is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -415,7 +415,7 @@ public function getDataSource(): ?DataSourceInterface } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setFormContractor(FormContractorInterface $formBuilder) { @@ -423,14 +423,14 @@ public function setFormContractor(FormContractorInterface $formBuilder) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getFormContractor() { if (null === $this->formContractor) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no form contractor is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no form contractor is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -444,7 +444,7 @@ public function getFormContractor() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setShowBuilder(ShowBuilderInterface $showBuilder) { @@ -452,14 +452,14 @@ public function setShowBuilder(ShowBuilderInterface $showBuilder) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getShowBuilder() { if (null === $this->showBuilder) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no show builder is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no show builder is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -473,7 +473,7 @@ public function getShowBuilder() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setListBuilder(ListBuilderInterface $listBuilder) { @@ -481,14 +481,14 @@ public function setListBuilder(ListBuilderInterface $listBuilder) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getListBuilder() { if (null === $this->listBuilder) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no list build is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no list build is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -502,7 +502,7 @@ public function getListBuilder() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) { @@ -510,14 +510,14 @@ public function setDatagridBuilder(DatagridBuilderInterface $datagridBuilder) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getDatagridBuilder() { if (null === $this->datagridBuilder) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no datagrid builder is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no datagrid builder is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -546,7 +546,7 @@ public function getTranslator() if (null === $this->translator) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no translator is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no translator is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -560,7 +560,7 @@ public function getTranslator() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setConfigurationPool(Pool $configurationPool) { @@ -568,7 +568,7 @@ public function setConfigurationPool(Pool $configurationPool) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getConfigurationPool() { @@ -576,7 +576,7 @@ public function getConfigurationPool() // NEXT_MAJOR: Remove this deprecation and uncomment the following exception if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) { @trigger_error(sprintf( - 'Calling %s() when no pool is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no pool is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -591,7 +591,7 @@ public function getConfigurationPool() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) { @@ -599,14 +599,14 @@ public function setRouteGenerator(RouteGeneratorInterface $routeGenerator) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getRouteGenerator() { if (null === $this->routeGenerator) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no route generator is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no route generator is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -653,7 +653,7 @@ public function getValidator() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setSecurityHandler(SecurityHandlerInterface $securityHandler) { @@ -661,14 +661,14 @@ public function setSecurityHandler(SecurityHandlerInterface $securityHandler) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getSecurityHandler() { if (null === $this->securityHandler) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -682,7 +682,7 @@ public function getSecurityHandler() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setMenuFactory(FactoryInterface $menuFactory) { @@ -690,14 +690,14 @@ public function setMenuFactory(FactoryInterface $menuFactory) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getMenuFactory() { if (null === $this->menuFactory) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no security handler is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -711,7 +711,7 @@ public function getMenuFactory() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setRouteBuilder(RouteBuilderInterface $routeBuilder) { @@ -719,14 +719,14 @@ public function setRouteBuilder(RouteBuilderInterface $routeBuilder) } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getRouteBuilder() { if (null === $this->routeBuilder) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no route builder is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no route builder is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); @@ -740,7 +740,7 @@ public function getRouteBuilder() } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $labelTranslatorStrategy) { @@ -748,14 +748,14 @@ public function setLabelTranslatorStrategy(LabelTranslatorStrategyInterface $lab } /** - * @final since sonata-admin/admin-bundle 3.x + * @final since sonata-admin/admin-bundle 3.84 */ public function getLabelTranslatorStrategy() { if (null === $this->labelTranslatorStrategy) { // NEXT_MAJOR: Remove this deprecation and uncomment the following exception @trigger_error(sprintf( - 'Calling %s() when no label translator strategy is set is deprecated since sonata-project/admin-bundle 3.x' + 'Calling %s() when no label translator strategy is set is deprecated since sonata-project/admin-bundle 3.84' .' and will throw a LogicException in 4.0', __METHOD__, ), E_USER_DEPRECATED); diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index 3a3eef4e9b..f18c523100 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -30,7 +30,7 @@ abstract class Filter implements FilterInterface * * @var mixed|null * - * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. + * @deprecated since sonata-project/admin-bundle 3.84, to be removed in 4.0. */ protected $value; @@ -194,12 +194,12 @@ public function getOptions() * * @param mixed $value * - * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. + * @deprecated since sonata-project/admin-bundle 3.84, to be removed in 4.0. */ public function setValue($value) { @trigger_error(sprintf( - 'Method %s() is deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0.', + 'Method %s() is deprecated since sonata-project/admin-bundle 3.84 and will be removed in version 4.0.', __METHOD__, ), E_USER_DEPRECATED); @@ -211,12 +211,12 @@ public function setValue($value) * * @return mixed * - * @deprecated since sonata-project/admin-bundle 3.x, to be removed in 4.0. + * @deprecated since sonata-project/admin-bundle 3.84, to be removed in 4.0. */ public function getValue() { @trigger_error(sprintf( - 'Method %s() is deprecated since sonata-project/admin-bundle 3.x and will be removed in version 4.0.', + 'Method %s() is deprecated since sonata-project/admin-bundle 3.84 and will be removed in version 4.0.', __METHOD__, ), E_USER_DEPRECATED); diff --git a/src/Util/FormBuilderIterator.php b/src/Util/FormBuilderIterator.php index 3c97587bc5..5d45dda05a 100644 --- a/src/Util/FormBuilderIterator.php +++ b/src/Util/FormBuilderIterator.php @@ -61,7 +61,7 @@ public function __construct(FormBuilderInterface $formBuilder, $prefix = null) if (null !== $prefix && !\is_string($prefix)) { @trigger_error(sprintf( 'Passing other type than string or null as argument 2 for method %s() is deprecated since' - .' sonata-project/admin-bundle 3.x. It will accept only string and null in version 4.0.', + .' sonata-project/admin-bundle 3.84. It will accept only string and null in version 4.0.', __METHOD__ ), E_USER_DEPRECATED); } diff --git a/tests/Datagrid/PagerTest.php b/tests/Datagrid/PagerTest.php index a4d770977b..37e9247deb 100644 --- a/tests/Datagrid/PagerTest.php +++ b/tests/Datagrid/PagerTest.php @@ -107,7 +107,7 @@ public function testGetMaxPerPage3(): void */ public function testGetCurrentMaxLink(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCurrentMaxLink()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCurrentMaxLink()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCurrentMaxLink()); $this->pager->getLinks(); @@ -129,7 +129,7 @@ public function testGetCurrentMaxLink(): void */ public function testGetMaxRecordLimit(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getMaxRecordLimit()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getMaxRecordLimit()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertFalse($this->pager->getMaxRecordLimit()); $this->pager->setMaxRecordLimit(99); @@ -152,7 +152,7 @@ public function testGetNbResults(): void */ public function testCount(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::count()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::count()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(0, $this->pager->count()); $this->callMethod($this->pager, 'setNbResults', [100]); @@ -175,10 +175,10 @@ public function testGetQuery(): void */ public function testGetCountColumn(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCountColumn()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCountColumn()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(['id'], $this->pager->getCountColumn()); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setCountColumn()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setCountColumn()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->pager->setCountColumn(['foo']); $this->assertSame(['foo'], $this->pager->getCountColumn()); } @@ -190,14 +190,14 @@ public function testGetCountColumn(): void */ public function testParameters(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getParameter()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertNull($this->pager->getParameter('foo', null)); $this->assertSame('bar', $this->pager->getParameter('foo', 'bar')); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::hasParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::hasParameter()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertFalse($this->pager->hasParameter('foo')); $this->assertSame([], $this->pager->getParameters()); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setParameter()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::setParameter()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->pager->setParameter('foo', 'foo_value'); $this->assertTrue($this->pager->hasParameter('foo')); @@ -332,7 +332,7 @@ public function testIterator(): void $this->assertSame($object3, $value); $this->assertSame($expectedObjects, $values); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertFalse($this->pager->valid()); $this->callMethod($this->pager, 'resetIterator'); @@ -350,7 +350,7 @@ public function testValid(): void ->method('getResults') ->willReturn([]); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::valid()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertFalse($this->pager->valid()); } @@ -365,7 +365,7 @@ public function testNext(): void ->method('getResults') ->willReturn([]); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::next()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::next()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertFalse($this->pager->next()); } @@ -380,7 +380,7 @@ public function testKey(): void ->method('getResults') ->willReturn([123 => new \stdClass()]); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::key()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::key()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(123, $this->pager->key()); } @@ -397,7 +397,7 @@ public function testCurrent(): void ->method('getResults') ->willReturn([$object]); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::current()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::current()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame($object, $this->pager->current()); } @@ -408,7 +408,7 @@ public function testCurrent(): void */ public function testGetCursor(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCursor()); $this->pager->setCursor(0); @@ -474,9 +474,9 @@ public function testGetObjectByCursor(): void $this->pager->setQuery($query); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getObjectByCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getObjectByCursor()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame($object1, $this->pager->getObjectByCursor(1)); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getCursor()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getCursor()); $id = 1; @@ -527,7 +527,7 @@ public function testGetPreviousPage(): void */ public function testGetFirstIndex(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getFirstIndex()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getFirstIndex()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(1, $this->pager->getFirstIndex()); $this->pager->setMaxPerPage(0); @@ -550,7 +550,7 @@ public function testGetFirstIndex(): void */ public function testGetLastIndex(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getLastIndex()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getLastIndex()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertSame(0, $this->pager->getLastIndex()); $this->pager->setMaxPerPage(0); @@ -578,7 +578,7 @@ public function testGetLastIndex(): void */ public function testGetNext(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getNext()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getNext()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertNull($this->pager->getNext()); $object1 = new \stdClass(); @@ -642,7 +642,7 @@ public function testGetNext(): void */ public function testGetPrevious(): void { - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getPrevious()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::getPrevious()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->assertNull($this->pager->getPrevious()); $object1 = new \stdClass(); @@ -707,7 +707,7 @@ public function testGetPrevious(): void public function testSerialize(): void { $pagerClone = clone $this->pager; - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::serialize()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::serialize()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $data = $this->pager->serialize(); $this->assertNotEmpty($data); @@ -746,7 +746,7 @@ public function testUnserialize(): void ->willReturn([]); $this->pager->current(); - $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::unserialize()" is deprecated since sonata-project/admin-bundle 3.x and will be removed in 4.0.'); + $this->expectDeprecation('The method "Sonata\AdminBundle\Datagrid\Pager::unserialize()" is deprecated since sonata-project/admin-bundle 3.84 and will be removed in 4.0.'); $this->pager->unserialize(serialize($serialized)); $this->assertSame(7, $this->pager->getMaxPerPage()); diff --git a/tests/Util/FormBuilderIteratorTest.php b/tests/Util/FormBuilderIteratorTest.php index 679295a0b4..0c83ce81d4 100644 --- a/tests/Util/FormBuilderIteratorTest.php +++ b/tests/Util/FormBuilderIteratorTest.php @@ -80,7 +80,7 @@ public function testHasChildren(): void */ public function testTriggersADeprecationWithWrongPrefixType(): void { - $this->expectDeprecation('Passing other type than string or null as argument 2 for method Sonata\AdminBundle\Util\FormBuilderIterator::__construct() is deprecated since sonata-project/admin-bundle 3.x. It will accept only string and null in version 4.0.'); + $this->expectDeprecation('Passing other type than string or null as argument 2 for method Sonata\AdminBundle\Util\FormBuilderIterator::__construct() is deprecated since sonata-project/admin-bundle 3.84. It will accept only string and null in version 4.0.'); $this->builder->add('name', TextType::class); $iterator = new FormBuilderIterator($this->builder, new \stdClass()); From f8a95bfc059baf1ce557d6bdd19b2b4f9ab26c60 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 16 Dec 2020 23:41:43 +0100 Subject: [PATCH 27/30] Fix signature --- src/Datagrid/PagerInterface.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Datagrid/PagerInterface.php b/src/Datagrid/PagerInterface.php index c9b422c5e1..ef612541a6 100644 --- a/src/Datagrid/PagerInterface.php +++ b/src/Datagrid/PagerInterface.php @@ -18,17 +18,17 @@ * * NEXT_MAJOR: Remove these comments and uncomment corresponding methods. * - * @method int getPage() - * @method int getFirstPage() - * @method int getLastPage() - * @method int getNextPage() - * @method int getPreviousPage() - * @method bool isFirstPage() - * @method bool isLastPage() - * @method int getNbResults() - * @method array getLinks(?int $nbLinks = null) - * @method bool haveToPaginate() - * @method ProxyQueryInterface getQuery() + * @method int getPage() + * @method int getFirstPage() + * @method int getLastPage() + * @method int getNextPage() + * @method int getPreviousPage() + * @method bool isFirstPage() + * @method bool isLastPage() + * @method int getNbResults() + * @method array getLinks(?int $nbLinks = null) + * @method bool haveToPaginate() + * @method ProxyQueryInterface|null getQuery() */ interface PagerInterface { @@ -78,7 +78,7 @@ public function setPage($page); // public function isLastPage(): bool; // NEXT_MAJOR: uncomment this method in 4.0 -// public function getQuery(): ProxyQueryInterface; +// public function getQuery(): ?ProxyQueryInterface; /** * @param ProxyQueryInterface $query From f15560452f88d422645a8375bcb27074a19a8324 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Thu, 17 Dec 2020 00:17:19 +0100 Subject: [PATCH 28/30] Minor improvements --- phpstan-baseline.neon | 2 +- src/Admin/AbstractAdmin.php | 4 ++-- src/DependencyInjection/Admin/AbstractTaggedAdmin.php | 6 ++++++ src/DependencyInjection/Admin/TaggedAdminInterface.php | 2 ++ src/Security/Handler/AclSecurityHandlerInterface.php | 3 ++- src/Security/Handler/SecurityHandlerInterface.php | 2 +- src/Util/AdminObjectAclData.php | 2 +- 7 files changed, 15 insertions(+), 6 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 446958d64d..d57283ad69 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -159,7 +159,7 @@ parameters: - # will be fixed in v4. Currently BC break - message: "#^Method Sonata\\\\AdminBundle\\\\Translator\\\\Extractor\\\\JMSTranslatorBundle\\\\AdminExtractor\\:\\:buildSecurityInformation\\(\\) should return array\\ but return statement is missing\\.$#" + message: "#^Method Sonata\\\\AdminBundle\\\\Translator\\\\Extractor\\\\JMSTranslatorBundle\\\\AdminExtractor\\:\\:buildSecurityInformation\\(\\) should return array\\\\> but return statement is missing\\.$#" count: 1 path: src/Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 0e4df15c26..d29578829e 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -1177,12 +1177,12 @@ public function generateObjectUrl($name, $object, array $parameters = [], $refer public function generateUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) { - return $this->routeGenerator->generateUrl($this, $name, $parameters, $referenceType); + return $this->getRouteGenerator()->generateUrl($this, $name, $parameters, $referenceType); } public function generateMenuUrl($name, array $parameters = [], $referenceType = RoutingUrlGeneratorInterface::ABSOLUTE_PATH) { - return $this->routeGenerator->generateMenuUrl($this, $name, $parameters, $referenceType); + return $this->getRouteGenerator()->generateMenuUrl($this, $name, $parameters, $referenceType); } final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index 31a885ecf2..f82f85ebd1 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -68,6 +68,8 @@ abstract class AbstractTaggedAdmin implements TaggedAdminInterface /** * @var array> + * + * @phpstan-var array{list: array{class: string}, mosaic: array{class: string}} */ protected $listModes = [ 'list' => ['class' => 'fa fa-list fa-fw'], @@ -318,6 +320,8 @@ public function getManagerType() /** * @final since sonata-admin/admin-bundle 3.84 + * + * @param array $information */ public function setSecurityInformation(array $information) { @@ -326,6 +330,8 @@ public function setSecurityInformation(array $information) /** * @final since sonata-admin/admin-bundle 3.84 + * + * @return array */ public function getSecurityInformation() { diff --git a/src/DependencyInjection/Admin/TaggedAdminInterface.php b/src/DependencyInjection/Admin/TaggedAdminInterface.php index 9c394cc24f..8ec4f8e586 100644 --- a/src/DependencyInjection/Admin/TaggedAdminInterface.php +++ b/src/DependencyInjection/Admin/TaggedAdminInterface.php @@ -120,6 +120,8 @@ public function getManagerType(); * NEXT_MAJOR: Uncomment this method. * * Set the roles and permissions per role. + * + * @param array $information */ // public function setSecurityInformation(array $information): void; diff --git a/src/Security/Handler/AclSecurityHandlerInterface.php b/src/Security/Handler/AclSecurityHandlerInterface.php index 466561e267..8d69156b0a 100644 --- a/src/Security/Handler/AclSecurityHandlerInterface.php +++ b/src/Security/Handler/AclSecurityHandlerInterface.php @@ -86,7 +86,8 @@ public function addObjectOwner(AclInterface $acl, ?UserSecurityIdentity $securit * * NEXT_MAJOR: change signature to `addObjectClassAces(MutableAclInterface $acl, array $roleInformation = []): void`. * - * @param MutableAclInterface $acl + * @param MutableAclInterface $acl + * @param array $roleInformation * * @return void */ diff --git a/src/Security/Handler/SecurityHandlerInterface.php b/src/Security/Handler/SecurityHandlerInterface.php index f937b9cebd..3ee14696fa 100644 --- a/src/Security/Handler/SecurityHandlerInterface.php +++ b/src/Security/Handler/SecurityHandlerInterface.php @@ -36,7 +36,7 @@ public function isGranted(AdminInterface $admin, $attributes, $object = null); public function getBaseRole(AdminInterface $admin); /** - * @return array + * @return array */ public function buildSecurityInformation(AdminInterface $admin); diff --git a/src/Util/AdminObjectAclData.php b/src/Util/AdminObjectAclData.php index 48c816a9e2..e33a2495a4 100644 --- a/src/Util/AdminObjectAclData.php +++ b/src/Util/AdminObjectAclData.php @@ -321,7 +321,7 @@ public function getSecurityHandler() } /** - * @return array + * @return array */ public function getSecurityInformation() { From 2d591769d5a3fc8df288cc324f1d7a7cdf146d09 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 29 Dec 2020 20:04:33 +0100 Subject: [PATCH 29/30] Remove useless template --- src/Admin/AdminInterface.php | 1 - src/DependencyInjection/Admin/AbstractTaggedAdmin.php | 1 - src/DependencyInjection/Admin/TaggedAdminInterface.php | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/Admin/AdminInterface.php b/src/Admin/AdminInterface.php index 5897a2d9e6..f5db9f6e7b 100644 --- a/src/Admin/AdminInterface.php +++ b/src/Admin/AdminInterface.php @@ -52,7 +52,6 @@ * @method void defineFormBuilder(FormBuilderInterface $formBuilder) * * @phpstan-template T of object - * @phpstan-extends TaggedAdminInterface * @phpstan-extends AccessRegistryInterface * @phpstan-extends UrlGeneratorInterface * @phpstan-extends LifecycleHookProviderInterface diff --git a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php index f82f85ebd1..835c55b998 100644 --- a/src/DependencyInjection/Admin/AbstractTaggedAdmin.php +++ b/src/DependencyInjection/Admin/AbstractTaggedAdmin.php @@ -32,7 +32,6 @@ /** * @phpstan-template T of object - * @phpstan-implements TaggedAdminInterface */ abstract class AbstractTaggedAdmin implements TaggedAdminInterface { diff --git a/src/DependencyInjection/Admin/TaggedAdminInterface.php b/src/DependencyInjection/Admin/TaggedAdminInterface.php index 8ec4f8e586..49b80e0e1f 100644 --- a/src/DependencyInjection/Admin/TaggedAdminInterface.php +++ b/src/DependencyInjection/Admin/TaggedAdminInterface.php @@ -41,8 +41,6 @@ * - The first and third argument are automatically injected by the AddDependencyCallsCompilerPass. * - The second one is used as a reference of the Admin in the Pool, with the `setAdminClasses` call. * - * @phpstan-template T of object - * * @method void initialize() * @method void setLabel(?string $label) * @method void showMosaicButton(bool $isShown) From 5f8d438e142fc3b94ec5cb80db798aca9f1636d5 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 29 Dec 2020 20:55:15 +0100 Subject: [PATCH 30/30] Fix psalm issue --- src/Util/FormViewIterator.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Util/FormViewIterator.php b/src/Util/FormViewIterator.php index 9fccc04a4c..d2d9b0e8bb 100644 --- a/src/Util/FormViewIterator.php +++ b/src/Util/FormViewIterator.php @@ -42,6 +42,9 @@ public function hasChildren() return \count($this->current()->children) > 0; } + /** + * @return FormView + */ public function current() { return $this->iterator->current();
    {{ 'action_delete'|trans({}, 'SonataAdminBundle') }}