- Issue created by @ptmkenny
- 🇯🇵Japan ptmkenny
Full stacktrace:
Fatal error: Uncaught TypeError: Drupal\jsonapi_defaults\Controller\EntityResource::__construct(): Argument #12 ($jsonapi_defaults) must be of type Drupal\jsonapi_defaults\JsonapiDefaultsInterface, Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and defined in /var/www/html/web/modules/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php:75 Stack trace: #0 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(259): Drupal\jsonapi_defaults\Controller\EntityResource->__construct() #1 /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php(177): Drupal\Component\DependencyInjection\Container->createService() #2 /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php(20): Drupal\Component\DependencyInjection\Container->get() #3 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(106): Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition() #4 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(219): Drupal\Core\Entity\EntityResolverManager->getControllerClass() #5 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EntityRouteAlterSubscriber.php(48): Drupal\Core\Entity\EntityResolverManager->setRouteOptions() #6 [internal function]: Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber->onRoutingRouteAlterSetType() #7 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func() #8 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteBuilder.php(189): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() #9 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild() #10 /var/www/html/web/core/includes/common.inc(485): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild() #11 /var/www/html/web/core/includes/utility.inc(41): drupal_flush_all_caches() #12 /var/www/html/vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(70): drupal_rebuild() #13 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild() #14 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array() #15 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback() #16 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter() #17 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process() #18 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute() #19 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run() #20 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand() #21 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun() #22 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run() #23 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun() #24 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run() #25 /var/www/html/vendor/drush/drush/drush(4): require('...') #26 /var/www/html/vendor/bin/drush(119): include('...') #27 {main} thrown in /var/www/html/web/modules/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php on line 75 [warning] Drush command terminated abnormally.
- last update
about 1 year ago 17 pass, 2 fail - Status changed to Needs review
about 1 year ago 5:16pm 2 June 2024 - 🇯🇵Japan ptmkenny
The eventDispatcher never got injected, but it is provided by core, so then in construct() all the arguments get out of order, breaking the site. This MR injects the eventDispatcher so that the parent constructor can be called properly.
27:41 25:56 Running23:53 21:57 Running- Status changed to Postponed
about 1 year ago 5:32pm 2 June 2024 - 🇯🇵Japan ptmkenny
So this issue was caused by me having applied the MR in ✨ Allow specifying `meta` data on JSON:API objects Needs work . When this issue eventually gets committed to core, the code will need to be updated, so I'm marking postponed for now. But feel free to close if you would rather handle this once the commit actually happens.
- 🇫🇷France jchatard
I'm trying to upgrade a Drupal 10.x webiste to 11.x and encounter this error.
I'm not entirely sure to understand if the patch was merged to the main branch?
- 🇫🇷France jchatard
So after digging I can confirm that the patch wasn't merged and is working for the upgrade process.
- 🇯🇵Japan ptmkenny
Thanks, but this can't be RTBC yet because the change is not backwards compatible with Drupal < 11.2 (when the metadata feature became available).
- 🇯🇴Jordan Rajab Natshah Jordan
I'm facing the same issue.
Thanks for the MR
Hoping for a new branch4.0.x
to manage this fix in a smoother way. - 🇯🇴Jordan Rajab Natshah Jordan
Attached a static
jsonapi_extras--2025-06-30--3452036--mr-51.patch
file, to this point of MR51.
To be used with Composer Patches and Drupal ~11.2.0 - 🇯🇵Japan ptmkenny
Bumping to major because this actually breaks sites that use 11.2+.
- First commit to issue fork.
- Merge request !69Issue #3452036: Use calls with setter injection in service definition. → (Open) created by godotislate
Put up alternate suggestion in MR 69.
This uses setter injection via method calls in the service definition to avoid overriding the constructor altogether.