Hi all,
I'm in Kazakhstan on the way to Mongolia, but have a customer issue back in Ireland I can't solve quickly with my limited internet access here. Maybe someone could help?
They want a custom breadcrumb. Few particularly unusual modules, but should mention that their site is multilingual and uses Workbench.
Workbench bases its hierarchy on taxonomy, so for the purposes of this, I'm ignoring Workbench and will just talk about taxonomy.
They have a complex hierarchical taxonomy, and node paths are generated based on the node's full 'path' of its taxonomy term in the hierarchary. So for example lets say the taxonomy is:
a -> b -> c -> d (where a is parent of b etc)
A node with title "node_title" and tagged with term c would get the path a/b/c/node_title
For every level of taxonomy they also have a main 'landing page', ie a normal node that is named the same as its taxonomy term. So there would be a node with title 'c' and tagged with term 'c' whose path is
a/b/c/c
The idea is that when you choose C in the menu, you get the 'landing page' and then can browse the other pages at the same taxonomy term level.
I know this is unusual, but I've had that discussion and this fits with how they work, so let's take it as given!
So the breadcrumb requirement is that, using my examples above, the breadcrumb for the a/b/c/node_title page should be
home >> a >> b >> c
Where a links to path a/a (i.e. the landing page for term a)
b links to path a/b/b
c links to path a/b/c/c
In other words, each part of the path links to the term's associated landing page.
My example is a bit simpler than reality, because the taxonomy terms are not single words, so the generated paths will obviously convert spaces to dashes, but also drop some words like 'and' 'of' etc. The result is that the breadcrumb needs to display the human-readable version of the taxonomy hierarchy, while the links obviously have to link to the associated urls.
I've tried several of the breadcrumb modules and tried custom coding a php block and using template.php and overriding the breadcrumb function, but I havent yet come up with a completely working solution.
Any tips or help would be hugely appreciated, as our customer has been waiting for this for weeks while I had spotty internet cover on our journey east.
Thanks & hope the weather's nice in Ireland (roasting here!)
Mike
Indytech

Comments
I'm currently trying to get
I'm currently trying to get this to work as a php block. I can easily pull out the current node's full aliased path and explode it
$path = $_GET['q'];
$alias = drupal_lookup_path('alias',$path, '');
$path_parts = explode('/', $alias);
...
If I could do the same for its taxonomy hierarchy then I would just need to match them together ;-)
I found this snippet for getting the current node, might be a bit heavy on the database though?
$node_id = basename($_SERVER['REQUEST_URI']);$node = node_load($node_id);
double posted!
oops!
Ok, here it is.My approach
Ok, here it is.
My approach was to create a new php format block and put it in the right region and turn off the standard breadcrumb display.
testing so far in my environment is good. waiting on customer's feedback.
would really appreciate review/feedback/constructive criticism on this.
/
/ Generate breadcrumb for current node or taxonomy term
/ by Mike Cahn, Indytech (with plenty of code snippets from drupal.org).
/
/ Notes:
/ This code is tightly coupled to the way the customersets its urls, and is only coded to produce
/ breadcrumbs for nodes and taxonomies. If the site begins to use other types of pages (e.g. views), additional
/ code would need to be written, here or elsewhere.
/
/ Instructions:
/ 1. Enable the php filter module
/ 2. In admin/config/content/formats, allow the Admin user to use the php filter
/ 3. Create a new empty block, and set its text format to php
/ 4. Paste this code into the block and save block
/ 5. Set the block to appear in one of the screen regions. You might start with putting it into the menu region, just
/ below the actual menu
/ 6. Turn off default breadcrumbs in admin/appearance/settings/marine_omega (toggle advanced elements)
/
/ IMPORTANT ASSUMPTIONS!
/ This code will NOT work unless your site data, urls, etc are set up in the way it expects them to be.
/ Some of the key points are:
/ 1. Every node must be assigned a taxonomy term. This is extracted during the breadcrumb creation process, and is also
/ a logical reqirement for the website. I would suggest that the taxonomy term field be made required for the Generic content type
/ 2. Your urls for your nodes are generated from the pattern [node:workbench-access-section-hierarchy]/[node:title]
/ 3. Your urls for your taxonomy are generated from the pattern site-area/[term:parents:join-path]/[term:name]
/ URL patterns are set at admin/config/search/path/patterns
/ 4. You must have landing pages for all your taxonomy terms, since the breadcrumbs will link to them
/
/
$separator = " > ";
$taxonomy_name = 'site-area';
$termid = 0;
$taxonomy_flag = false;
switch (arg(0)) {
case 'node':
// Extract taxonomy term from the node object
$node_id = arg(1);
$node = node_load($node_id);
// Get node's taxonomy term
$fieldname = 'field_site_area';
$items = field_get_items('node', $node, $fieldname);
if ($items) {
$termid = $items[0]['tid'];
}
break;
case 'taxonomy':
// We should be able to get taxonomy term from the (unaliased) path argument (it should be in format: /taxonomy/term/15 )
if (arg(2)) {
$termid = arg(2);
$taxonomy_flag = true;
}
}
if ($termid) {
// Get taxonomy ancestors all the way up the tree
$parents = array_reverse(taxonomy_get_parents_all($termid));
// Get current aliased path parts
$path = $_GET['q'];
$alias = drupal_lookup_path('alias',$path, '');
$path_parts = explode('/', $alias);
// Build up crumb piece by piece, taking one part of path at a time.
$size = sizeof($path_parts)-1;
// Number of iterations is one higher for taxonomy terms because they don't have repeats at end of url (eg site-area/areas-activity/areas-activity)
if ($taxonomy_flag) {
$size++;
}
$crumb = '<span class="custom-breadcrumb">' . l(t('Home'), '<front>'); // Breadcrumb starts with home
$current_path = $GLOBALS['base_url']; // This will probably be "http://www.customername.ie"
$j = 0;
for ($i=0; $i < $size; $i++ ) {
$part = $path_parts[$i];
$current_path .= '/' . $part;
// Dont include a crumb for taxonomy name itself. Although it is part of the path, it isnt needed for breadcrumb
if ($part != $taxonomy_name) {
// Get name of next taxonomy term
$termname = $parents[$j++]->name;
if ($taxonomy_flag) {
$crumb .= $separator . l($termname, $current_path);
} else {
$crumb .= $separator . l($termname, $current_path . '/' . $part);
}
}
}
$crumb .= '</span>';
print $crumb;
}