diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 5d2998dbaf..a65e1749c9 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -4,6 +4,31 @@ UPGRADE 3.x UPGRADE FROM 3.xx to 3.xx ========================= +### Deprecated `admin_pool` parameter in `sonata.admin.dashboard.top` and `sonata.admin.dashboard.bottom` block events. + +This parameter will be removed in 4.0. If you are using it, you SHOULD inject `Pool` service instead. + +### Deprecated global Twig `sonata_admin` variable + +This variable has been deprecated in favor of `sonata_config` variable. + +### Sonata\AdminBundle\Twig\GlobalVariables + +This class has been deprecated without replacement. + +### Sonata\AdminBundle\Model\ModelManagerInterface + +Argument 2 of `Sonata\AdminBundle\Model\ModelManagerInterface::createQuery()` method has been removed. + +### Sonata\AdminBundle\Admin\Pool + +- `Sonata\AdminBundle\Admin\Pool::getTitle()` method has been deprecated. + Use `Sonata\AdminBundle\SonataConfiguration::getTitle()` instead. +- `Sonata\AdminBundle\Admin\Pool::getTitleLogo()` method has been deprecated. + Use `Sonata\AdminBundle\SonataConfiguration::getLogo()` instead. +- `Sonata\AdminBundle\Admin\Pool::getOption()` method has been deprecated. + Use `Sonata\AdminBundle\SonataConfiguration::getOption()` instead. + ### Sonata\AdminBundle\Admin\FieldDescriptionInterface The following methods have been deprecated from the interface and will be added as abstract methods to diff --git a/src/Admin/Pool.php b/src/Admin/Pool.php index b5a74e75e0..8e3a66984b 100644 --- a/src/Admin/Pool.php +++ b/src/Admin/Pool.php @@ -13,6 +13,7 @@ namespace Sonata\AdminBundle\Admin; +use Sonata\AdminBundle\SonataConfiguration; use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\PropertyAccess\PropertyAccess; @@ -60,16 +61,28 @@ class Pool protected $assets = []; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @var string */ protected $title; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @var string */ protected $titleLogo; /** + * NEXT_MAJOR: Remove this property. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @var array */ protected $options = []; @@ -92,6 +105,7 @@ class Pool /** * NEXT_MAJOR: Remove $propertyAccessor argument. + * NEXT_MAJOR: Remove $title, $logoTitle and $options. * * @param string $title * @param string $logoTitle @@ -532,22 +546,48 @@ public function getTemplate($name) } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @return string */ public function getTitleLogo() { + @trigger_error(sprintf( + 'The "%s" method is deprecated since version 3.x and will be removed in 4.0.' + .' Use "%s::getTitle()" instead.', + SonataConfiguration::class, + __METHOD__ + ), E_USER_DEPRECATED); + return $this->titleLogo; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @return string */ public function getTitle() { + @trigger_error(sprintf( + 'The "%s" method is deprecated since version 3.x and will be removed in 4.0.' + .' Use "%s::getLogo()" instead.', + SonataConfiguration::class, + __METHOD__ + ), E_USER_DEPRECATED); + return $this->title; } /** + * NEXT_MAJOR: Remove this method. + * + * @deprecated since sonata-project/admin-bundle 3.x, will be dropped in 4.0. + * * @param string $name * @param mixed $default * @@ -555,6 +595,13 @@ public function getTitle() */ public function getOption($name, $default = null) { + @trigger_error(sprintf( + 'The "%s" method is deprecated since version 3.x and will be removed in 4.0.' + .' Use "%s::getOption()" instead.', + SonataConfiguration::class, + __METHOD__ + ), E_USER_DEPRECATED); + if (isset($this->options[$name])) { return $this->options[$name]; } diff --git a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php index a7b95f004f..a5ff38006a 100644 --- a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php +++ b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php @@ -27,6 +27,8 @@ class GlobalVariablesCompilerPass implements CompilerPassInterface public function process(ContainerBuilder $container) { $container->getDefinition('twig') + ->addMethodCall('addGlobal', ['sonata_config', new Reference('sonata.admin.configuration')]) + // NEXT_MAJOR: Remove next line. ->addMethodCall('addGlobal', ['sonata_admin', new Reference('sonata.admin.twig.global')]); } } diff --git a/src/DependencyInjection/SonataAdminExtension.php b/src/DependencyInjection/SonataAdminExtension.php index 74df9bea46..0efb42fd31 100644 --- a/src/DependencyInjection/SonataAdminExtension.php +++ b/src/DependencyInjection/SonataAdminExtension.php @@ -92,11 +92,17 @@ public function load(array $configs, ContainerBuilder $container) $config['options']['role_super_admin'] = $config['security']['role_super_admin']; $config['options']['search'] = $config['search']; + // NEXT_MAJOR: Remove this Pool configuration. $pool = $container->getDefinition('sonata.admin.pool'); $pool->replaceArgument(1, $config['title']); $pool->replaceArgument(2, $config['title_logo']); $pool->replaceArgument(3, $config['options']); + $sonataConfiguration = $container->getDefinition('sonata.admin.configuration'); + $sonataConfiguration->replaceArgument(0, $config['title']); + $sonataConfiguration->replaceArgument(1, $config['title_logo']); + $sonataConfiguration->replaceArgument(2, $config['options']); + if (false === $config['options']['lock_protection']) { $container->removeDefinition('sonata.admin.lock.extension'); } diff --git a/src/Resources/config/core.php b/src/Resources/config/core.php index b1d6878ac0..08e960b0f2 100644 --- a/src/Resources/config/core.php +++ b/src/Resources/config/core.php @@ -27,6 +27,7 @@ use Sonata\AdminBundle\Model\AuditManagerInterface; use Sonata\AdminBundle\Route\AdminPoolLoader; use Sonata\AdminBundle\Search\SearchHandler; +use Sonata\AdminBundle\SonataConfiguration; use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface; use Sonata\AdminBundle\Templating\TemplateRegistry; use Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy; @@ -61,6 +62,15 @@ ->alias(Pool::class, 'sonata.admin.pool') + ->set('sonata.admin.configuration', SonataConfiguration::class) + ->args([ + '', + '', + [], + ]) + + ->alias(SonataConfiguration::class, 'sonata.admin.configuration') + ->set('sonata.admin.route_loader', AdminPoolLoader::class) ->public() ->tag('routing.loader') @@ -213,6 +223,7 @@ ->public() ->tag('sonata.admin.extension', ['global' => true]) + // NEXT_MAJOR: Remove this service definition and alias. ->set('sonata.admin.twig.global', GlobalVariables::class) ->public() ->args([ diff --git a/src/Resources/config/twig.php b/src/Resources/config/twig.php index 277880b32e..cf51aaf84a 100644 --- a/src/Resources/config/twig.php +++ b/src/Resources/config/twig.php @@ -11,6 +11,7 @@ * file that was distributed with this source code. */ +use Sonata\AdminBundle\Twig\Extension\GroupExtension; use Sonata\AdminBundle\Twig\Extension\PaginationExtension; use Sonata\AdminBundle\Twig\Extension\SonataAdminExtension; use Sonata\AdminBundle\Twig\Extension\TemplateRegistryExtension; @@ -65,6 +66,12 @@ new ReferenceConfigurator('service_container'), ]) + ->set('sonata.admin.group.extension', GroupExtension::class) + ->tag('twig.extension') + ->args([ + new ReferenceConfigurator('sonata.admin.pool'), + ]) + // NEXT_MAJOR: Remove this service. ->set('sonata.pagination.twig.extension', PaginationExtension::class) ->tag('twig.extension') diff --git a/src/Resources/views/Block/block_admin_list.html.twig b/src/Resources/views/Block/block_admin_list.html.twig index 59a06c2da5..f10ed521f1 100644 --- a/src/Resources/views/Block/block_admin_list.html.twig +++ b/src/Resources/views/Block/block_admin_list.html.twig @@ -13,7 +13,7 @@ file that was distributed with this source code. {% block block %} {% for group in groups %} - {% set display = group.roles is empty or is_granted(sonata_admin.adminPool.getOption('role_super_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} + {% set display = group.roles is empty or is_granted(sonata_config.getOption('role_super_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} {% if display %}