Closed kursez closed 1 year ago
Indeed, the callback wasn't updated https://github.com/sonata-project/SonataPageBundle/blob/4.x/src/Admin/PageAdmin.php#L197
It should be something like
'callback' => static function (ProxyQueryInterface $queryBuilder, string $alias, string $field, FilterData $data): void {
$builder = $queryBuilder->getQueryBuilder();
if (\in_array($data->getValue(), ['hybrid', 'cms'], true)) {
$builder->andWhere(sprintf('%s.routeName %s :routeName', $alias, 'cms' === $data->getValue() ? '=' : '!='));
$builder->setParameter('routeName', PageInterface::PAGE_ROUTE_CMS_NAME);
}
},
Seems that the issue is on 197:113 instead of a array the type should be \Sonata\AdminBundle\Filter\Model\FilterData and instead of data['value'] it should be data->getValue()
you got me some minutes earlier ;) I tried this already but there is also an issue with the twig sonat-admin/resources/CRUD/base_list.html.twig the issue is that the callback should return also some boolean so the type should be changed from void to bool and the proper bool should be returned accordingly
so it should be
'callback' => static function (ProxyQueryInterface $queryBuilder, string $alias, string $field, \Sonata\AdminBundle\Filter\Model\FilterData $data): bool { $builder = $queryBuilder->getQueryBuilder();
if (\in_array($data->getValue(), ['hybrid', 'cms'], true)) {
$builder->andWhere(sprintf('%s.routeName %s :routeName', $alias, 'cms' === $data->getValue() ? '=' : '!='));
$builder->setParameter('routeName', PageInterface::PAGE_ROUTE_CMS_NAME);
}
return true;
},
but it should not always return true I guess
I guess I can overwrite the admin with some extension until this get's fixed
I guess I can overwrite the admin with some extension until this get's fixed
You can also provide a PR with the fix and I'll review/merge/release it.
Environment: dev, prod
Direct dependencies required in composer.json: sonata-project/admin-bundle 4.22.2 4.22.2 The missing Symfony Admin Generator sonata-project/classification-bundle 4.3.0 4.3.0 Symfony SonataClassificationBundle sonata-project/formatter-bundle 5.0.2 5.0.2 Symfony SonataFormatterBundle sonata-project/media-bundle 4.5.1 4.5.1 Symfony SonataMediaBundle sonata-project/page-bundle 4.0.0 4.0.0 This bundle provides a Site and Page management through container and block services sonata-project/user-bundle 5.4.0 5.4.0 Symfony SonataUserBundle
Transitive dependencies not required in composer.json: sonata-project/block-bundle 4.19.0 4.19.0 Symfony SonataBlockBundle sonata-project/cache 2.2.0 2.2.0 Cache library Package sonata-project/cache is abandoned, you should avoid using it. No replacement was suggested. sonata-project/doctrine-extensions 2.1.0 2.1.0 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 4.9.1 4.9.1 Integrate Doctrine ORM into the SonataAdminBundle sonata-project/exporter 3.1.1 3.1.1 Lightweight Exporter library sonata-project/form-extensions 1.18.0 1.18.0 Symfony form extensions sonata-project/seo-bundle 3.5.0 3.5.0 Symfony SonataSeoBundle sonata-project/twig-extensions 2.0.0 2.0.0 Sonata twig extensions
Symfony packages
Direct dependencies required in composer.json: symfony/asset v6.1.5 v6.2.0 Manages URL generation and versioning of web assets such as CSS stylesheets, JavaScript files and image files symfony/browser-kit v6.1.3 v6.2.0 Simulates the behavior of a web browser, allowing you to make requests, click on links and submit forms programmatic... symfony/cache v6.1.10 v6.2.4 Provides extended PSR-6, PSR-16 (and tags) implementations symfony/console v6.1.9 v6.2.3 Eases the creation of beautiful and testable command line interfaces symfony/css-selector v6.1.9 v6.2.3 Converts CSS selectors to XPath expressions symfony/dom-crawler v6.1.9 v6.2.3 Eases DOM navigation for HTML and XML documents symfony/dotenv v6.1.0 v6.2.0 Registers environment variables from a .env file symfony/flex v2.2.4 v2.2.4 Composer plugin for Symfony symfony/framework-bundle v6.1.9 v6.2.3 Provides a tight integration between Symfony components and the Symfony full-stack framework symfony/monolog-bundle v3.8.0 v3.8.0 Symfony MonologBundle symfony/phpunit-bridge v6.2.3 v6.2.3 Provides utilities for PHPUnit, especially user deprecation notices management symfony/runtime v6.1.3 v6.2.0 Enables decoupling PHP applications from global state symfony/stopwatch v6.1.5 v6.2.0 Provides a way to profile code symfony/web-profiler-bundle v6.1.9 v6.2.4 Provides a development tool that gives detailed information about the execution of any request symfony/yaml v6.1.9 v6.2.2 Loads and dumps YAML files
Transitive dependencies not required in composer.json: symfony/cache-contracts v3.2.0 v3.2.0 Generic abstractions related to caching symfony/config v6.1.3 v6.2.0 Helps you find, load, combine, autofill and validate configuration values of any kind symfony/dependency-injection v6.1.9 v6.2.3 Allows you to standardize and centralize the way objects are constructed in your application symfony/deprecation-contracts v3.2.0 v3.2.0 A generic function and convention to trigger deprecation notices symfony/doctrine-bridge v6.1.9 v6.2.3 Provides integration for Doctrine with various Symfony components symfony/error-handler v6.1.9 v6.2.3 Provides tools to manage errors and ease debugging PHP code symfony/event-dispatcher v6.1.9 v6.2.2 Provides tools that allow your application components to communicate with each other by dispatching events and liste... symfony/event-dispatcher-contracts v3.2.0 v3.2.0 Generic abstractions related to dispatching event symfony/expression-language v6.1.6 v6.2.2 Provides an engine that can compile and evaluate expressions symfony/filesystem v6.1.5 v6.2.0 Provides basic utilities for the filesystem symfony/finder v6.1.9 v6.2.3 Finds files and directories via an intuitive fluent interface symfony/form v6.1.9 v6.2.3 Allows to easily create, process and reuse HTML forms symfony/http-client v6.1.9 v6.2.2 Provides powerful methods to fetch HTTP resources synchronously or asynchronously symfony/http-client-contracts v3.2.0 v3.2.0 Generic abstractions related to HTTP clients symfony/http-foundation v6.1.9 v6.2.2 Defines an object-oriented layer for the HTTP specification symfony/http-kernel v6.1.10 v6.2.4 Provides a structured process for converting a Request into a Response symfony/intl v6.1.7 v6.2.0 Provides a PHP replacement layer for the C intl extension that includes additional data from the ICU library symfony/mailer v6.1.9 v6.2.2 Helps sending emails symfony/mime v6.1.9 v6.2.2 Allows manipulating MIME messages symfony/monolog-bridge v6.1.9 v6.2.2 Provides integration for Monolog with various Symfony components symfony/options-resolver v6.1.0 v6.2.0 Provides an improved replacement for the arrayreplace PHP function symfony/password-hasher v6.1.3 v6.2.0 Provides password hashing utilities symfony/polyfill-intl-grapheme v1.27.0 v1.27.0 Symfony polyfill for intl's grapheme* functions symfony/polyfill-intl-icu v1.27.0 v1.27.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.27.0 v1.27.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.27.0 v1.27.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.27.0 v1.27.0 Symfony polyfill for the Mbstring extension symfony/polyfill-php56 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions symfony/process v6.1.3 v6.2.0 Executes commands in sub-processes symfony/property-access v6.1.7 v6.2.3 Provides functions to read and write from/to an object or array using a simple string notation symfony/property-info v6.1.9 v6.2.3 Extracts information about PHP class' properties using metadata of popular sources symfony/routing v6.1.9 v6.2.3 Maps an HTTP request to a set of configuration variables symfony/security-acl v3.3.2 v3.3.2 Symfony Security Component - ACL (Access Control List) symfony/security-bundle v6.1.9 v6.2.3 Provides a tight integration of the Security component into the Symfony full-stack framework symfony/security-core v6.1.9 v6.2.2 Symfony Security Component - Core Library symfony/security-csrf v6.1.0 v6.2.0 Symfony Security Component - CSRF Library symfony/security-http v6.1.9 v6.2.2 Symfony Security Component - HTTP Integration symfony/serializer v6.1.9 v6.2.3 Handles serializing and deserializing data structures, including object graphs, into array structures or other forma... symfony/service-contracts v3.2.0 v3.2.0 Generic abstractions related to writing services symfony/string v6.1.9 v6.2.2 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unifie... symfony/translation v6.1.6 v6.2.3 Provides tools to internationalize your application symfony/translation-contracts v3.2.0 v3.2.0 Generic abstractions related to translation symfony/twig-bridge v6.1.9 v6.2.3 Provides integration for Twig with various Symfony components symfony/twig-bundle v6.1.9 v6.2.3 Provides a tight integration of Twig into the Symfony full-stack framework symfony/validator v6.1.9 v6.2.3 Provides tools to validate values symfony/var-dumper v6.1.9 v6.2.3 Provides mechanisms for walking through any arbitrary PHP variable symfony/var-exporter v6.1.9 v6.2.3 Allows exporting any serializable PHP data structure to plain PHP code
PHP 8.1.12
Description:
When trying to filter with page type (cms, hybrid) and error is thrown
Steps to reproduce
go to: admin/app/sonatapagepage/tree click on filter click on pagetype and select either cms or hybrid
Expected results
See the filtered tree of the pages
Actual results
TypeError: Sonata\PageBundle\Admin\PageAdmin::Sonata\PageBundle\Admin{closure}(): Argument #4 ($data) must be of type array, Sonata\AdminBundle\Filter\Model\FilterData given, called in /usr/src/app/vendor/sonata-project/doctrine-orm-admin-bundle/src/Filter/CallbackFilter.php on line 29
at vendor/sonata-project/page-bundle/src/Admin/PageAdmin.php:197 at Sonata\PageBundle\Admin\PageAdmin::Sonata\PageBundle\Admin{closure}(object(ProxyQuery), 'o', 'hybrid', object(FilterData)) (vendor/sonata-project/doctrine-orm-admin-bundle/src/Filter/CallbackFilter.php:29) at Sonata\DoctrineORMAdminBundle\Filter\CallbackFilter->filter(object(ProxyQuery), 'o', 'hybrid', object(FilterData)) (vendor/sonata-project/doctrine-orm-admin-bundle/src/Filter/Filter.php:44) at Sonata\DoctrineORMAdminBundle\Filter\Filter->apply(object(ProxyQuery), object(FilterData)) (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:276) at Sonata\AdminBundle\Datagrid\Datagrid->applyFilters(array('site' => object(FilterData), 'name' => object(FilterData), 'type' => object(FilterData), 'pageAlias' => object(FilterData), 'parent' => object(FilterData), 'edited' => object(FilterData), 'hybrid' => object(FilterData), '_sort_by' => '', '_sort_order' => null, '_page' => '1', '_per_page' => '25')) (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:120) at Sonata\AdminBundle\Datagrid\Datagrid->buildPager() (vendor/sonata-project/admin-bundle/src/Datagrid/Datagrid.php:103) at Sonata\AdminBundle\Datagrid\Datagrid->getResults() (vendor/twig/twig/src/Extension/CoreExtension.php:1635) at twig_get_attribute(object(Environment), object(Source), object(Datagrid), 'results', array(), 'any', false, false, false, 34) (var/cache/dev/twig/8f/8ff49f73c187df6ff2768ecc0749dd83.php:67)
Extra notes
seems that the type of the filter has changed in the sonata admin bundle and the one that sonata page is passing is wrong