Problem/Motivation
After the introduction of ModuleInstaller::invoke() the ModuleHandler::add* method family likely belongs to ModuleInstaller, if at all. In the current state it does not accurately represent what users may expect.
It picks up procedural implementations only.
This is because OOP implementations would need a container rebuild.
ModuleHandler::add() is protected, it is called by ModuleHandler::addProfile() and ModuelHandler::addModule().
These two in turn are only called here:
install.core.inc
// Override the module list with a minimal set of modules.
$module_handler = \Drupal::moduleHandler();
if (!$module_handler->moduleExists('system')) {
$module_handler->addModule('system', 'core/modules/system');
}
if ($profile && !$module_handler->moduleExists($profile)) {
$module_handler->addProfile($profile, $install_state['profiles'][$profile]->getPath());
}
Also in authorize.php
// We have to enable the user and system modules, even to check access and
// display errors via the maintenance theme.
\Drupal::moduleHandler()->addModule('system', 'core/modules/system');
\Drupal::moduleHandler()->addModule('user', 'core/modules/user');
\Drupal::moduleHandler()->load('system');
\Drupal::moduleHandler()->load('user');
// Initialize the maintenance theme for this administrative script.
drupal_maintenance_theme();
It is called in several tests:
- core/tests/Drupal/KernelTests/KernelTestBase.php
- core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
- core/tests/Drupal/Tests/UpdatePathTestTrait.php
Steps to reproduce
N/A
Proposed resolution
Replace calls to addModule() and addProfile() in core.
Deprecate addModule() and addProfile().
Mark add() for deletion when addModule() and addProfile() are removed in Drupal 12.
Remaining tasks
N/A
User interface changes
N/A
Introduced terminology
N/A
API changes
Do not call addModule() or addProfile()
Data model changes
N/A
Release notes snippet
N/A
Issue fork drupal-3481778
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ghost of drupal pastComment #3
nicxvan commentedComment #4
nicxvan commentedComment #5
nicxvan commentedComment #8
nicxvan commentedComment #9
nicxvan commentedComment #11
nicxvan commentedComment #12
daffie commentedBack to NW for the 2 remarks on the MR.
Comment #13
nicxvan commentedI think I answered your concerns, let me know if you have any further questions.
Comment #14
daffie commentedMy questions have been answered.
All code changes look good to me.
The IS and the CR are in order.
For me it is RTBC.
Comment #15
dwwThanks for working on this!
GitLab thinks this needs a rebase due to conflicts.
Meanwhile, I opened some MR threads, mostly with pedantic nits.
Comment #16
nicxvan commentedYeah I saw the conflict but when I went to rebase it was gone, maybe an issue was reverted I'll fix it and address your comments.
Comment #17
nicxvan commentedRebase is werd I'll look tomorrow
Comment #18
nicxvan commentedRebased and comments addressed.
Comment #19
dwwThe functional test fails in https://git.drupalcode.org/issue/drupal-3481778/-/pipelines/367140 are random, but the fail in Unit is legit. Opened MR threads with suggestions.
Almost there, thanks!
-Derek
Comment #20
nicxvan commentedComment #21
dwwWhereas:
Therefore, RTBC!
Thanks again,
-Derek
Comment #22
dwwComment #23
longwaveThis looks like a nice cleanup, added a couple of minor questions to the MR.
Comment #24
nicxvan commentedI replied to the comments that I could not address.
Comment #25
nicxvan commentedFollow up created and all comments addressed.
Comment #26
smustgrave commentedResolved all threads
When looking at the CR though it wasn't super clear, maybe something like
ModuleHandler::addModule and ModuleHandler::addProfile have been deprecated. There is no direct replacement. (can the reason why be mentioned?)
Adding modules or profiles run time is not supported. Use ModuleInstallerInterface::install instead.
before/after implementations or least an after of how one would use ModuleInstallerInterface::install
Comment #27
nicxvan commentedUpdated the CR.
Comment #28
smustgrave commentedThanks!
CR reads much better. I believe all feedback for this one is complete. Fingers crossed.
Comment #30
quietone commentedI left some questions in the MR. The change record before section should be for 'addModule' and 'addProfile' not 'add'. Tagging for updates.
Comment #31
oily commented@quiteone RE: #30, updated the CR.
Comment #32
oily commentedDealt with 2 of 3 review comments in the MR. Rebased. The 3rd review comment involves a code comment. I am not sure what the coder's reason for the comment was. Hopefully they can deal with that review comment.
Comment #33
nicxvan commentedI will revert one of your changes you removed the deprecation on module handler add.
I'll address the remaining comment too it just needs to be more imperative.
Comment #34
oily commented@nicxvan Ah, I see. Thank you for fixing.
Comment #35
nicxvan commented@quietone, I don't think we can change the return type since it's inherit doc and the parent has return type of array|false?
Is that ok?
Comment #36
nicxvan commentedComment #38
nicxvan commentedComment #39
nicxvan commentedI rebased on head, the last comment was addressed upstream so this should be ready.
Comment #40
smustgrave commentedCR does appear to be updated so removing that tag.
Checked the MR and all threads do appear to be addressed, even went back and read some older ones.
Feel this could be considered a 11.2 release priority (remove if I'm wrong)
Believe this one is good to go.
Comment #41
catchThis looks good but one small question.
Comment #42
nicxvan commentedThis should be ready now.
Comment #43
mikelutzFeedback addressed, and I gave it a once over myself, this looks good to go.
Comment #45
catchYeah I agree it'd be a horrible idea, but it just made me think about it whereas conditionally setting it doesn't.
Looks good. Committed/pushed to 11.x, thanks!
Comment #48
donquixote commentedThe ModuleHandler::add() is more broken than we thought.
This is the least part of the problem.
Much worse is that it removes existing implementations, and prevents them from being added later.
See #3528899: ModuleHandler::add() removes implementations from other modules.