We currently run a Drupal site within a university web space and would like to know if it is possible to add the university's home page as a constant link at the beginning of all generated breadcrumbs?

Comments

jweowu’s picture

You might wish to simply over-ride theme_breadcrumb()

brett_wilson’s picture

i'm still not sure how this can be achieved. for future releases and upgrades we are trying to keep module modifications to a bare minimum.

jweowu’s picture

If you have a custom theme, just implement mytheme_breadcrumb() in template.php.

If you're using a core or contrib theme and don't want to touch it, then Drupal 6 has a nice way for you to over-ride theme functions with a custom module.

http://api.drupal.org/api/function/hook_theme_registry_alter/6

/**
 * Implementation of hook_theme_registry_alter().
 */
function mymodule_theme_registry_alter(&$theme_registry) {
  $theme_registry['breadcrumb'] = array(
    'function' => 'mymodule_theme_breadcrumb',
    'args' => array('breadcrumb' => NULL),
  );
}

/**
 * Return a themed breadcrumb trail.
 *
 * @param $breadcrumb
 *   An array containing the breadcrumb links.
 * @return a string containing the breadcrumb output.
 */
function mymodule_theme_breadcrumb($breadcrumb) {
  if (empty($breadcrumb)) {
    $breadcrumb = array();
  }
  $link = l("University", "http://www.myuniversity.org/");
  array_unshift($breadcrumb, $link);
  return '<div class="breadcrumb">'. implode(' » ', $breadcrumb) .'</div>';
}

In either case, remember to clear the theme registry cache, otherwise Drupal won't see the change.

(The admin_menu module provides handy links for cache clearing.)

brett_wilson’s picture

Thanks for the reply but i'm still getting how to implement this. where should this code go?

jweowu’s picture

Okay, you definitely need to do a bit of reading about the Drupal theme and module systems.
It will help you tremendously in the long run if you understand how to over-ride things without touching the core code.

For the above code, you would create a new custom module (or extend an existing one). I've used 'mymodule' as a name, but you would replace each instance of that with the actual name you wish to use. Choose something unique (perhaps the name of your university), as PHP does not have namespaces, so function names can clash if you choose poorly.

You would create a directory somewhere under sites/all/modules. It can be deeper than that -- you can separate out your custom and contrib modules by putting contrib modules in sites/all/modules/contrib/ and custom modules in sites/all/modules/custom/

So you might have:
sites/all/modules/contrib/menu_breadcrumb/
sites/all/modules/custom/mymodule/

Inside the mymodule directory, make two files:
mymodule.info
mymodule.module

See other .info files for examples, but the following would suffice:

name = My Module
description = Custom functionality for the University
core = 6.x

mymodule.module would contain the previous code.

Then enable the module in Drupal. That will probably clear the theme cache registry automatically.

I hope that helps, but like I said -- start reading the documentation!

brett_wilson’s picture

thanks so much. This helps greatly. I am in the process of getting my head around Drupal. So thanks again for the reply.

jweowu’s picture

You're welcome. Happy Drupaling :)

xurizaemon’s picture

Category: feature » support
Status: Active » Fixed

Marking support, fixed. Thanks jweowu.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.