Logger property of EntityResource should be psr/log compatible

Created on 24 June 2024, 4 days ago

Problem/Motivation

When trying to install this module while using monolog, I get the following error:

TypeError: Cannot assign Psr\Log\NullLogger to property Drupal\jsonapi_defaults\Controller\EntityResource::$logger of type Drupal\Core\Logger\LoggerChannelInterface in /var/www/html/web/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php on line 104 #0 [internal function]: Drupal\jsonapi_defaults\Controller\EntityResource->__construct(Object(Drupal\Core\Entity\EntityTypeManager), Object(Drupal\Core\Entity\EntityFieldManager), Object(Drupal\jsonapi_extras\ResourceType\ConfigurableResourceTypeRepository), Object(Drupal\Core\Render\Renderer), Object(Drupal\Core\Entity\EntityRepository), Object(Drupal\jsonapi\IncludeResolver), Object(Drupal\jsonapi\Access\EntityAccessChecker), Object(Drupal\jsonapi\Context\FieldResolver), Object(Drupal\jsonapi\Serializer\Serializer), Object(Drupal\Component\Datetime\Time), Object(Drupal\Core\Session\AccountProxy), Object(Drupal\jsonapi_defaults\JsonapiDefaults), Object(Drupal\monolog\Logger\MonologLoggerChannelFactory))
#1 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(1140): ReflectionClass->newInstanceArgs(Array)
#2 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(586): Symfony\Component\DependencyInjection\ContainerBuilder->createService(Object(Symfony\Component\DependencyInjection\Definition), Array, true, 'jsonapi.entity_...')
#3 /var/www/html/vendor/symfony/dependency-injection/ContainerBuilder.php(531): Symfony\Component\DependencyInjection\ContainerBuilder->doGet('jsonapi.entity_...', 1)
#4 /var/www/html/web/core/lib/Drupal/Core/DependencyInjection/ClassResolver.php(33): Symfony\Component\DependencyInjection\ContainerBuilder->get('jsonapi.entity_...')
#5 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(106): Drupal\Core\DependencyInjection\ClassResolver->getInstanceFromDefinition('jsonapi.entity_...')
#6 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityResolverManager.php(219): Drupal\Core\Entity\EntityResolverManager->getControllerClass(Array)
#7 /var/www/html/web/core/lib/Drupal/Core/EventSubscriber/EntityRouteAlterSubscriber.php(48): Drupal\Core\Entity\EntityResolverManager->setRouteOptions(Object(Symfony\Component\Routing\Route))
#8 [internal function]: Drupal\Core\EventSubscriber\EntityRouteAlterSubscriber->onRoutingRouteAlterSetType(Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#9 /var/www/html/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(111): call_user_func(Array, Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#10 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteBuilder.php(189): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Drupal\Core\Routing\RouteBuildEvent), 'routing.route_a...')
#11 /var/www/html/web/core/lib/Drupal/Core/ProxyClass/Routing/RouteBuilder.php(83): Drupal\Core\Routing\RouteBuilder->rebuild()
#12 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php(67): Drupal\Core\ProxyClass\Routing\RouteBuilder->rebuild()
#13 /var/www/html/web/core/lib/Drupal/Core/Routing/RouteProviderLazyBuilder.php(83): Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteProvider()
#14 /var/www/html/web/core/lib/Drupal/Core/Installer/InstallerRouteProviderLazyBuilder.php(23): Drupal\Core\Routing\RouteProviderLazyBuilder->getRouteByName('entity.entity_v...')
#15 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(443): Drupal\Core\Installer\InstallerRouteProviderLazyBuilder->getRouteByName('entity.entity_v...')
#16 /var/www/html/web/core/lib/Drupal/Core/Routing/UrlGenerator.php(276): Drupal\Core\Routing\UrlGenerator->getRoute('entity.entity_v...')
#17 /var/www/html/web/core/lib/Drupal/Core/Render/MetadataBubblingUrlGenerator.php(108): Drupal\Core\Routing\UrlGenerator->generateFromRoute('entity.entity_v...', Array, Array, true)
#18 /var/www/html/web/core/lib/Drupal/Core/Url.php(765): Drupal\Core\Render\MetadataBubblingUrlGenerator->generateFromRoute('entity.entity_v...', Array, Array, true)
#19 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(306): Drupal\Core\Url->toString(true)
#20 [internal function]: Drupal\Core\Entity\EntityBase->Drupal\Core\Entity\{closure}('delete-form')
#21 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(315): array_filter(Array, Object(Closure))
#22 /var/www/html/web/core/modules/menu_link_content/menu_link_content.module(105): Drupal\Core\Entity\EntityBase->uriRelationships()
#23 [internal function]: menu_link_content_entity_predelete(Object(Drupal\Core\Entity\Entity\EntityViewMode), 'entity_view_mod...')
#24 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(417): call_user_func_array(Object(Closure), Array)
#25 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(396): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'menu_link_conte...')
#26 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(424): Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_predelet...', Object(Closure))
#27 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(343): Drupal\Core\Extension\ModuleHandler->invokeAll('entity_predelet...', Array)
#28 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(452): Drupal\Core\Config\Entity\ConfigEntityStorage->invokeHook('predelete', Object(Drupal\Core\Entity\Entity\EntityViewMode))
#29 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(362): Drupal\Core\Entity\EntityStorageBase->delete(Array)
#30 /var/www/html/web/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(384): Drupal\Core\Entity\EntityBase->delete()
#31 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(1068): Drupal\Core\Config\Entity\ConfigEntityStorage->importDelete('core.entity_vie...', Object(Drupal\Core\Config\Config), Object(Drupal\Core\Config\Config))
#32 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(851): Drupal\Core\Config\ConfigImporter->importInvokeOwner('', 'delete', 'core.entity_vie...')
#33 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(672): Drupal\Core\Config\ConfigImporter->processConfiguration('', 'delete', 'core.entity_vie...')
#34 /var/www/html/web/core/lib/Drupal/Core/Config/ConfigImporter.php(570): Drupal\Core\Config\ConfigImporter->processConfigurations(Array)
#35 /var/www/html/web/core/lib/Drupal/Core/Config/Importer/ConfigImporterBatch.php(31): Drupal\Core\Config\ConfigImporter->doSyncStep('processConfigur...', Array)
#36 /var/www/html/web/core/includes/batch.inc(296): Drupal\Core\Config\Importer\ConfigImporterBatch::process(Object(Drupal\Core\Config\ConfigImporter), 'processConfigur...', Array)
#37 /var/www/html/web/core/includes/form.inc(977): _batch_process()
#38 /var/www/html/web/core/includes/install.core.inc(654): batch_process(Object(Drupal\Core\Url), Object(Drupal\Core\Url))
#39 /var/www/html/web/core/includes/install.core.inc(572): install_run_task(Array, Array)
#40 /var/www/html/web/core/includes/install.core.inc(122): install_run_tasks(Array, Array)
#41 /var/www/html/vendor/drush/drush/includes/drush.inc(69): install_drupal(Object(Composer\Autoload\ClassLoader), Array, Array)
#42 /var/www/html/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array('install_drupal', Array)
#43 /var/www/html/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(167): drush_op('install_drupal', Object(Composer\Autoload\ClassLoader), Array, Array)
#44 [internal function]: Drush\Commands\core\SiteInstallCommands->install('minimal', Array)
#45 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
#46 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
#47 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(176): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#48 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(391): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
#49 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#50 /var/www/html/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#51 /var/www/html/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#52 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#53 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#54 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
#55 /var/www/html/vendor/drush/drush/drush.php(139): Drush\Runtime\Runtime->run(Array)
#56 /var/www/html/vendor/drush/drush/drush(4): require('/var/www/html/v...')
#57 /var/www/html/vendor/bin/drush(119): include('/var/www/html/v...')
#58 {main}
TypeError: Cannot assign Psr\Log\NullLogger to property Drupal\jsonapi_defaults\Controller\EntityResource::$logger of type Drupal\Core\Logger\LoggerChannelInterface in Drupal\jsonapi_defaults\Controller\EntityResource->__construct() (line 104 of /var/www/html/web/modules/contrib/jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php).

For some reason it only started to happen after upgrading to Drupal 10.3. However, the point still stands. I could use a null logger while developing locally if I wanted :)

Steps to reproduce

Use monolog. Install the module. Probably clear the cache?

Proposed resolution

Use the logger annotations from psr/log instead. This is consistently done in core as well.

Remaining tasks

- review
- commit

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

πŸ‡³πŸ‡΄Norway eiriksm Norway

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024