I've just started developing Drupal module and have completed the simple "Hello "World" module. The module is working fine on both Drupal 6 and 7.

How can I use the same module on both Drupal 6 and 7, instead of packaging it as 2 separate modules?


Sorry, you can't without hacking Drupal's core. By the documentation for Drupal 7 you need to set:

core = 7.x

in module's info file. At the same time documentation for Drupal 6 requires you to set:

core = 6.x

Values without [] may appear only once, so you cannot write:

core = 6.x
core = 7.x

And you cannot make a value to be an array, so following also would not be recognized and accepted:

core[] = 6.x
core[] = 7.x

Safest way to solve it is to keep modules separate, and move common PHP code to a PHP library. With Libraries API it should be pretty easy to do.

  • That's really sad! I actually have tried all those and none worked. :-(. Anyways, thanx for the prompt response.. – Nitin Bansal Jul 24 '13 at 11:06
  • 1
    @NitinBansal why sad? Most of the time you will need different hooks and all for different versions, and you can move common code to a library. – Mołot Jul 24 '13 at 11:10
  • 2
    Throwing both 6.x and 7.x hooks into one file is not the efficient way. It's like creating one saddle for both your horse and your camel - sure, it can be done, but either it'll be poor fit for both, or you'll end up with poor animal toting more weight than it needs to get the job done. Better to have two saddles and common set of saddle bags. – Mołot Jul 24 '13 at 11:15
  • 1
    Hmmm...yeah, thats totally correct. Infact, I have actually used hooks that otherwise I wouldn't have used as they'll be outdated by next year just to fit my module into supporting both versions. Thnx for clarification :-) – Nitin Bansal Jul 24 '13 at 11:20
  • 1
    @NitinBansal To add what Mołot said, there could a case where the same hook has different uses in different Drupal versions; for example that is what happens with hook_hook_info(), which has a purpose with Drupal 6 and a totally different one with Drupal 7. I let you imagine what it would happen if you were using the same code for Drupal 6 and Drupal 7. – kiamlaluno Jul 24 '13 at 12:04

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.