Problem/Motivation
Part of #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() effort. Remove usage of drupal_static() from system_get_module_admin_tasks().
Proposed resolution
- Add two new services:
user.module_permissions_link_helper=>Drupal\user\ModulePermissionsLinkHelperfor module permission links andsystem.module_admin_links_helper=>Drupal\system\ModuleAdminLinksHelperfor module admin links
- Deprecate
system_get_module_admin_tasks(). - Deprecate usage of
drupal_static_reset('system_get_module_admin_tasks').
Remaining tasks
Add tests for the new servicesConsider renaming to\Drupal\system\ModuleAdminLinkHelperand\Drupal\user\ModulePermissionsLinkHelperConsider using\Drupal\Core\Cache\MemoryCache\MemoryCacheto keep the ability to flush the cache externally
User interface changes
None.
API changes
- Added two new services:
user.module_permissions_link_helper=>Drupal\user\ModulePermissionsLinkHelperfor module permission links andsystem.module_admin_links_helper=>Drupal\system\ModuleAdminLinksHelperfor module admin links
system_get_module_admin_tasks()is deprecated.- Using
drupal_static_reset()withsystem_get_module_admin_tasksas parameter is deprecated.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #50 | 3038971-50-interdiff.txt | 1.17 KB | kim.pepper |
| #50 | 3038971-50.patch | 25.69 KB | kim.pepper |
Issue fork drupal-3038971
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:
- 3038971-systemgetmoduleadmintasks
changes, plain diff MR !928
Comments
Comment #2
claudiu.cristeapatch.
Comment #3
claudiu.cristeaIn fact this should be a trait, not a service, as is only code reusing between
AdminControllerandHelpController.Comment #4
andypostMixed feelings about trait
it does 3 things
- transforms menu links a-ka http://cgit.drupalcode.org/drupal/tree/core/modules/system/src/Plugin/Bl...
- check access to links
- build links
I bet it fits both controllers and blocks
Maybe makes sense to move it to render element?
similar controllers to render links finally
This is tree transformation, which waiting for alter in system menu block, issue #2854013: Allow SystemMenuBlock tree manipulators to be altered
actually render element filtered by module(extension?)
user namespace?! sounds should live in core
Comment #5
claudiu.cristea@andypost, in #2 I tried to make it a helper service in
system.module. The test failure is because the dependency on user module services.Comment #8
hardik_patel_12 commentedRe-rolling for 9.1.x-dev.
Comment #10
andypostFixed deprecation messages (looks it needs better wording - usage will throw exception?)
And fixed tests + clean-up
Looking through changes I still not sure we can make it trait without injecting so many services
Comment #13
berdirDo we really need to make it a trait if it's static? Or it could just be be a separate, standalone service. Then we can properly inject things and call it from different places. And it can be a non-static property and installing modules will automatically invalidate it.
I think we don't do require_once of include files in unit tests, so this probably needs to be a kernel test. You can mock stuff there too if necessary.
and deprecation message update of course. Feels like we should have way to automate that ;)
Comment #15
claudiu.cristeaI like the idea from #13, mostly because the cache reset is no more necessary. Or should we keep a "reset internal cache" method?
Comment #16
andypostThere's MR
Comment #17
claudiu.cristea@Berdir, the problem with moving to a service with proper injection is that the
user.permissionsservice introduces a system.module dependency to user module. This makes the test fail. Moving the service to User module would fix the problem but part of this future service still belongs to System as functionality, while the links to permissions feels like they belong to User. In a perfect world we should build the admin tasks somehow as a composition, each module (system & user) would participate to build the list of tasks. Then all dependecies are in the right place. But would it be worth it to introduce such a complexity?EDIT: I see now 3 alternatives to the "perfect solution":
user.permissions. Create a::getUserPermissions()protected (or private?) method that checks::hasService()first and then returns\Drupal::service('user.permissions'). This would be a soft dependency on User module.Comment #18
claudiu.cristeaLast change implements #17.2, which seem to me the most practical.
Comment #19
claudiu.cristeaIn https://www.drupal.org/project/drupal/issues/3038971#mr928-note33503, I tried the complex solution. Maybe complex but more clean.
Comment #20
berdirFine with whatever is the most practical solution. user and system are both required modules, they're full of interdependencies, that's really nothing new and only an issue during initial installation bootstrapping and tests.
Wouldn't it be sufficient use an optionally injected dependency for those?
Comment #21
daffie commentedComment #24
andypostMR needs rebase to 9.5.x
Comment #26
andypostIt needs re-roll and suggestion was to move to trait #2466933-46: Change $info array argument to system_get_module_admin_tasks() to $name
Comment #28
kim.pepperReroll of MR !928. Used a patch as I don't have permission to rebase it on 11.x, and creating a new MR and losing the code comments is probably more confusing for reviewers.
I replaced usage of
ModuleHandler::getName()as there is an issue to deprecate that in favour ofModuleExtensionList::getName().The existing deprecation for passing a string instead of an array to
system_get_module_admin_tasks()is no longer needed as we are deprecating the whole function. Removed this and the corresponding deprecation test.Comment #29
kim.pepperForgot to replace a usage of
system_get_module_admin_tasks()and removed an unrelated change.Comment #30
kim.pepperRemaining tasks:
\Drupal\system\ModuleAdminLinkHelperand\Drupal\user\ModulePermissionsLinkHelper\Drupal\Core\Cache\MemoryCache\MemoryCacheto keep the ability to flush the cache externallyComment #32
kim.pepperTest is failing because link change from
/admin/people/permissions/module/localeto/admin/people/permissions#module-locale. Seems like a valid fail?Comment #33
kim.pepperLooks like this was older than the module specific permissions page?? https://www.drupal.org/node/3223123
Comment #36
kim.pepperFix missing
$namearg togetModulePermissionsLink()Comment #37
kim.pepper\Drupal\system\ModuleAdminLinkHelperand\Drupal\user\ModulePermissionsLinkHelperComment #38
kim.pepperRemaining task:
\Drupal\Core\Cache\MemoryCache\MemoryCacheto keep the ability to flush the cache externallyComment #39
kim.pepperComment #40
kim.pepperFixes:
\Drupal\Core\Cache\MemoryCache\MemoryCacheto keep the ability to flush the cache externallyComment #41
kim.pepperUpdated the IS and CR
Comment #42
andypostthis is the only reason to keep it separate module/service (usage of user's module route)
But I think it could be implemented in system module's service just checking the route presence
Comment #43
andypostOne more typo
it should use
$info['name']instead of$nameComment #44
kim.pepper#42
Ah ok. Not sure what service provides that?
Comment #45
kim.pepperRe: #43 Fixed.
Re: #42 We are using
\Drupal\user\PermissionHandlerInterface::moduleProvidesPermissions()here. I'm reluctant to add another circular dependency between core, system, and user modules.Comment #47
kim.pepperRandom fail
Comment #48
smustgrave commentedReviewing #45
Deprecation appears to be up to date
Good test coverage
Reviewed the change record, the example was very useful and imagine will help those update later.
LGTM.
Comment #50
kim.pepperFix missing service aliases.
Comment #51
kim.pepperI think it safe to put this back to RTBC
Comment #53
andypostrandom failure
Comment #55
catchThis shows up a general issue that we have dependencies on user module in system module, and dependencies on system module in.. a lot of things but probably also including user.
It might make sense at some point to move the admin ui building out of system module into a system_ui module that's just responsible for building admin pages. That module could then depend on system and user without issue.
There's no workaround though that I can think of except for making that third module, so committed/pushed to 11.x, thanks!
Comment #57
quietone commentedPublished change record.