Disable 3rdparty hook from custom module once

by Roland Franssen   Last Updated February 13, 2018 11:07 AM

Im using the menu_trail_by_path which does a pretty good job for most of my URL's, however in a custom module I'm setting the breadcrumbs directly (drupal_set_breadcrumb in a page callback). These crumbs get messed up due the menu_trail_by_path module (sort of overwritten I guess =/)

This happens because menu_trail_by_path sets the crumbs using hook_page_delivery_callback_alter which is called after the page callback apparently.

I would like to keep my custom crumbs in the page callback as it has all the required (dynamic) data available.

Hero we go.. how on earth can I disable the page_delivery_callback_alter hook from the menu_trail_by_path module... once? I.e. for the current runtime /request only.


Roland Franssen

Tags : 7 hooks

Answers 1

You could implement hook_module_implements_alter() to avoid a hook implemented by a module is invoked. The problem is that Drupal saves in cache the list of modules implementing a hook, but you can change the list of hooks implemented by modules back to the original one.

function mymodule_implements_alter(&$implementations, $hook) {
  if ($your_condition && ($hook == 'page_delivery_callback_alter')) {
    $old_implementations = &drupal_static(__FUNCTION__, array());
    if (empty($old_implementations)) {
      $old_implementations = array_merge(array(), $implementations);

function mymodule_exit() {
  $old_implementations = &drupal_static('mymodule_implements_alter', array());
  $implementations = &drupal_static('module_implements');

  if (!empty($old_implementations)) {
    $implementations['page_deliver_callback_alter'] = $old_implementations;

This code works only in the case hook_exit() is invoked, which is normally done in drupal_page_footer().

You should be sure mymodule_implements_alter() is executed after the implementations made from other modules, in order to preserve the changes done from other modules.

July 18, 2015 20:56 PM

Related Questions

How to find hooks being called by a Drupal page?

Updated April 03, 2015 21:20 PM

Modify text of error message for required field

Updated April 22, 2015 20:03 PM

Where are hooks stored/cached?

Updated April 13, 2015 20:03 PM