0

Is it possible, using a module, to override a breadcrumd definition defined in another module's hook_node_view()?

  • Module property_bc sets a custom breadcrumb for nodes of type Property.
  • Module property_bc_plus wants to override that behaviour.

property_bc implementation of hook_node_view would be:

<?php
/**
 * Implementation of hook_node_view().
 */
function property_bc_node_view($node, $view_mode, $langcode) {
  if ($node->type == 'property') {
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), NULL);
    $breadcrumb[] = l(check_plain($node->name), "user/$node->uid");
    $breadcrumb[] = l(t('Properties'), "user/$node->uid/properties");
    drupal_set_breadcrumb($breadcrumb);
  }
}

1 Answer 1

3

Different solution depending of your context.

  • Change the module order by changing their weight: http://drupal.org/node/110238
  • Use an other hook than is called later like hook_node_view_alter
  • Add a flag in your node and test against it

First module

 <?php
 function property_bc_node_view($node, $view_mode, $langcode) {
      if ($node->type == 'property') {
        $breadcrumb = array();
        $breadcrumb[] = l(t('Home'), NULL);
        $breadcrumb[] = l(check_plain($node->name), "user/$node->uid");
        $breadcrumb[] = l(t('Properties'), "user/$node->uid/properties");
        $node->custom_bredcrumb_is_set = TRUE;
        drupal_set_breadcrumb($breadcrumb);
      }
    }

In your other module

    <?php
    function property_bc_plus_node_view($node, $view_mode, $langcode) {
      if ($node->type == 'property' && isset($node->custom_bredcrumb_is_set) && $node->custom_bredcrumb_is_set != TRUE) {
        $breadcrumb = array();
        $node->custom_bredcrumb_is_set = TRUE;
        drupal_set_breadcrumb($breadcrumb);
      }

}
1
  • You solution is great. Just a note here, I didn't modify the first module since this is what I wanted to avoid in the first place. May 29, 2013 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.