I am developing a brand new module (there isn't any site using it yet). It requires a specific Drupal version, as it uses the hook_taxonomy_term_view() hook that was introduced in Drupal core version 7.17.

I want to avoid my module being enabled on a site using, for example, Drupal 7.16 or any earlier versions of Drupal core. Higher versions of Drupal, above 7.17, should be fine.

My Question: How can I make my module dependent on that Drupal 7.17 version, which is a minimum for my module?

Note: I don't need (have to worry about) a solution for sites where the module is already installed. So there is no need for it to be disabled somehow in such pre-7.17 Drupal versions.

  • The question is tagged hooks because it is about a hook I should use in my code. hooks doesn't mean I am looking for a hook I could use; I am open to any solution that allows me to avoid the module is installed on a site not using Drupal 7.17, or higher. – kiamlaluno Jan 26 '13 at 16:04
  • You can require a minor version of some other module by dependencies[] = mymodule (1.12) but it seems like this doesn't work for core. – AyeshK Jan 26 '13 at 17:08
  • @AyeshK Uh! Now, that could be interesting, if you could point me to a Drupal core module that is always enabled. – kiamlaluno Jan 26 '13 at 17:31
  • I tried it with dependencies[] = taxonomy (>7.17) and some other possible version numbers but didn't work. – AyeshK Jan 26 '13 at 18:03

The trick, apparently, is to use the system module like:

dependencies[] = system (>=7.17)
| improve this answer | |
  • 4
    This is the correct one. Source: dww and I wrote the versioned dependency checker. I blogged about this at drupal4hu.com/node/274 and now added to the relevant handbook page at drupal.org/node/542202 as well. – user49 Jan 29 '13 at 20:40

hook_requirements() exists for exactly that sort of purpose.

Check installation requirements and do status reporting.

You can check the $phase parameter to determine if the module is being installed, check the current Drupal version against your required version, and return a severity of REQUIREMENT_ERROR. That will prevent the module from being installed until the requirement is met.

The documentation is pretty thorough, the one thing worth mentioning here is that the hook needs to be implemented in the module's .install file.

| improve this answer | |
  • This is not the right answer I have no idea why it's upvoted so heavily. – user49 Jan 29 '13 at 20:32
  • @chx I'll take your word for it, but in that case the description of the function "Check installation requirements and do status reporting." is somewhat misleading is it not? We are after all talking specifically about checking for module requirements upon installation :) – Clive Jan 29 '13 at 21:42
  • 1
    @Chapabu Not according to the docs :) It talks about modules specifically, and basically says to use that hook to return REQUIREMENT_ERROR to make sure a module is not installed if it fails the requirements. I'd assumed checking the version of Drupal was a valid use case (the docs don't mention not doing that) but I guess I've missed something. It might just be bad practice or something I dunno – Clive Jan 29 '13 at 22:48
  • 1
    @Clive Weird, dunno where I got that from then..maybe D8 should just be a docs upgrade ;-) – Chapabu Jan 29 '13 at 23:05
  • 1
    @chx You'll have to excuse my ignorance, never done this before...does the issue go against D8 and then get backported? In your opinion does the whole text need to change or does it just need a note mentioning not to use this hook to check for module/core versions, only library requirements, etc (with a link to the docs you mentioned)? Thanks – Clive Feb 1 '13 at 20:14

You could use the hook_enabled

This would fire after the module is installed. You can check the version of the drupal installed and if it is not the correct version then use module_disable and give the required error message.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.