sonata-project / SonataAdminBundle

The missing Symfony Admin Generator
https://docs.sonata-project.org/projects/SonataAdminBundle
MIT License
2.11k stars 1.26k forks source link

"sonata.admin.request.fetcher " not found when instantiating custom Admin action #7459

Closed donatascn closed 3 years ago

donatascn commented 3 years ago

Environment

Sonata
``` $ composer show --latest 'sonata-project/*' Color legend: sonata-project/admin-bundle 4.0.0-rc.2 4.0.0-rc.2 The missing Symfony Admin Generator sonata-project/block-bundle 4.7.0 4.7.0 Symfony SonataBlockBundle sonata-project/cache 2.2.0 2.2.0 Cache library sonata-project/doctrine-extensions 1.13.1 1.13.1 Doctrine2 behavioral extensions sonata-project/doctrine-orm-admin-bundle 4.0.0-rc.2 4.0.0-rc.2 Integrate Doctrine ORM into the SonataAdminBundle sonata-project/exporter 2.7.0 2.7.0 Lightweight Exporter library sonata-project/form-extensions 1.9.0 1.9.0 Symfony form extensions sonata-project/twig-extensions 1.7.0 1.7.0 Sonata twig extensions ```
Symfony
``` $ composer show --latest 'symfony/*' symfony/contracts v1.1.10 v2.4.0 A set of abstractions extracted out of the Symfony components symfony/deprecation-contracts v2.4.0 v2.4.0 A generic function and convention to trigger deprecation notices symfony/maker-bundle v1.31.1 v1.33.0 Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code. symfony/monolog-bundle v3.5.0 v3.7.0 Symfony MonologBundle symfony/phpunit-bridge v4.4.13 v5.3.4 Symfony PHPUnit Bridge symfony/polyfill-apcu v1.18.1 v1.23.0 Symfony polyfill backporting apcu_* functions to lower PHP versions symfony/polyfill-ctype v1.23.0 v1.23.0 Symfony polyfill for ctype functions symfony/polyfill-iconv v1.18.1 v1.23.0 Symfony polyfill for the Iconv extension symfony/polyfill-intl-grapheme v1.22.1 v1.23.1 Symfony polyfill for intl's grapheme_* functions symfony/polyfill-intl-icu v1.22.1 v1.23.0 Symfony polyfill for intl's ICU-related data and classes symfony/polyfill-intl-idn v1.22.1 v1.23.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions symfony/polyfill-intl-normalizer v1.22.1 v1.23.0 Symfony polyfill for intl's Normalizer class and related functions symfony/polyfill-mbstring v1.22.1 v1.23.1 Symfony polyfill for the Mbstring extension symfony/polyfill-php70 v1.20.0 v1.20.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions symfony/polyfill-php72 v1.22.1 v1.23.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions symfony/polyfill-php73 v1.22.1 v1.23.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP versions symfony/polyfill-php80 v1.22.1 v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions symfony/polyfill-php81 v1.23.0 v1.23.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions symfony/polyfill-uuid v1.22.1 v1.23.0 Symfony polyfill for uuid functions symfony/psr-http-message-bridge v2.1.0 v2.1.1 PSR HTTP message bridge symfony/security-acl v3.1.1 v3.2.0 Symfony Security Component - ACL (Access Control List) symfony/string v5.3.3 v5.3.3 Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way symfony/swiftmailer-bundle v3.3.1 v3.5.2 Symfony SwiftmailerBundle symfony/symfony v4.4.25 v5.3.6 The Symfony PHP framework ```

PHP version

PHP 7.4.22 (cli) (built: Aug  6 2021 23:34:16) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Subject

Getting an error when loading list view of an Admin that has a custom Action defined.

Steps to reproduce

Create a custom Admin action according to this guide and try accessing list view of the Admin

Expected results

List view loads.

Actual results

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
The "sonata.admin.request.fetcher" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

  at vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:275
  at Symfony\Component\DependencyInjection\Container->make()
     (vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:231)
  at Symfony\Component\DependencyInjection\Container->get()
     (vendor/sonata-project/admin-bundle/src/Controller/CRUDController.php:902)
  at Sonata\AdminBundle\Controller\CRUDController->configureAdmin()
     (vendor/sonata-project/admin-bundle/src/EventListener/ConfigureCRUDControllerListener.php:40)
  at Sonata\AdminBundle\EventListener\ConfigureCRUDControllerListener->onKernelController()
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/WrappedListener.php:126)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke()
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:264)
  at Symfony\Component\EventDispatcher\EventDispatcher->doDispatch()
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:239)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners()
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/EventDispatcher.php:73)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch()
     (vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/Debug/TraceableEventDispatcher.php:168)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch()
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:146)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw()
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php:80)
  at Symfony\Component\HttpKernel\HttpKernel->handle()
     (vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:201)
  at Symfony\Component\HttpKernel\Kernel->handle()
     (web/app_dev.php:19)
dmaicher commented 3 years ago

Seems like your CRUD controller class is not configured properly as a service subscriber.

See https://github.com/sonata-project/SonataAdminBundle/blob/4.x/src/Controller/CRUDController.php#L91

Normally this sonata.admin.request.fetcher service is provided within a service locator.

Is your controller service tagged as container.service_subscriber? If not easiest would be to enable autoconfiguration for it.

Also see https://symfony.com/doc/current/service_container/service_subscribers_locators.html#defining-a-service-subscriber

VincentLanglet commented 3 years ago

We might need to update the doc https://github.com/sonata-project/SonataAdminBundle/blob/4.x/docs/reference/architecture.rst#crudcontroller or some other doc.

donatascn commented 3 years ago

Having it in docs would help. Thanks!

VincentLanglet commented 3 years ago

Having it in docs would help. Thanks!

Can you do a PR to update the docs with the change you made ? :)