diff --git a/CHANGELOG.md b/CHANGELOG.md index 02ed464ca8..c5a4601022 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,23 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [4.30.1](https://github.com/sonata-project/SonataAdminBundle/compare/4.30.0...4.30.1) - 2024-04-10 +### Fixed +- [[#8175](https://github.com/sonata-project/SonataAdminBundle/pull/8175)] `Filter::getLabelTranslationParameters` implementation ([@VincentLanglet](https://github.com/VincentLanglet)) + +## [4.30.0](https://github.com/sonata-project/SonataAdminBundle/compare/4.29.3...4.30.0) - 2024-04-10 +### Added +- [[#8170](https://github.com/sonata-project/SonataAdminBundle/pull/8170)] SearchHandlerInterface ([@VincentLanglet](https://github.com/VincentLanglet)) + +### Deprecated +- [[#8172](https://github.com/sonata-project/SonataAdminBundle/pull/8172)] Not implementing `FilterInterface::showFilter` ([@VincentLanglet](https://github.com/VincentLanglet)) +- [[#8172](https://github.com/sonata-project/SonataAdminBundle/pull/8172)] Not implementing `FilterInterface::getLabelTranslationParameters` ([@VincentLanglet](https://github.com/VincentLanglet)) +- [[#8172](https://github.com/sonata-project/SonataAdminBundle/pull/8172)] Not implementing `FilterInterface::withAdvancedFilter` ([@VincentLanglet](https://github.com/VincentLanglet)) + +### Fixed +- [[#8173](https://github.com/sonata-project/SonataAdminBundle/pull/8173)] Active state in side menu for nested child admins ([@VincentLanglet](https://github.com/VincentLanglet)) +- [[#8172](https://github.com/sonata-project/SonataAdminBundle/pull/8172)] `label_translation_parameters` option usage ([@VincentLanglet](https://github.com/VincentLanglet)) + ## [4.29.3](https://github.com/sonata-project/SonataAdminBundle/compare/4.29.2...4.29.3) - 2024-01-22 ### Fixed - [[#8149](https://github.com/sonata-project/SonataAdminBundle/pull/8149)] Fix possible null error in search ([@core23](https://github.com/core23)) diff --git a/src/Block/AdminSearchBlockService.php b/src/Block/AdminSearchBlockService.php index 372a55b96d..674715ef7e 100644 --- a/src/Block/AdminSearchBlockService.php +++ b/src/Block/AdminSearchBlockService.php @@ -16,7 +16,7 @@ use Sonata\AdminBundle\Admin\Pool; use Sonata\AdminBundle\Filter\FilterInterface; use Sonata\AdminBundle\Search\SearchableFilterInterface; -use Sonata\AdminBundle\Search\SearchHandler; +use Sonata\AdminBundle\Search\SearchHandlerInterface; use Sonata\AdminBundle\Templating\TemplateRegistryInterface; use Sonata\BlockBundle\Block\BlockContextInterface; use Sonata\BlockBundle\Block\Service\AbstractBlockService; @@ -37,7 +37,7 @@ final class AdminSearchBlockService extends AbstractBlockService public function __construct( Environment $twig, private Pool $pool, - private SearchHandler $searchHandler, + private SearchHandlerInterface $searchHandler, private TemplateRegistryInterface $templateRegistry, private string $emptyBoxesOption, private string $adminRoute diff --git a/src/Datagrid/Datagrid.php b/src/Datagrid/Datagrid.php index 0ffb9eaedb..98048744f3 100644 --- a/src/Datagrid/Datagrid.php +++ b/src/Datagrid/Datagrid.php @@ -325,7 +325,28 @@ private function buildForm(): FormInterface // NEXT_MAJOR: Keep the if part. if (method_exists($filter, 'getFormOptions')) { $type = FilterDataType::class; - $options = $filter->getFormOptions(); + + // NEXT_MAJOR: Keep the if part. + if (method_exists($filter, 'getLabelTranslationParameters')) { + $labelTranslationParameters = $filter->getLabelTranslationParameters(); + } else { + @trigger_error( + 'Not implementing "getLabelTranslationParameters()" is deprecated since sonata-project/admin-bundle 4.30' + .' and will throw an error in 5.0.', + \E_USER_DEPRECATED + ); + + $labelTranslationParameters = $filter->getOption('label_translation_parameters'); + } + + $defaultFormOptions = [ + 'label' => $filter->getLabel(), + 'label_translation_parameters' => $labelTranslationParameters, + 'translation_domain' => $filter->getTranslationDomain(), + 'field_type' => $filter->getFieldType(), + 'field_options' => $filter->getFieldOptions(), + ]; + $options = array_merge($defaultFormOptions, $filter->getFormOptions()); } else { @trigger_error( 'Not implementing "getFormOptions()" is deprecated since sonata-project/admin-bundle 4.15' diff --git a/src/Filter/Filter.php b/src/Filter/Filter.php index e54be96277..05cce37744 100644 --- a/src/Filter/Filter.php +++ b/src/Filter/Filter.php @@ -248,6 +248,24 @@ public function getRenderSettings(): array ]; } + final public function showFilter(): ?bool + { + return $this->getOption('show_filter'); + } + + /** + * @return array + */ + final public function getLabelTranslationParameters(): array + { + return $this->getOption('label_translation_parameters', []); + } + + final public function withAdvancedFilter(): bool + { + return $this->getOption('advanced_filter'); + } + final protected function setActive(bool $active): void { $this->active = $active; diff --git a/src/Filter/FilterInterface.php b/src/Filter/FilterInterface.php index 74479309d8..d0f59b5c58 100644 --- a/src/Filter/FilterInterface.php +++ b/src/Filter/FilterInterface.php @@ -20,6 +20,9 @@ * @author Thomas Rabaix * * @method array getFormOptions(); + * @method bool|null showFilter(); + * @method array getLabelTranslationParameters(); + * @method bool withAdvancedFilter(); */ interface FilterInterface { diff --git a/src/Menu/Matcher/Voter/AdminVoter.php b/src/Menu/Matcher/Voter/AdminVoter.php index 7876475abf..a326127b41 100644 --- a/src/Menu/Matcher/Voter/AdminVoter.php +++ b/src/Menu/Matcher/Voter/AdminVoter.php @@ -32,32 +32,43 @@ public function __construct( public function matchItem(ItemInterface $item): ?bool { - $admin = $item->getExtra('admin'); - $request = $this->requestStack->getMainRequest(); + if (null === $request) { + return null; + } - if ($admin instanceof AdminInterface + $admin = $item->getExtra('admin'); + if ( + $admin instanceof AdminInterface && $admin->hasRoute('list') && $admin->hasAccess('list') - && null !== $request + && $this->match($admin, $request->get('_sonata_admin')) ) { - $requestCode = $request->get('_sonata_admin'); - - if ($admin->getCode() === $requestCode) { - return true; - } - - foreach ($admin->getChildren() as $child) { - if ($child->getBaseCodeRoute() === $requestCode) { - return true; - } - } + return true; } $route = $item->getExtra('route'); - if (null !== $route && null !== $request && $route === $request->get('_route')) { + if (null !== $route && $route === $request->get('_route')) { return true; } return null; } + + /** + * @param AdminInterface $admin + */ + private function match(AdminInterface $admin, mixed $requestCode): bool + { + if ($admin->getBaseCodeRoute() === $requestCode) { + return true; + } + + foreach ($admin->getChildren() as $child) { + if ($this->match($child, $requestCode)) { + return true; + } + } + + return false; + } } diff --git a/src/Resources/config/core.php b/src/Resources/config/core.php index f57a51cf67..3ff2683220 100644 --- a/src/Resources/config/core.php +++ b/src/Resources/config/core.php @@ -33,6 +33,7 @@ use Sonata\AdminBundle\Request\AdminFetcherInterface; use Sonata\AdminBundle\Route\AdminPoolLoader; use Sonata\AdminBundle\Search\SearchHandler; +use Sonata\AdminBundle\Search\SearchHandlerInterface; use Sonata\AdminBundle\SonataConfiguration; use Sonata\AdminBundle\Templating\TemplateRegistry; use Sonata\AdminBundle\Translator\BCLabelTranslatorStrategy; @@ -124,6 +125,8 @@ ->set('sonata.admin.search.handler', SearchHandler::class) + ->alias(SearchHandlerInterface::class, 'sonata.admin.search.handler') + ->set('sonata.admin.controller.crud', CRUDController::class) ->public() ->tag('container.service_subscriber') diff --git a/src/Resources/views/Block/block_search_result.html.twig b/src/Resources/views/Block/block_search_result.html.twig index 19b67bc784..07e6413b40 100644 --- a/src/Resources/views/Block/block_search_result.html.twig +++ b/src/Resources/views/Block/block_search_result.html.twig @@ -45,10 +45,10 @@ file that was distributed with this source code.
{% for name, filter in filters %} - {% if filter.option('translation_domain') is same as(false) %} - {{ filter.option('label') }} + {% if filter.translationDomain is same as(false) %} + {{ filter.label }} {% else %} - {{ filter.option('label')|trans({}, filter.option('translation_domain', admin.translationDomain)) }} + {{ filter.label|trans({}, filter.translationDomain ?? admin.translationDomain) }} {% endif %} {% endfor %} diff --git a/src/Resources/views/CRUD/base_list.html.twig b/src/Resources/views/CRUD/base_list.html.twig index b833b0df95..5692b296e2 100644 --- a/src/Resources/views/CRUD/base_list.html.twig +++ b/src/Resources/views/CRUD/base_list.html.twig @@ -256,7 +256,8 @@ file that was distributed with this source code. {% endblock %} {% block list_filters_actions %} - {% set displayableFilters = admin.datagrid.filters|filter(filter => filter.option('show_filter') is not same as (false)) %} + {# NEXT_MAJOR: Remove |default(filter.option('show_filter')) #} + {% set displayableFilters = admin.datagrid.filters|filter(filter => filter.showFilter|default(filter.option('show_filter')) is not same as (false)) %} {%- if displayableFilters|length %}