Problem/Motivation
Requirements are produced by implementing the hook_requirements()
hook. But there's no way they can be altered. Consider some situations that requires alteration:
- A distribution works only with a higher version of PHP than the underlying Drupal core it depends on.
- A module wants to decrease or to increase the severity of a requirement.
- Other modules want to add more details in the requirement description entry.
- A CI/CD system checks for errors & warnings at the end of a production deployment. If there are some, it rolls-back the deployment. However, they want to define some exceptions that are acceptable.
- A module simply wants to remove a requirement provided by other module.
Note that the Drush command core:requirements
did already implement the --ignore
option but that helps only to achieve removal of requirements and not alteration.
Steps to reproduce
N/A
Proposed resolution
Define a new hook_requirements_alter()
hook.
Remaining tasks
None.
User interface changes
None.
API changes
New hook: hook_requirements_alter()
.
Data model changes
None.
Release notes snippet
Requirements can be altered by modules implementing hook_requirements_alter()
.
Original report by David_Rothstein
This patch introduces a hook_requirements_alter() hook to Drupal. A possible use case is discussed in http://drupal.org/node/295697 (allowing modules to modify the recommended minimum PHP memory limit provided by Drupal core), but there are others.
The patch is mostly working, but not quite yet. If you put an implementation of the hook in an .install file (i.e., same place as hook_requirements itself), it seems to work correctly during runtime and during the initial installation of Drupal. It does not work correctly when installing a new module, however (i.e., the part of the patch in drupal_check_module()
). Unfortunately I think that in order to work there, the function would need to be in the .module file instead...? So it seems like getting this patch to work would either involve two separate hooks (ugly), or it would depend on doing some registry stuff differently (I'm not too familiar with the new registry yet).
It also would be nice to get this hook to work during update.php. but since hook_requirements itself isn't even called then (except for system.module), I'm leaving that out for now.
Anyway, I'm putting this patch here until I have time to work on it more... someone else please feel free to pick it up if you like the idea!
Comment | File | Size | Author |
---|
Issue fork drupal-309040
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 #1
Dave ReidMaybe #309457: Allow profiles to specify required memory in .info file would be a better solution?
Comment #2
Dave ReidSimpler title. Also marked #469082: Introduce hook_requirements_alter() as a duplicate of this issue.
Comment #3
David_Rothstein CreditAttribution: David_Rothstein commented#752618: hook_requirements_alter() doesn't exist was duplicate. Also, at this point, this is probably a Drupal 8 issue.
Comment #4
larowlanAnother duplicate #1110366: Allows modules to implement hook_requirements_alter()
Comment #5
David_Rothstein CreditAttribution: David_Rothstein commentedCool, looks like the patch you wrote in that issue has a nice start at writing some hook documentation - we should make sure to pull that in to the patch here.
Comment #6
larowlanYeah although I didn't allow for the fact that module_invoke_all isn't available at install time!
Next time I'll run tests locally first, it's just sooo easy with the testbot
Comment #7
quicksketchAnother great example of why this hook would be good, especially now that File module implements hook_requirements to inform the user about upload progress abilities: #1001024: Allow override of Upload Progress Implementation in hook_requirements..
Comment #8
MustangGB CreditAttribution: MustangGB commentedAlso interested in this issue to achieve #1001024: Allow override of Upload Progress Implementation in hook_requirements.
Comment #9
rickvug CreditAttribution: rickvug commentedI've also run into hook_requirements issues when modules are included in an installation profile. It would be helpful to have access to an alter as the fix right now is to patch the offending module to change the requirement check.
Comment #10
David_Rothstein CreditAttribution: David_Rothstein commentedI was just thinking that this hook might also be useful for the Update Manager to alter some of the System module's requirements (e.g., the row which shows the version of the Drupal core that is installed); it could alter the existing row to show whether or not the version is up to date, rather than having separate rows in the status report for this like it does now, which seems a little weird.
Comment #17
Chi CreditAttribution: Chi commentedComment #18
Chi CreditAttribution: Chi commentedComment #19
joachim CreditAttribution: joachim commentedA few nitpicks:
Are these in the same format as the return value of hook_requirements()? If so, needs a @see to that. If not, needs to explain.
Sample code in hooks typically needs a comment to explain what it's doing.
Comment #20
dwwA few more nits:
We'll need an automated test that the hook is working as expected, too.
The test could even do what the example from system.api.php is proposing. ;)
We should probably
@see hook_requirements()
here, too.Thanks,
-Derek
Comment #23
MykolaVeryha CreditAttribution: MykolaVeryha commentedComment #25
BryanGullan CreditAttribution: BryanGullan as a volunteer commentedHere's an updated patch created against 9.2.4, based on the most recently uploaded patch but not considering whether the comments in #19 and #20 need to be taken into account.
Comment #26
apadernoComment #27
daffie CreditAttribution: daffie commentedWe still need a test.
Comment #33
claudiu.cristeaComment #34
claudiu.cristeaTests added
Comment #35
claudiu.cristeaNeeds:
Comment #36
claudiu.cristeaAdded,
Comment #37
claudiu.cristeaHiding patches, we're now working on the MR
Comment #38
daffie CreditAttribution: daffie commentedAll code changes look good to me.
There is testing added.
The IS and the CR are in order.
For me it is RTBC.
Comment #41
catchCommitted/pushed to 10.1.x and cherry-picked to 10.0.x and 9.5.x - since this is just a small API addition I think it's fine during beta.
Comment #42
Chi CreditAttribution: Chi commentedMinor follow-up.
#3316871: Fix wrong documentation in hook_requirements_alter