1

Background:
I've got a multi-user/multi-channel project. Some channels are "classic" websites, but I've also got a channel that targets a non-interactive TV display. All channels are rendered using Drupal's templating (Technically a "channel" is just a theme, selected by a custom ThemeNegotiator acting on the current subdomain.) The problem is that some modules like e.g. Google Tag Manager or EU Cookie Compliance are unnecessary and disruptive on my TV channel.

Is there a simple way to dynamically disable certain modules at runtime?

The module should not be uninstalled, just inactive/dormant for the current request. I know that I could write module-specific hooks for each module I want to suppress. But I was wondering if - instead of writing a couple of different hooks - there is a single universal shortcut, something like the pseudo-code below:

if ($isMyCondition) {
  $modulesToDisable = ['eu_cookie_compliance', 'google_tag', 'foo_module', 'bar_module'];
  foreach ($modulesToDisable as $module) {
    \Drupal::something()->disableModuleForThisRequest($module);
  }
}
1
  • Don't disable the whole module. Just override its functionality to not fire on certain conditions. – leymannx Jan 25 at 13:48
3

The concept of disabling modules (separate to uninstalling them), did exist in Drupal 7, but it was removed in Drupal 8.

You will either need to uninstall the modules, or find a different way to disable the specific behaviours which are causing you problems, via events/hooks/etc.

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.