Show breadcrumb on node forms and comment forms
smitty - September 11, 2008 - 12:26
| Project: | Taxonomy Breadcrumb |
| Version: | 5.x-1.4 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
In version 1.4 the taxonomy breadcrumb only shows up when a node is displayed. But not if the node is edited or if a comment is written (on a sepaerate Page, dependant to the settings of the comment module).
Here is the code to make the breadcrumb also show up on node forms and on comment forms. Put this code into the function 'taxonomy_breadcrumb_form_alter' after line 325 (Version 1.4):
// If we are on a form of a node
elseif (substr($form_id, -9, 9) == 'node_form') {
if (!drupal_is_front_page() && arg(1) == $form['nid']['#value']) {
// See if the node type of the current node is part of the node types listed on the advanced settings page.
$array_of_types = explode(' ', variable_get('taxonomy_breadcrumb_node_types', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT));
$in_list = in_array($form['type']['#value'], $array_of_types);
// if the node type IS IN the node types list and the list IS inclusive OR
// if the node type IS NOT IN the node types list and the list IS NOT inclusive (e.g. exclusive)
// THEN modify the breadcrumb trail.
if ($in_list == variable_get('taxonomy_breadcrumb_include_nodes', FALSE) ) {
// Extract lightest term from lightest vocabulary assosciated with node.
$term = taxonomy_breadcrumb_node_get_lightest_term($form['nid']['#value']);
$breadcrumb = taxonomy_breadcrumb_generate_breadcrumb($term->tid);
drupal_set_breadcrumb($breadcrumb);
}
}
}
// If we are on a form of a comment
elseif ($form_id == 'comment_form') {
if (!drupal_is_front_page()) {
// See if the node type of the current node is part of the node types listed on the advanced settings page.
$node = node_load($form['nid']['#value']);
$node_type = $node->type;
$array_of_types = explode(' ', variable_get('taxonomy_breadcrumb_node_types', TAXONOMY_BREADCRUMB_NODE_TYPES_DEFAULT));
$in_list = in_array($node_type, $array_of_types);
// if the node type IS IN the node types list and the list IS inclusive OR
// if the node type IS NOT IN the node types list and the list IS NOT inclusive (e.g. exclusive)
// THEN modify the breadcrumb trail.
if ($in_list == variable_get('taxonomy_breadcrumb_include_nodes', FALSE) ) {
// Extract lightest term from lightest vocabulary assosciated with node.
$term = taxonomy_breadcrumb_node_get_lightest_term($form['nid']['#value']);
$breadcrumb = taxonomy_breadcrumb_generate_breadcrumb($term->tid);
drupal_set_breadcrumb($breadcrumb);
}
}
} 