Problem/Motivation
Hooks make the implementation details hard to reliably override. This change allows other modules to create another service to subclass/override methods defined in your module.
My specific use case is around the user query. I only wanted to count certain roles to be able to be registered.
Proposed resolution
The proposed patch moves the implementation details into a service which allows others to override.
Remaining tasks
-
Other changes
I applied the patch in 2997455 (to align with good coding standards)
I also updated how the users are queried using an entity query approach versus the SelectInterface.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | interdiff_7-8.txt | 1.12 KB | mediabounds |
| #8 | user_registration_limit-refactor_to_service-3310126-8.patch | 12.95 KB | mediabounds |
Comments
Comment #2
bbeversdorf commentedComment #3
bbeversdorf commentedComment #4
bbeversdorf commentedComment #5
bbeversdorf commentedHere is a new patch that is a little cleaner implementation (keeping the form alter logic in the hooks and moving the business logic to the service).
Comment #6
bbeversdorf commentedComment #7
mediabounds commentedMake a minor change to the previous patch to resolve a WSOD if the limit field is left empty on the user settings screen.
Comment #8
mediabounds commentedFound two additional issues which are resolved in this updated patch:
a. A type annotation in the new service had an extra semicolon on it
b. The submit handler in the form alter is replacing the built-in submit handler (this is an issue in the current version of the module too)
Comment #9
heykarthikwithuComment #10
heykarthikwithuThank you @bbeversdorf & @mediabounds.
I have added the changes to the 2.0.x branch - https://git.drupalcode.org/project/user_registration_limit/-/commit/3e68fb02f34cb99013ba39a778c15ccfe759600d
Additional changes:
1. Minor issue with the
accessCheck(FALSE)of the entity query is Fixed.2. Updated the Readme with the details of module usage.
Will be released in the upcoming release.
Comment #11
heykarthikwithuReleased in the 2.0.0 version