Language module makes decorating of language manager hard

Created on 11 February 2019, almost 6 years ago
Updated 1 August 2024, 4 months ago

Problem/Motivation

Language module alters definition of 'language_manager' service from core.services.yml (see LanguageServiceProvider::alter()):

<?php
  public function alter(ContainerBuilder $container) {
    $definition = $container->getDefinition('language_manager');
    $definition->setClass('Drupal\language\ConfigurableLanguageManager')
      ->addArgument(new Reference('config.factory'))
      ->addArgument(new Reference('module_handler'))
      ->addArgument(new Reference('language.config_factory_override'))
      ->addArgument(new Reference('request_stack'));
    if ($default_language_values = $this->getDefaultLanguageValues()) {
      $container->setParameter('language.default_values', $default_language_values);
    }
  }
?>

This way of altering the service makes it hard for non-core modules to decorate the service, since the decorator cannot know the class of decorated service.

Proposed resolution

Instead of altering language manager service, language module could declare another public service, which will decorate language manager service.

Remaining tasks

- Create the new service (language.language_manager?) in language.services.yml
- Remove LanguageServiceProvider::alter() method
- Update the code of language module to use the new service
- Update the tests

User interface changes

No UI changes

API changes

New service language.language_manager, existing only when language module is enabled

Data model changes

No data model changes.

Release notes snippet

Language module exposes its own, extended language_manager service as language.language_manager

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Language moduleΒ  β†’

Last updated about 1 month ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡§πŸ‡¬Bulgaria valthebald Sofia

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    Tagging for tests to show the new service functionality

    This will need an upgrade path for the backwards compatibility since it's changing existing services. Instead of changing them may need to pass in the new service and have a trigger_error.

    Needs a change record to announce the new service and changes to existing one.

    Thanks!

  • πŸ‡¦πŸ‡ΊAustralia acbramley

    This has been triaged as part of bug smash. Along with #21 this also needs a reroll and retarget of the MR to 11.x

Production build 0.71.5 2024