If my module calls a function of another module, that other module should be listed as a dependency of my module.

Now my module only provides some field handlers for the Views module. On the one hand, my module is useless without the Views module. On the other hand, my module does not call any functions or methods provided by the Views module.

Should I add Views to the list of dependencies for that module? If yes, would that change if my module provides other functionality unrelated to views (like custom pages)?

Note that I used Views only as an example. The question applies to all optional modules, that define hooks.


As I see it, you only need to list a module as a dependency if it's possible for your module to cause errors or bugs if the other module (Views in your example) is not enabled.

That said, if your module really doesn't do much without Views as you say, it seems to make sense to list it as a dependency. At this point it's mostly about user experience. You want it to be clear to users that Views is essentially required in order to use your module.

Note that there are other options in the middle also: you could use hook_enable to check whether module_exists('views') when your module is enabled, and if it's not you can use drupal_set_message() to tell the user that it's probably a good idea to install Views.

| improve this answer | |

The Drupal.org .info file documentation does not define a dependency in itself other than stating a module cannot be enabled if a dependency is not present.

I guess you have to decide for yourself what you would consider a dependency. Personally, if a user needs to use Views in order to use your module than you would want to make sure it is installed.

If you don't want to make a module a dependency because it only supports secondary functionality in your module, you can use module_exists() to make sure your module doesn't die if the function it is calling is not there.

| improve this answer | |

If your module implements any views API hooks, then you should declare views as a dependency.

Also, consider that at some point in the future, if you don't declare views as a dependency, there will be a user who will send you an email asking you why your module doesn't do anything. :-)

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