Remove a hook from an installed contrib module without patching itPeter MajmeskuWed, 01/06/2021 - 18:08

Let's say you have installed a contrib module, which does things for you. But the module contains a Drupal hook-function which you do not want. That's easy without patching. You can remove the hook like follows:

php
function my_module_module_implements_alter(&$implementations$hook) {
  if (
$hook == 'query_entity_query_alter' && isset($implementations['group']) {
    unset(
$implementations['group']);
  }

This function will remove the hook_query_entity_query_alter() function from the Group contrib module. If it doesn't, you could check the module weight of you custom module with the core.extension.yml file. There you can set

my_module: 0

to

my_module: 10

The module weight must be higher than the module weight of the contrib module which you want to modify.