diff --git a/UPGRADE-3.x.md b/UPGRADE-3.x.md index 8ba09e0efaa..cc245eeed90 100644 --- a/UPGRADE-3.x.md +++ b/UPGRADE-3.x.md @@ -4,12 +4,30 @@ UPGRADE 3.x UPGRADE FROM 3.xx to 3.xx ========================= +### Deprecated `admin_pool` parameter in `sonata.admin.dashboard.top` and `onata.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_configuration` variable. + +### Sonata\AdminBundle\Twig\GlobalVariables + +This class has been deprecated without replacement. + ### Sonata\AdminBundle\Admin\Pool - Passing a `Symfony\Component\PropertyAccess\PropertyAccessorInterface` instance as 4 argument instantiating `Sonata\AdminBundle\Admin\Pool` is deprecated. - `Sonata\AdminBundle\Admin\Pool::getPropertyAccessor()` method has been deprecated. You SHOULD inject `Symfony\Component\PropertyAccess\PropertyAccessorInterface` where is needed. +- `Sonata\AdminBundle\Admin\Pool::getTitle()` method has been deprecated. +Use `Sonata\AdminBundle\Admin\SonataConfiguration::getTitle()` instead. +- `Sonata\AdminBundle\Admin\Pool::getTitleLogo()` method has been deprecated. +Use `Sonata\AdminBundle\Admin\SonataConfiguration::getLogo()` instead. +- `Sonata\AdminBundle\Admin\Pool::getOption()` method has been deprecated. +Use `Sonata\AdminBundle\Admin\SonataConfiguration::getOption()` instead. ### Sonata\AdminBundle\Action\SetObjectFieldValueAction diff --git a/src/Admin/Pool.php b/src/Admin/Pool.php index 494338bb1fa..eb98289d932 100644 --- a/src/Admin/Pool.php +++ b/src/Admin/Pool.php @@ -60,16 +60,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 +104,7 @@ class Pool /** * NEXT_MAJOR: Remove $propertyAccessor argument. + * NEXT_MAJOR: Remove $title, $logoTitle and $options. * * @param string $title * @param string $logoTitle @@ -532,22 +545,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 +594,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/Admin/SonataConfiguration.php b/src/Admin/SonataConfiguration.php new file mode 100644 index 00000000000..f610ccdc475 --- /dev/null +++ b/src/Admin/SonataConfiguration.php @@ -0,0 +1,105 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Sonata\AdminBundle\Admin; + +final class SonataConfiguration +{ + /** + * @var string + */ + private $title; + + /** + * @var string + */ + private $logo; + + /** + * @var array + * @phpstan-param array{ + * html5_validate: bool, + * sort_admins: bool, + * confirm_exit: bool, + * js_debug: bool, + * skin: string, + * use_select2: bool, + * use_icheck: bool, + * use_bootlint: bool, + * use_stickyforms: bool, + * pager_links: ?int, + * form_type: string, + * default_group: string, + * default_label_catalogue: string, + * default_icon: string, + * dropdown_number_groups_per_colums: int, + * title_mode: 'single_text'|'single_image'|'both', + * lock_protection: bool, + * mosaic_background: string, + * lock_protection: bool, + * legacy_twig_text_extension: bool, + * } $options + */ + private $options; + + /** + * @phpstan-param array{ + * html5_validate: bool, + * sort_admins: bool, + * confirm_exit: bool, + * js_debug: bool, + * skin: string, + * use_select2: bool, + * use_icheck: bool, + * use_bootlint: bool, + * use_stickyforms: bool, + * pager_links: ?int, + * form_type: string, + * default_group: string, + * default_label_catalogue: string, + * default_icon: string, + * dropdown_number_groups_per_colums: int, + * title_mode: 'single_text'|'single_image'|'both', + * lock_protection: bool, + * mosaic_background: string, + * lock_protection: bool, + * legacy_twig_text_extension: bool, + * } $options + */ + public function __construct(string $title, string $logo, array $options) + { + $this->title = $title; + $this->logo = $logo; + $this->options = $options; + } + + public function getTitle(): string + { + return $this->title; + } + + public function getLogo(): string + { + return $this->logo; + } + + /** + * @param mixed $default + * + * @return mixed + */ + public function getOption(string $name, $default = null) + { + return $this->options[$name] ?? $default; + } +} diff --git a/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php b/src/DependencyInjection/Compiler/GlobalVariablesCompilerPass.php index a7b95f004f8..b105173f345 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_configuration', 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 74df9bea46e..0efb42fd31c 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 b1d6878ac0e..1e69428dad5 100644 --- a/src/Resources/config/core.php +++ b/src/Resources/config/core.php @@ -16,6 +16,7 @@ use Sonata\AdminBundle\Admin\BreadcrumbsBuilderInterface; use Sonata\AdminBundle\Admin\Extension\LockExtension; use Sonata\AdminBundle\Admin\Pool; +use Sonata\AdminBundle\Admin\SonataConfiguration; use Sonata\AdminBundle\Controller\HelperController; use Sonata\AdminBundle\Event\AdminEventExtension; use Sonata\AdminBundle\Export\Exporter; @@ -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 277880b32e0..cf51aaf84ae 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 59a06c2da58..6da3554be4f 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_configuration.getOption('role_super_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} {% if display %}
diff --git a/src/Resources/views/CRUD/base_acl.html.twig b/src/Resources/views/CRUD/base_acl.html.twig index 82276de9385..592f0c711e4 100644 --- a/src/Resources/views/CRUD/base_acl.html.twig +++ b/src/Resources/views/CRUD/base_acl.html.twig @@ -19,9 +19,9 @@ file that was distributed with this source code. {% block form %} {% block form_acl_roles %} - {{ acl.render_form(aclRolesForm, permissions, 'td_role', admin, sonata_admin.adminPool, object) }} + {{ acl.render_form(aclRolesForm, permissions, 'td_role', admin, sonata_configuration, object) }} {% endblock %} {% block form_acl_users %} - {{ acl.render_form(aclUsersForm, permissions, 'td_username', admin, sonata_admin.adminPool, object) }} + {{ acl.render_form(aclUsersForm, permissions, 'td_username', admin, sonata_configuration, object) }} {% endblock %} {% endblock %} diff --git a/src/Resources/views/CRUD/base_acl_macro.html.twig b/src/Resources/views/CRUD/base_acl_macro.html.twig index a8d9b08d76c..6c622cd3c85 100644 --- a/src/Resources/views/CRUD/base_acl_macro.html.twig +++ b/src/Resources/views/CRUD/base_acl_macro.html.twig @@ -9,12 +9,12 @@ file that was distributed with this source code. #} -{% macro render_form(form, permissions, td_type, admin, admin_pool, object) %} +{% macro render_form(form, permissions, td_type, admin, admin_configuration, object) %}
{{ include('@SonataAdmin/Helper/render_form_dismissable_errors.html.twig') }} diff --git a/src/Resources/views/CRUD/base_edit_form.html.twig b/src/Resources/views/CRUD/base_edit_form.html.twig index de1bac67fde..b3543cedccb 100644 --- a/src/Resources/views/CRUD/base_edit_form.html.twig +++ b/src/Resources/views/CRUD/base_edit_form.html.twig @@ -10,13 +10,13 @@
{% else %} diff --git a/src/Resources/views/CRUD/list_outer_rows_mosaic.html.twig b/src/Resources/views/CRUD/list_outer_rows_mosaic.html.twig index c93631eb335..0d9644e5e56 100644 --- a/src/Resources/views/CRUD/list_outer_rows_mosaic.html.twig +++ b/src/Resources/views/CRUD/list_outer_rows_mosaic.html.twig @@ -30,7 +30,7 @@ This template can be customized to match your needs. You should only extends the
{% block sonata_mosaic_background %} - {% set metaImage = meta.isImageAvailable is defined and not meta.isImageAvailable ? sonata_admin.mosaicBackground : meta.image %} + {% set metaImage = meta.isImageAvailable is defined and not meta.isImageAvailable ? sonata_configuration.getOption('mosaic_background') : meta.image %} {% if not (metaImage starts with 'data:') %} {% set metaImage = asset(metaImage) %} {% endif %} diff --git a/src/Resources/views/Core/add_block.html.twig b/src/Resources/views/Core/add_block.html.twig index 7eada64fdf3..21e06f6c49a 100644 --- a/src/Resources/views/Core/add_block.html.twig +++ b/src/Resources/views/Core/add_block.html.twig @@ -1,10 +1,7 @@ {% block user_block %} - {% set items_per_column = sonata_admin.adminPool.getOption('dropdown_number_groups_per_colums') %} - {% set groups = [] %} + {% set items_per_column = sonata_configuration.getOption('dropdown_number_groups_per_colums') %} - {% for group in sonata_admin.adminPool.dashboardgroups|filter(group => group.items|filter(admin => admin.hasRoute('create') and admin.hasAccess('create'))|length > 0) %} - {% set groups = [group]|merge(groups) %} - {% endfor %} + {% set groups = get_sonata_dashboard_groups_with_creatable_admins() %} {% set column_count = (groups|length / items_per_column)|round(0, 'ceil') %} @@ -12,7 +9,7 @@ {% if column_count > 1 %}style="width: {{ column_count*140 }}px;"{% endif %} > {% for group in groups|reverse %} - {% set display = group.roles is empty or is_granted(sonata_admin.adminPool.getOption('role_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} + {% set display = group.roles is empty or is_granted(sonata_configuration.getOption('role_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} {% if loop.first %} {% set render_first_element = true %} diff --git a/src/Resources/views/Core/dashboard.html.twig b/src/Resources/views/Core/dashboard.html.twig index 2433f068dc4..e248198a254 100644 --- a/src/Resources/views/Core/dashboard.html.twig +++ b/src/Resources/views/Core/dashboard.html.twig @@ -50,7 +50,8 @@ file that was distributed with this source code. {% endif %} {% endfor %} - {{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': sonata_admin.adminPool }) }} + {# NEXT_MAJOR: Remove the admin_pool argument #} + {{ sonata_block_render_event('sonata.admin.dashboard.top', { 'admin_pool': sonata_admin.adminPool('sonata_deprecation_mute') }) }} {% if has_top %}
@@ -125,6 +126,7 @@ file that was distributed with this source code.
{% endif %} - {{ sonata_block_render_event('sonata.admin.dashboard.bottom', { 'admin_pool': sonata_admin.adminPool }) }} + {# NEXT_MAJOR: Remove the admin_pool argument #} + {{ sonata_block_render_event('sonata.admin.dashboard.bottom', { 'admin_pool': sonata_admin.adminPool('sonata_deprecation_mute') }) }} {% endblock %} diff --git a/src/Resources/views/Core/search.html.twig b/src/Resources/views/Core/search.html.twig index 6b378b620b8..565e5902ceb 100644 --- a/src/Resources/views/Core/search.html.twig +++ b/src/Resources/views/Core/search.html.twig @@ -20,7 +20,7 @@ file that was distributed with this source code. {% set count = 0 %}
{% 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_configuration.getOption('role_super_admin')) or group.roles|filter(role => is_granted(role))|length > 0 %} {% if display %} {% for admin in group.items %} diff --git a/src/Resources/views/Menu/sonata_menu.html.twig b/src/Resources/views/Menu/sonata_menu.html.twig index fb20dcf49ea..e3107108a1b 100644 --- a/src/Resources/views/Menu/sonata_menu.html.twig +++ b/src/Resources/views/Menu/sonata_menu.html.twig @@ -9,7 +9,7 @@ {% block item %} {%- if item.displayed -%} {#- check role of the group #} - {%- set display = item.extra('roles') is empty or is_granted(sonata_admin.adminPool.getOption('role_super_admin')) or item.extra('roles')|filter(role => is_granted(role))|length > 0 -%} + {%- set display = item.extra('roles') is empty or is_granted(sonata_configuration.getOption('role_super_admin')) or item.extra('roles')|filter(role => is_granted(role))|length > 0 -%} {%- endif -%} {%- if item.displayed and display|default -%} diff --git a/src/Resources/views/standard_layout.html.twig b/src/Resources/views/standard_layout.html.twig index 4318059688c..57bfd06e138 100644 --- a/src/Resources/views/standard_layout.html.twig +++ b/src/Resources/views/standard_layout.html.twig @@ -21,9 +21,9 @@ file that was distributed with this source code. {% set _actions = block('actions') is defined ? block('actions')|trim : null %} {% set _navbar_title = block('navbar_title') is defined ? block('navbar_title')|trim : null %} {% set _list_filters_actions = block('list_filters_actions') is defined ? block('list_filters_actions')|trim : null -%} -{% set _skin = sonata_admin.adminPool.getOption('skin') %} -{% set _use_select2 = sonata_admin.adminPool.getOption('use_select2') %} -{% set _use_icheck = sonata_admin.adminPool.getOption('use_icheck') %} +{% set _skin = sonata_configuration.getOption('skin') %} +{% set _use_select2 = sonata_configuration.getOption('use_select2') %} +{% set _use_icheck = sonata_configuration.getOption('use_icheck') %} @@ -37,11 +37,11 @@ file that was distributed with this source code. {% block stylesheets %} - {% for stylesheet in sonata_admin.adminPool.getOption('stylesheets', []) %} + {% for stylesheet in sonata_configuration.getOption('stylesheets', []) %} {% endfor %} {% endblock %} @@ -60,7 +60,7 @@ file that was distributed with this source code. {% endblock %} {% block sonata_javascript_pool %} - {% for javascript in sonata_admin.adminPool.getOption('javascripts', []) %} + {% for javascript in sonata_configuration.getOption('javascripts', []) %} {% endfor %} {% endblock %} @@ -76,7 +76,7 @@ file that was distributed with this source code. {% endif %} {# localize select2 #} - {% if sonata_admin.adminPool.getOption('use_select2') %} + {% if sonata_configuration.getOption('use_select2') %} {% set localeForSelect2 = canonicalize_locale_for_select2() %} {% if localeForSelect2 %} @@ -139,11 +139,11 @@ file that was distributed with this source code. {% block logo %} {% apply spaceless %} {% endapply %} @@ -199,7 +199,7 @@ file that was distributed with this source code.
{% block sonata_top_nav_menu %} - {% if app.user and is_granted(sonata_admin.adminPool.getOption('role_admin')) %} + {% if app.user and is_granted(sonata_configuration.getOption('role_admin')) %}