I'm writing a module that can have some additional functionality if other modules such as Block or Menu are enabled, but I don't want to declare them as a dependency.
Currently I'm using if(module_exists($module)) { ... }
to provide module-specific functionality within my custom module (in this case, defining a particular view if the module in question is present).
However I've heard that this is not the right way to provide module-specific features, and that instead I should use hooks and plugins. The only problem is that I don't really know what that means or how to get started converting my module to using those instead of if()
s.
How do I define a custom view that depends on another module without using an if()
?
One of the things I am trying to do is to expose that module's SQL tables to Views if the module exists, and then define a custom view with those tables.
module_exists
could be a reasonable solution.