Problem/Motivation
Postponed on #3493718: Convert system_requirements() into OOP hooks and install time class
In IRC the other day I was chatting with @realityloop who was getting some notices on admin pages because a module installed on his site was incorrectly returning from hook_requirements.
The module didn't provide a title in the return, and this was causing a large number of warnings, because by default we assume this is present in a uasort call.
Proposed resolution
Replace the return value of hook_requirements with value objects. This will enforce the structure of the return in a way that an array cannot.
Implement \ArrayAccess for BC sake
Remaining tasks
Remaining tasks:
- Decide if we should just enforce required properties by using constructor args
- Ensure sorting works
- Replace usages of requirements arrays
User interface changes
API changes
Addition of a new value object
Data model changes
| Comment | File | Size | Author |
|---|
Issue fork drupal-2909472
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
kim.pepperI need something to do on a 24 hr Sydney to London flight. ;-(
Comment #3
kim.pepperInitial implementation for review.
Comment #4
dawehnerI'm wondering whether we should have one class per severity aka. RequirementInfo, RequirementOk, RequirementWarning and SeverityError? It feels like this would cause an ever better to read requirement.
Comment #5
larowlanYeah and would be consistent with AccessResults - agree
Comment #6
larowlanWe should be setting defaults here to avoid the issue outlined in the OP.
We should add getters so we can eventually use that over the \ArrayAccess
These should just be
return $thiswith no commentComment #7
larowlanSame as mentioned in #2908735: [meta] Add value objects to represent hook_schema we should use named properties for title, description, value, severity and then save $definition for stuff outside that - this will optimize the memory footprint
Comment #8
kim.pepperThanks for the review. I've switched to using properties and having a separate class for each severity level.
Comment #9
sam152 commentedComments.
inheritdoc?
Just return in_array...
Shouldn't be able to set this if it's based on the class, but is this needed for BC?
No "Base" in class name?
Comment #10
kim.pepperAfter discussing with @Sam152, I added an interface for Requirement too.
Comment #11
dawehnerShould we move this constant on the individual classes?
Comment #12
kim.pepperWouldn't it make more sense to allow you to compare different severity levels? In SystemManager we are doing:
Doing a comparison of classes to see which had the max severity would be cumbersome.
Comment #13
larowlanComment #14
dawehnerMaybe we could provide some nice helper functions for that?
Comment #15
kim.pepperSounds like a plan. Here's a patch with the above and a helper.
Comment #17
dawehnerNice usage of
array_reduce!Comment #18
kim.pepperThanks! I've inlined the max method to an anonymous function.
The previous fail was a random one related to Layout Builder.
Comment #21
idebr commentedThe data model for a Requirement in this issue does not match the return values being implemented in #2505499: Explicitly support render arrays in hook_requirements(), specifically the supported value of description.
The related issue does indicate there is a need for a value object that outlines the correct data model.
Comment #27
kristen polSurprisingly, this patch still applies :)
Reviewed the code and there are a few items:
Extra line.
Deprecation version needs to change. Example;
Nitpicks:
1. Use different values for warning vs error.
2. Use single quotes.
Also, please review feedback from #21.
Comment #31
andypostInstead of constants it could be enum or even removed in favour of methods (like accessResult doing).
But this weight used only for frontend to group sort requirements - that usage is missing in replacement
Comment #34
kim.pepperWe could possibly roll this into #3409372: [meta] Replace hook_requirements() with OOP classes
Comment #35
kim.pepperComment #37
kim.pepperConverted to a single
Requirementclass with enums forRequirementSeverityandRequirementPhase.Remaining tasks:
Comment #38
kim.pepperHiding old patches
Comment #39
smustgrave commentedSeems to have some test failures.
Comment #40
kim.pepperI think this issue is quite large, having to convert all of cores hook requirements to value objects as well as handle deprecations.
We should split out the smaller task of creating enums for RequirementSeverity and RequirementPhase #3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants
Comment #41
berdir#3409372: [meta] Replace hook_requirements() with OOP classes is two thirds done.
If we can get this also into 11.2 then this might considerably simplify the BC layer. New hook use value objects, old hooks use arrays, we just need to merge it together in the places where core calls both the old and the new hooks?
Comment #42
dwwAgreed this would be great to do in 11.2.0 so the new hooks only use the new API. Tagging as such. But this should now be postponed on #3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants, no?
Comment #43
kim.pepperComment #44
voleger#3410938: Create enums for RequirementSeverity and deprecate drupal_requirements_severity() constants is merged
Comment #45
kim.pepperRebased on 11.x
Comment #46
nicxvan commentedSeveral failures, this definitely won't make it in for 11.2 I think.
Personally I would want to postpone this in the system_requirements conversion. That issue was green and just need to take the new enum into account.
I'll link it later when I fix that issue. #3493718: Convert system_requirements() into OOP hooks and install time class
Comment #47
nicxvan commentedComment #48
kim.pepperDamn. I wish I saw your comment before I started converting
system_requirements()😓Comment #49
kim.pepperI pushed up my work in progress in case it's useful later.
Comment #50
kim.pepperComment #51
larowlanComment #52
larowlanComment #53
larowlanBlocker is in
Comment #54
kim.pepperWorking on this
Comment #55
kim.pepperRebased on 11.x and moved everything over from
system_requirements()to\Drupal\system\Install\Requirements\SystemRequirements::checkRequirements()Comment #56
nicxvan commentedTook a first pass review.
We also want to handle when update requirements / phase and install time for modules and profiles during profile install amc module install.
Comment #57
nicxvan commentedIs this meant to be scoped to only runtime?
Most of the changes seem like that but some of the changes should run during update and install.
I'm also unsure why we're not getting failures from update and install being converted but no equivalent mapper like you put in runtime requirements during the status report.
Comment #58
nicxvan commentedA bunch of minor suggestions and a few substantial questions.