26 February 2014

I had a problem with path breadcrumbs where I couldn't get taxonomy therms through commerce product reference. So I had to disable the path breadcrumb for the node and do it manually. I didn't want to put the code to theme, because it had to work irrelevant from it. Here is the example of altering node breadcrumbs via hook from my module in Drupal 7.

Source code viewer
  1. function HOOK_node_view_alter(&$build) {
  2. $node = &$build['#node'];
  3. if ($build['#view_mode'] == 'full' && $node->type == 'product') {
  4. $product = commerce_product_load($node->field_product[LANGUAGE_NONE][0]['product_id']);
  5. $tid = &$product->field_category[LANGUAGE_NONE][0]['tid'];
  6. $terms = taxonomy_get_parents($tid);
  7. $breadcrumb = drupal_get_breadcrumb();
  8. if (!empty($terms)) {
  9. foreach ($terms as $term) {
  10. $breadcrumb[] = l($term->name, 'taxonomy/term/'.$term->tid);
  11. }
  12. }
  13. $breadcrumb[] = l($product->field_category[LANGUAGE_NONE][0]['taxonomy_term']->name, 'taxonomy/term/'.$tid);
  14. $breadcrumb[] = $node->title;
  15. drupal_set_breadcrumb($breadcrumb);
  16. }
  17. }
Programming Language: PHP