I have a bunch of modules that provide the same functionality with various differences(for example different provider of some service) and they cannot co-exist because they would collide in certain things.
I was looking at what options are available for an installed module to prevent installation of another module and there are any. The closest one is the hook_module_preinstall but unfortunately it is being called right after the module that is being installed is put into the central module registry so throwing an exception would not work. I would have to manually remove sich module from the registry manually and that does not sound like a good approach at all.
So I think moving invocation of this hook just a few lines sooner would solve this. Or introduce a new type of hook_requirements that would be actually called on installed modules and not on the module that is being installed.
I can even imagine a simple code that could even check for "tags" or some other attribute in the module's info file and prevent installing modules on its own if module with the same tag is already installed. So no custom code would be required from developers.
Example: imagine payment method plugin for payment gateway like Stripe or PayPal or something like that. And you want user to be able to manage his credit cards. Of course you want to have a single place for this so you create s dedicated route at /user/uid/credit-cards. Each provider stores the CC info on their server so you only have the card IDs. Now if you would want to change provider, you cannot migrate those cards to this new provider so user would have to add cards manually again. And if you would have both providers at the same time, that would require separate pages to manage those cards for each user and that is just impossibly bad UX. So you would use one of the provider at any given time, but not both.
Comments
Comment #1
Anonymous (not verified) commentedivanjaros created an issue. See original summary.
Comment #2
cilefen commentedSomewhat related issue: #2494073: Prevent modules which have unmet Composer dependencies from being installed
Comment #15
jigarius+1 for this. I'm facing a similar problem at the moment.
I think this issue might be considered a distant duplicate of this issue that proposes adding a "conflicts[]" in module.info.
I invite the author of this issue to close this one if they see it as a duplicate of the one that I shared.
Comment #17
nicxvan commentedThis is a duplicate, thanks!
I think rather than a hook we'd do this with conflicts.
Comment #18
nicxvan commented