Problem/Motivation
Before being able to use the Language system, it needs to be bootstrapped by calling drupal_language_initialize(), or drupal_bootstrap(DRUPAL_BOOTSTRAP_LANGUAGE). This causes many problems as in some cases we don't know whether the language system has been initialized or not.
Proposed resolution
Use Dependency Injection to lazy-initialization the language bootstrap for us, when we need it. This means we'll get rid of DRUPAL_BOOTSTRAP_LANGUAGE, and initialize the bootstrap when we try to retrieve the language objects.
Remaining tasks
User interface changes
None.
API changes
We wouldn't need to call DRUPAL_BOOTSTRAP_LANGUAGE to use the language system, as it will be done for us, whenever we need to use the language system.
| Comment | File | Size | Author |
|---|---|---|---|
| #30 | drupal8.dep-language-init.30.patch | 4.81 KB | yesct |
| #22 | drupal8.dep-language-init.22.patch | 4.74 KB | sun |
| #16 | 1550866_16_language_di.patch | 30.53 KB | cosmicdreams |
| #13 | 1550866_14_language_di.patch | 29.43 KB | cosmicdreams |
| #12 | 1550866_12_language_di.patch | 28.44 KB | cosmicdreams |
Comments
Comment #1
robloachTags
Comment #2
robloachComment #3
timmillwoodIt's not just the language system, we should do this with everything!
Comment #4
gábor hojtsyI think its fare to do it first for languages since we did DI for that first too.
Comment #5
cosmicdreams commentedgiven the goal of this issue we should include the changes to eliminate the use of $GLOBALS for the language system
Comment #6
cosmicdreams commentedcurious to see how this patch tests.
Comment #8
cosmicdreams commentedLooks like it needs a reroll
Comment #10
cosmicdreams commentedSee if combining this patch with #1539614: Modify language module to use Dependency Injection for language makes this handle the exceptions about language_content better.
Comment #12
cosmicdreams commentedFound some $GLOBALS still in use for language dependencies:
Comment #13
cosmicdreams commentedFound two more instances of variables that need to use the DI instead of $GLOBALS
Comment #14
cosmicdreams commentedIn looking at some of the exceptions this is generating I found one code error that I don't know the solution for:
In Language.php, lines 67 - 81 we have this:
In that code block $hook is undefined. Should it be a string? what should it be? Should we get the value through reflection?
How should we proceed?
Comment #16
cosmicdreams commentedI found 5 or 6 more GLOBALS to eliminate. Let's see if this patch score better
Comment #18
cosmicdreams commented#16: 1550866_16_language_di.patch queued for re-testing.
Comment #20
jair commentedNeeds reroll
Comment #20.0
jair commentedUpdated issue summary.
Comment #21
balintcsaba commentedComment #22
sunThe bootstrap phase is gone already. The language system is initialized on-demand.
Technically, I don't see why attached patch should not work.
Comment #23
andypostManually installed d8 in russian, added english and content translation - everything works fine!
Seems this
$language_manager->init();obsolete now so filed follow-up #2214057: Remove obsolete LanguageManagerInterface::init() methodComment #24
plachI am not sure about this hunk: shouldn't we reset the language manager so language is re-negotiated when needed?
Comment #25
andypostSuppose on uninstall the container rebuild happens, so none-configurable language manager is used
Comment #26
cosmicdreams commentedso back to RTBC?
Comment #27
sunI agree with @andypost,
ModuleHandler::uninstall()reboots the kernel + rebuilds the container, which means thatLanguageManageris replaced with a new instance already.hook_modules_uninstalled()is only invoked later on, so a reset in there would actually reset it "twice."Comment #28
plachWorks for me, thanks :)
Comment #29
yesct commentedDoesn't apply. I'll reroll this now.
Comment #30
yesct commentedeasy reroll (automatic 3-way merge, no conflicts).
was a change in context lines:
< \Drupal::setContainer($container);
---
> @@ -376,8 +376,6 @@ function install_begin_request(&$install_state) {
> $container->get('string_translation')
> ->addTranslator($container->get('string_translator.file_translation'));
probably rtbc if green.
Comment #31
andypostComment #32
catchCommitted/pushed to 8.x, thanks!