Problem/Motivation
#2208429: Extension System, Part III: ExtensionList, ModuleExtensionList and ProfileExtensionList makes it possible to deprecate \Drupal\Core\Extension\ModuleHandlerInterface::getName() and replace it with calls to \Drupal::service('extension.list.module')->getName($module)
Proposed resolution
Mark ModuleHandlerInterface::getName() as @deprecated. Include @see for the change record.
Cause ModuleHandler::getName() to @trigger_error(E_USER_DEPRECATED). (Note this is the implementation, not the interface.)
Replace all core usages of ModuleHandler::getName() with ModuleExtensionList::getName(). (I found two in language.module, there are probably others.)
Add a new method \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleExtensionList().
Helpful links on deprecation: https://www.drupal.org/core/deprecation#how-method
Remaining tasks
User interface changes
None
API changes
ModuleHandler::getName()is deprecated- New method
\Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleExtensionList()is added
Data model changes
None
| Comment | File | Size | Author |
|---|
Issue fork drupal-2926070
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:
- 2926070-deprecate-modulehandlerinterfacegetname
changes, plain diff MR !5845
- 11.x
compare
Comments
Comment #2
ioana apetri commentedI will work on this.Could you tell me where is specifically used? I cannot see anywhere. Thanks
Comment #4
mile23Updated IS with some instructions. Thanks for taking it on, @yo30.
Comment #5
mile23Comment #6
zahord commentedHi, I've create a patch with the change after the update of 8.6.x, I hope it works.
Comment #7
zahord commentedComment #9
zahord commentedComment #10
zahord commentedComment #11
mile23Thanks. Looking pretty good except for a few things.
Still needs to @trigger_error() in the implementation.
Trailing whitespace, and the change record is https://www.drupal.org/node/2709919
Comment #12
yogeshmpawarUpdated patch with changes addressed in comment #11 & also added interdiff.
Comment #13
alexpott#11.1 needs implementing. See https://www.drupal.org/core/deprecation
Comment #14
yogeshmpawarThanks @alexpott for pointing this issue mentioned in comment #11.1, also added an interdiff.
Comment #16
yogeshmpawarFew changes in patch & PHPLint error removed.
Comment #18
yogeshmpawarSorry, my bad missed one line to remove & added updated patch with an interdiff.
Comment #20
zahord commentedAdded an update in PermissionHandler::getModuleNames()
Comment #21
zahord commentedComment #23
zahord commentedComment #24
zahord commentedComment #26
MerryHamster commentedI hope changes help reduce bugs in tests
Comment #27
MerryHamster commentedComment #29
andypostTest injection into
PermissionHandlerComment #31
zahord commentedUpdated to prevent error when PermissionHandlerTest
Comment #32
zahord commentedComment #35
gnugetHi @zahord.
Thanks for your patch!
I reviewed the patch and found a few things that need to be fixed before to be ready.
I'm going to work on those later this week unless you wanted to do it :-)
let me know.
David.
Here the extension.list.module can be injected.
Here the service can't be injected but we might want to emulate what was done with the moduleHandler.
I mean, create a function called
getExtensionListModule.Here the
extension.list.modulecan be injected as well.Here we should inject it as well.
Here as well, it should be injected.
here as well.
Here as well.
as well.
Here as well
Remove this extra space at the end of the line.
Comment #36
gnugetHere my first try.
I removed the moduleHandler in the plugins where it wasn't used anymore.
I used this line to make sure that we removed all the old calls:
And I fixed all the points from #35
Comment #38
mile23Should be
__METHOD__ . 'is deprecated....'like you see inparseDependency().Also, we're up to 8.7.x now, so we have to change that in both of the deprecation messages.
Comment #39
gnugetHi @Mile23
Thank you for your review.
Ok New patch, I did the following changes:
TestModuleExtensionList) and instead I mocked the ModuleExtensionList.And let's see what the bot says at this time :-)
The commands used to check if all the methods were updated are:
Comment #40
andypostFinally green and yay! few things needs work
var never set - use `!isset()` condition to get service to static cache
would be great to add why that added and follow-up to get rid of
Comment #41
tim.plunkettReading through this issue, I understand that we *can* deprecate
ModuleHandlerInterface::getName()But I don't see any discussion of why we should.
The module handler service seems like the perfect place to consult when looking for this information.
Just because it itself has to delegate to another service to find the answer doesn't mean that all module devs should do the same instead.
Additionally, you end up with code like this, where you need TWO separate services injected:
Why do we want to encourage devs to use the
extension.list.moduleservice directly?I think the abstraction of keeping it on the module handler is a good one.
Comment #42
alexpott@tim.plunkett I think that #41 is a good point. The one reason that sticks out for me is the ModuleHandler is about handling installed modules, calling their hooks and loading their code.
The above code is super odd to me.
Comment #43
gnugetThanks for all your comments!
40.1
I almost copied
getModuleHandlerto creategetModuleExtensionListand there the moduleHandler is not set either, and I think that is on purpose because this is a trait, so we cannot know if the class that used this trait defined the var or not, so it tries to check if it is defined and if that is the case then it uses it if not then get the service.41.2
I had to define the constant because it is used at
Drupal\Core\Extension\ModuleExtensionList::defaultsnot sure if we can just get rid of it, the same happened withDrupal\Core\Extension\ThemeHandlerand atThemeHandlerTestthese constants were defined as well at the end of the tests, and there wasn't added a comment explaining why they were defined there, should I anyway add the comment?I noticed a small error so I attach a new patch.
I hope this address #42, if you want me to change something anyway let me know and I will provided a new patch.
Thanks again.
David.
Comment #44
alexpottHere's one thing that's annoying - it'd be nice if the extension object was more aware...
¯\_(ツ)_/¯
Comment #45
alexpottThe module handler is not required anymore and should be removed.
We don;t need the module handler code here anymore really. The getting of list and checking if it is there could be achieved with the module list service. We could catch
\Drupal\Core\Extension\Exception\UnknownExtensionExceptioninstead of getting the list here.Comment #46
mile23Generally, if you're doing this then you're really writing a kernel test and don't know it yet. If we can move the tests to be kernel tests without changing what they're testing, then maybe we should. But if we leave them as unit tests, we should at least mark them as
@runTestsInSeparateProcessesso we don't pollute the constant space for other tests. And also add@todoso we can change them in #2908079: Move some of the bootstrap.inc PHP-related constants to \Drupal and deprecate the old versionsComment #47
gnugetHi AlexPott.
45.1
Yes it is used, not by
MenuLinkDefaultFormbutViewsMenuLinkFormextends this class and there it is being used atbuildConfigurationForm45.2
Ok, new patch attached (I didn't deleted
getModuleHandler()even if it is not used anymore because it is a public function and not sure if I will break the BC if I delete it) this is pretty similar to what I did on #3012962 :-)Comment #48
almaudoh commentedThis is actually a bug. The exception should be UninstalledExtensionException. This particular wtf is one of the reasons for deprecating
ModuleHandler::getName(). A thing to do here would be to get them to behave the same.Comment #50
gnuget#46
I haven't the expertise to say if we can convert this into a KernelTest, so I will let to someone else decide about that, for now I just added the
@todoand the@runTestsInSeparateProcessesin the tests which define the constant.Also, I fixed the failing test.
Comment #52
dawehnerI guess at this point we would need to reroll this patch against 8.8.x
I'm confused, why are we adding a DRUPAL_MINIMUM_PHP which is lower than the real value right now?
Comment #53
gnugetNew patch rerolled against 8.8.x
No idea, I just updated the patch to use the real value.
Comment #54
larowlanAnswering @tim.plunkett in #41, there is a hidden circular dependency between the module handler and the extension list.
ExtensionList has module handler injected, and ModuleHandler::getName() refs the extension list.
So this would resolve that. But yeah, there are other ways around that, such as a setModuleExtensionList method on module handler, which we could call from ModuleExtensionList::construct, but that still hides the dependency
Comment #61
smustgrave commentedShould this be going into 10?
Comment #62
andypostYes, thank you
Comment #63
smustgrave commentedTook a shot. Lets see what fails.
Comment #64
smustgrave commentedApologize can't get phpstan working on D10 so if this fails sorry!
Comment #65
smustgrave commentedComment #67
smustgrave commentedComment #69
smustgrave commentedComment #71
smustgrave commentedComment #72
kim.pepperWe need a legacy test for this deprecation
We shouldn't need to do this anymore. See https://www.drupal.org/node/2909361
ditto
ditto
Comment #73
smustgrave commentedAddressed #72
Comment #74
kim.pepperWe should add an assert here.
Comment #75
smustgrave commentedUpdated based on #74
Comment #76
daffie commentedWith the change from this issue is the module handler service no longer used. It can be properly deprecated. The ViewsMenuLinkForm is extending this class and it is using the module handler service. Therefor in that class the module handler service need to be added.
Can we change this line to:
catch (UnknownExtensionException $e) {We add a new service always to the end of the list, not somewhere in the middle. It is easier for classes that are overriding the class we are changing.
We cannot just remove an exiting service from a class. The problem is that an overridding class might be using the service and when we remove it the overriding will fail. This is a BC break. So module handler service needs to be properly deprecated in this issue.
Again we cannot just remove a service. It need to be properly deprecated.
Again we cannot just remove a service. It need to be properly deprecated.
Comment #77
smustgrave commentedInterdiff is missing some changes. I use patchutils and get an error sometimes when the changes are alot.
This patch needed a reroll also
I addressed the points in #76 to best my ability. Could use some feedback on the deprecated service if that was done correctly.
Comment #79
andypostHere's fixes and clean-up
Comment #81
andypostFix broken test
Comment #82
smustgrave commentedApplied patch #81
Searched for "Drupal::service('module_handler')->getName" only instance I found was in the test.
Change record appears to list those classes that have been updated with a new argument.
Think this is good.
Comment #83
alexpottWith these changes \Drupal\Core\Plugin\CategorizingPluginManagerTrait::getModuleHandler is unused so we should deprecate it.
Why public? I think the old getModuleHandler() was public by mistake. This doesn't feel like it should be a public method of a plugin manager.
The module handler can be deprecated here - use a union id
ModuleHandlerInterface|ModuleExtensionList $module_handlerand theDeprecatedServicePropertyTrait. This is better than doing constructor promotion because it means less change in the future. It does mean you'll have to add the typehinted property the ModuleExtensionList but it means we don't have a NULL argument and we don't have to go about removing the module handler later.We need to deprecate passing in module handler here. We can use a union on the last argument to pass in either a module handler or a module extension list and do the right thing. We can also use the deprecatedServicePropertyTrait to provide BC.
Module handler is not longer used... we can use a union and to the same as above here.
Comment #84
andypostI think better to parent the issue to #2941155: ModuleHandler should not maintain list of installed modules now that ModuleExtensionList exists according to #42
needs summary update for newAPI changes at least
Patch to address review #83
Comment #85
andypostAnd re-roll for 10.2 as beta phase + minor clean-up
Comment #87
andypostUnrelated failure
Comment #88
smustgrave commentedCan't believe we are already in 10.2.
Any idea when a 10.2.x-dev will be opened? This ticket should probably be postponed on that.
But the deprecation looks good.
Moving to NW for the issue summary update you tagged in #84.
Comment #89
kim.pepperUpdated IS.
Comment #90
smustgrave commentedIS looks good!
Do we have 10.2 tag?
Comment #92
smustgrave commentedrandom
Comment #94
kim.pepperNeeds a rebase on 11.x
Comment #95
andypostre-roll after context change in #3325557: Enable more service autowiring by adding interface aliases to core modules
Comment #96
smustgrave commentedReroll looks good
Comment #100
andypostThank you for re-roll and updating deprecation to 10.3
Comment #101
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #103
dimitriskr commentedComment #104
smustgrave commentedUpdated the versions on the CR
Comment #105
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #106
kim.pepperRebased on 11.x. Back to RTBC
Comment #107
catchNeeds another rebase.
Comment #108
andypostRebased
Comment #109
smustgrave commentedRebase seems good.
Comment #112
catchCommitted/pushed to 11.x and cherry-picked to 10.3.x, thanks!
Comment #113
chi commentedThere is something wrong here. ExtensionList is marked as internal. We should not recommend using it in change records.
Comment #114
catchFrom the ExtensionList docs:
This doesn't apply to the existing public methods.
Comment #115
chi commentedAs long as it has class level
@internaltag the whole class is considered as internal by static analyzers. We might need to move the@internaltag to particular methods in that class.