Is it possible to dynamically disable a module at runtime? Background:
I've got a multi-user/multi-channel project. Some channels are &quot;classic&quot; 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 &quot;channel&quot; 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()-&gt;disableModuleForThisRequest($module);
  }
}
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.