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!

Issue fork drupal-309040

Command icon 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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Dave Reid’s picture

Dave Reid’s picture

Title: Allow modules to modify each others' requirements » Add hook_requirements_alter()

Simpler title. Also marked #469082: Introduce hook_requirements_alter() as a duplicate of this issue.

David_Rothstein’s picture

Version: 7.x-dev » 8.x-dev

#752618: hook_requirements_alter() doesn't exist was duplicate. Also, at this point, this is probably a Drupal 8 issue.

larowlan’s picture

David_Rothstein’s picture

Cool, 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.

larowlan’s picture

Yeah 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

quicksketch’s picture

Another 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..

MustangGB’s picture

rickvug’s picture

I'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.

David_Rothstein’s picture

I 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.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Chi’s picture

Version: 8.6.x-dev » 8.9.x-dev
Issue summary: View changes
Issue tags: +Needs reroll
Chi’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
1.13 KB
joachim’s picture

Status: Needs review » Needs work

A few nitpicks:

  1. +++ b/core/modules/system/system.api.php
    @@ -34,5 +34,15 @@ function hook_system_themes_page_alter(&$theme_groups) {
    + * @param array $requirements
    + *   The requirements data.
    

    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.

  2. +++ b/core/modules/system/system.api.php
    @@ -34,5 +34,15 @@ function hook_system_themes_page_alter(&$theme_groups) {
    +  unset($requirements['update status']);
    

    Sample code in hooks typically needs a comment to explain what it's doing.

dww’s picture

Issue tags: +Needs tests

A few more nits:

  1. +++ b/core/modules/system/src/SystemManager.php
    @@ -109,6 +109,7 @@ public function listRequirements() {
    +    $this->moduleHandler->alter('requirements', $requirements);
    

    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. ;)

  2. +++ b/core/modules/system/system.api.php
    @@ -34,5 +34,15 @@ function hook_system_themes_page_alter(&$theme_groups) {
     /**
    + * Alters requirements data.
    + *
    + * @param array $requirements
    + *   The requirements data.
    + */
    

    We should probably @see hook_requirements() here, too.

Thanks,
-Derek

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

MykolaVeryha’s picture

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

BryanGullan’s picture

Here'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.

apaderno’s picture

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Needs work

We still need a test.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

claudiu.cristea made their first commit to this issue’s fork.

claudiu.cristea’s picture

Status: Needs work » Needs review
claudiu.cristea’s picture

Issue tags: -Needs tests

Tests added

claudiu.cristea’s picture

Needs:

  • IS summary update
  • Change record
claudiu.cristea’s picture

Added,

  • IS summary update
  • Change record
claudiu.cristea’s picture

Hiding patches, we're now working on the MR

daffie’s picture

Status: Needs review » Reviewed & tested by the community

All code changes look good to me.
There is testing added.
The IS and the CR are in order.
For me it is RTBC.

  • catch committed 41dce09 on 10.0.x
    Issue #309040 by claudiu.cristea, David_Rothstein, Chi, BryanGullan,...
  • catch committed 5e67517 on 10.1.x
    Issue #309040 by claudiu.cristea, David_Rothstein, Chi, BryanGullan,...

  • catch committed d6cd747 on 9.5.x
    Issue #309040 by claudiu.cristea, David_Rothstein, Chi, BryanGullan,...
catch’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/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.

Chi’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.