Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Currently the notification of entity type creation/deletion is hard-coded in the module handler. The reason is that this needs happen right after module schema has been installed, but before hook_install
is called.
Proposed resolution
Introduce an event to which the Entity Manager can subscribe and react and decouple the module handler from the entity manager.
Remaining tasks
- Agree on the solution
- Write a patch
- Reviews
User interface changes
None
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#76 | 2350111-76.patch | 15.02 KB | jofitz |
#76 | interdiff-75-76.txt | 5.04 KB | jofitz |
#75 | 2350111-75.patch | 14.69 KB | jofitz |
#69 | 2350111-67.patch | 14.71 KB | jibran |
Comments
Comment #1
plachComment #2
plachComment #3
tim.plunkett+1, #2561639: Wrong placeholder for exception shown when new fields are created during module installation was very strange to see entity field code directly in ModuleInstaller
Comment #4
dawehnerLet's see how much breaks
Comment #6
tim.plunkettMissing a constructor. Also, from what I remember, pulling each service from the container during each loop was important when installing a module that adds new entity types.
onModuleUninstall
Also, isn't there a preUninstall portion too?
Comment #7
dawehnerSo there is currently:
so I guess we would have also pre, and after ideally?
Comment #9
dawehnerThere we go.
Comment #10
dawehnerPatch still applies. Anyone interested in a review exchance?
Comment #11
tim.plunkett$this->kernel->getContainer()?!
Why can't the event dispatcher be injected? If it's for a good reason, we should probably have a comment here so no one tries to inject it later.
Comment #12
dawehnerGood point!
Comment #13
znerol CreditAttribution: znerol commentedThere is
ModuleInstaller::updateKernel()
which is supposed to refresh dependencies injected intoModuleInstaller
. Therefore it should be safe to inject the event dispatcher dependency and reuse the existing mechanism to refresh its reference where appropriate.Comment #14
dawehnerGood point!
Comment #15
amateescu CreditAttribution: amateescu as a volunteer commentedHmm, is there any reason for not using the injected event dispatcher? Wasn't that the whole point of the change in #14? :)
Comment #16
dawehnerUps, you are totally right.
Comment #17
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI know this is just moved code but the comment here is wrong, we're in the "uninstall" part of the code :)
Comment #18
dawehnerSure, let's fix that.
Comment #19
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedShould we mention that this is actually the (machine) name of the module being installed / uninstalled?
Can't find anything else to complain about so let's do this :)
Comment #20
dawehnerSure, we can do that.
Comment #21
tim.plunkett+1 for RTBC, thanks @znerol for pointing out the ModuleInstaller::updateKernel() bit!
Comment #23
tim.plunkett#2679547: Fix random fail in ConfigImportAllTest caused by ModuleInstaller not rebuilding routes immediately, which happens to be surfaced by BigPipe
Comment #26
dawehnerComment #27
dawehnerLet's try it again.
Comment #28
tim.plunkettWas wondering why we only add dependencies and not remove them, but I see we're removing \Drupal:: calls.
Are any of these other services viable to remove in this patch, or is that a follow-up?
Comment #30
timmillwoodComment #32
XanoI fixed at least one test failure in
CommentLanguageTest
(and likely some others as well), and improved some docblocks.Comment #33
timmillwoodAwesome @Xano!
Comment #34
martin107 CreditAttribution: martin107 commentedNothing significant, just removing a final stray @file tag
Comment #35
dawehnerBack to RTBC
Comment #37
jibranComment #42
daffie CreditAttribution: daffie commentedThe testbot failures are the same as those of the daily automatic testing. So back to RTBC.
Comment #43
daffie CreditAttribution: daffie commentedMy mistake: no failures with the daily automatic testing.
Comment #44
dawehnerPatch was green already.
Added a change record in the meantime.
Comment #46
Mile23Reroll of #34.
Comment #47
dawehnerRE-RTBC as of previous RTBCs
Comment #48
alexpottWe need to refresh the event dispatcher because if a module was being installed as part of a loop and listened to this event it wouldn't have it fired. See \Drupal\Core\Extension\ModuleInstaller::updateKernel()
There was an issue somewhere to add a trait to do this.
Comment #49
dawehner#2380293: Properly inject services into ModuleInstaller is the other one.
Comment #51
saltednut*uninstalled ?
Comment #52
saltednutHappy to work on this with a little more direction.
Comment #53
saltednutThis use statement is repeated.My mistake. Patch addressing maintainer concerns forthcoming.
Comment #54
saltednutPatch addresses #48 and #51
Comment #55
saltednutI am seeing some memory errors when I run a site install using #54 - removing the
$this->eventDispatcher = $container->get('event_dispatcher');
added resolves this, so maybe something else needs to be done?Comment #56
saltednutI am not certain this will work correctly with the UI-based installer, at least based on some testing we have done using this patch and the new event in the config_rewrite project. Do we currently have tests for the installer that ensure events are triggered?
Comment #57
Wim LeersHow does #54 address #48? Is the interdiff incomplete?
Comment #58
Wim LeersWhy are these specific to modules — why are they not generic across all types of extensions?
The only thing I can think of is that this is somehow triggering a recursive loop, perhaps due to some PHP error that is caught/handled in a certain way. Have you already checked the PHP error log?
Comment #59
dawehnerWell, at least as of now a module installation is a completly separate process to theme installation, like a container rebuild just happens on a module rebuild, sure that's worth to consider though.
Comment #61
saltednutReroll of #54
Comment #63
saltednutTestbot seems suspect. See results, need a manual review here if someone can run the tests locally.
https://www.drupal.org/pift-ci-job/600858
Comment #64
Mile23You can restart the test run with the 'Add test/retest' link.
Doing that now.
Comment #66
saltednutThanks, Paul! It looks like its still having issues. Is there something we can do?
Comment #67
saltednutThere is a periodic failure on some environments, but not all:
Otherwise, there are instances of
PHP 5.6 & MySQL 5.5 CI error
I am not sure how to address either of these issues with the testbot, but it seems strange the bot failing for *any* reason would immediately mark the issue as needs work.
I will not flip it back to Needs Review, but there is nothing in the test results that tells me the patch is the source of CI errors or random cache expiry time problems.
Comment #69
jibranRerolled #54 again. #61 was missing a file. Also fixed some docs and injected logger service to the event subscriber.
Comment #70
jibranI realize that we don't need tests for event subscriber so removing the tag.
Other than the discussion on #59 I don't think anything else is pending.
Do we need profiling here?
Comment #72
jibranAnyone up for review.
Comment #73
phenaproximaLooks pretty good to me. Nice work, @jibran et. al!
Why was the router builder removed?
The doc comment is inaccurate :)
Should probably use === here, and in other similar comparisons.
Is it possible to pass the entire Extension object, rather than just the name? If not, can we rename getModule() to getModuleName(), for clarity's sake?
Don't these doc comments need @Event? I've seen that elsewhere in core...
I would normally say this needs tests, but this is the sort of deep change that would break just about every single test in core if it didn't work...so honestly, I feel pretty good about it.
Comment #74
volegerComment #75
jofitz CreditAttribution: jofitz at ComputerMinds commentedRe-roll.
Now to address #73...
Comment #76
jofitz CreditAttribution: jofitz at ComputerMinds commentedComment #77
phenaproximaThanks, @Jo Fitzgerald.
This one seems extremely straightforward. The fact that the tests all pass with it solidly proves that it works, given how foundational the module installer is to the proper functioning of Drupal.
I see no reason to hold off on RTBC.
Comment #78
alexpottThis kinda feels wrong and problematic. If we can't do proper injection this event is going to be fraught with trickiness. For example what happens if a module has a service that is subscribed to this event. Does it fire on its own install. Does it fire on its own uninstall? There's no test coverage of these type of complexities and there needs to be.
Comment #79
dawehnerThis feels fishy. I see there is code inside the module installer (at the end) to update the event subscriber, so shouldn't this allow stuff to continue working without having to go through the kernel? I could imagine people would make a lot of mistakes when they just inject services normally, instead of injecting the kernel. Did someone do the research to understand that this is the only possible option?
Comment #80
dawehner#2206347: Use event system in ModuleHandler, which is essential a duplicate, had a ExtensionEvent. I think this would be a good idea, given all of them could share that.
Comment #81
jibran#2206347: Use event system in ModuleHandler is old but still relevant here. I think we should resocpe #2206347 and postpone on this. Once the events are in we can remove the cache bin code from
ModuleInstaller
as well.Comment #84
saltednutI'd like to see this continue somehow but I believe doing this on the extension level is the best approach? It'd be really good if install profiles, themes and modules all acted pretty much the same way and fired similar events during installation and otherwise.