Should the
LoggerChannelTrait
be deprecated, then, to encourage service injection and discourage new uses of the trait?- πΊπΈUnited States mile23 Seattle, WA
Searching through Drupal 11, I see that: A) LoggerChannelTrait is unused within core, and B) therefore no services follow this pattern. That's a step forward, I'd say... I assume the trait is still in use in contrib, which is why it's not deprecated at this point though maybe it should be.
Also, core now defines logger channels as services, rather than the factory, so you see this pattern in core.services.yml:
logger.channel_base: abstract: true class: Drupal\Core\Logger\LoggerChannel factory: ['@logger.factory', 'get'] logger.channel.default: parent: logger.channel_base arguments: ['system'] logger.channel.php: parent: logger.channel_base arguments: ['php'] ... views.entity_schema_subscriber: class: Drupal\views\EventSubscriber\ViewsEntitySchemaSubscriber arguments: ['@entity_type.manager', '@logger.channel.default']
So yay, even better.
Yes, there are plenty of uses in contrib.
Deprecating it would probably help encourage contrib to use injection.
- π©πͺGermany donquixote
@mile23
Searching through Drupal 11, I see that: A) LoggerChannelTrait is unused within core, and B) therefore no services follow this pattern.
I do find it used in the following places in core:
core/lib/Drupal/Core/Controller/ControllerBase.php
core/lib/Drupal/Core/Form/FormBase.php
core/modules/layout_builder/src/Plugin/Derivative/FieldBlockDeriver.php
core/modules/jsonapi/src/ResourceType/ResourceTypeRepository.php
core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
core/modules/views/src/ViewExecutable.php
core/modules/language/src/LanguageNegotiator.phpAt least LanguageNegotiator is a service.
But the bigger usage is through base classes ControllerBase and FormBase, which also have other Drupal::*() calls.I wonder if we should stop using these base classes with their hidden magic.