Problem/Motivation
As part of
π
Update Logger Injection to be Autoconfigured
Active
, services in the Patternkit module were updated autoconfigure injection of the logger service per the changes from
β¨
Add autoconfigure for module loggers
Needs review
. Unfortunately, it seems that this autoconfiguration is failing if the service is marked private using the attribute public: false
.
Specifically, the Drupal\patternkit\Asset\PatternDiscoveryLoader
class was updated to use the new interface and injection of the logger was removed from the constructor. As shown below, the related service definition is marked as private.
patternkit.pattern.discovery.loader:
class: Drupal\patternkit\Asset\PatternDiscoveryLoader
arguments:
- '@patternkit.library.namespace_resolver'
- '@plugin.manager.library.pattern'
public: false
This has resulted in the class's $logger
instance variable remaining null
and throwing a fatal error like the following if a library plugin fails to be discovered:
β― ddev drush cr
[warning] The "file.svg" library plugin was not found
PHP Fatal error: Uncaught Error: Call to a member function info() on null in /var/www/html/src/Asset/PatternDiscoveryLoader.php:132
Stack trace:
#0 /var/www/html/src/Asset/PatternDiscovery.php(218): Drupal\patternkit\Asset\PatternDiscoveryLoader->getPatternsByNamespace()
#1 /var/www/html/src/Asset/PatternDiscovery.php(98): Drupal\patternkit\Asset\PatternDiscovery->buildPatternDefinitions()
#2 /var/www/html/src/Asset/PatternDiscovery.php(138): Drupal\patternkit\Asset\PatternDiscovery->getPatternsByNamespace()
#3 /var/www/html/src/Asset/PatternDiscovery.php(226): Drupal\patternkit\Asset\PatternDiscovery->getPatternDefinitions()
#4 /var/www/html/patternkit.module(79): Drupal\patternkit\Asset\PatternDiscovery->rebuild()
#5 [internal function]: patternkit_rebuild()
#6 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(355): call_user_func_array()
#7 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(307): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()
#8 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(354): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#9 /var/www/html/web/core/includes/common.inc(446): Drupal\Core\Extension\ModuleHandler->invokeAll()
#10 /var/www/html/web/core/includes/utility.inc(41): drupal_flush_all_caches()
#11 /var/www/html/vendor/drush/drush/src/Commands/core/CacheRebuildCommands.php(60): drupal_rebuild()
#12 [internal function]: Drush\Commands\core\CacheRebuildCommands->rebuild()
#13 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array()
#14 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback()
#15 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter()
#16 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process()
#17 /var/www/html/vendor/symfony/console/Command/Command.php(279): Consolidation\AnnotatedCommand\AnnotatedCommand->execute()
#18 /var/www/html/vendor/symfony/console/Application.php(1094): Symfony\Component\Console\Command\Command->run()
#19 /var/www/html/vendor/symfony/console/Application.php(342): Symfony\Component\Console\Application->doRunCommand()
#20 /var/www/html/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRun()
#21 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run()
#22 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun()
#23 /var/www/html/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run()
#24 /var/www/html/vendor/bin/drush.php(119): include('...')
#25 {main}
thrown in /var/www/html/src/Asset/PatternDiscoveryLoader.php on line 132
[warning] Drush command terminated abnormally.
Failed to run drush cr: exit status 1
Steps to reproduce
- Add a library definition with a specified plugin like the following in a module's
*.libraries.yml
file:
svgIcons:
drupalSettings: {}
patterns:
images/icons: { plugin: file.svg }
- Ensure at least one svg file exists in the
images/icons
directory of that module
- Run a cache rebuild with
drush cr
Proposed resolution
Explicitly add the setLogger
call to the patternkit.pattern.discovery.loader
service:
patternkit.pattern.discovery.loader:
class: Drupal\patternkit\Asset\PatternDiscoveryLoader
arguments:
- '@patternkit.library.namespace_resolver'
- '@plugin.manager.library.pattern'
calls:
- ['setLogger', ['@logger.channel.patternkit']]
public: false
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None