I have a number of taxonomy settings with taxonomy context that work extremely well. I wanted, however, to alphabetize some of the taxonomy views with the views module and this seems to break the taxonomy context breadcrumb (although for some reason the rest of it works).

I had read somewhere to add the following code as an argument within the view to display the breadcrumb that is set within taxonomy context but it doesn't appear to work - or perhaps I'm doing something wrong. How can I get the breadcrumb I set within taxonomy context to show up with a taxonomy listing view instead of what views gives me which is incorrect.

if ($args[0]) {
    $term = taxonomy_get_term($args[0]);
    if ($term) {
        $vocab = taxonomy_get_vocabulary($term->vid);
        $arr_bc = array(
            l(t('Home'), NULL),
            l($vocab->name, 'taxonomy/vocabulary/' . $term->vid),
            '<em>' . check_plain($term->name) . '</em>'
        );
        drupal_set_breadcrumb($arr_bc);
    }
}
return $args;
CommentFileSizeAuthor
#2 taxonomy_context.module.patch2.42 KBlee20

Comments

summit’s picture

Subscribing. Having similar issues with views using views argument.
greetings,
Martijn

lee20’s picture

Status: Active » Needs review
StatusFileSize
new2.42 KB

I found a fix for this issue reseting the breadcrumb after the view has been rendered by utilizing the hook_views_post_view() hook.

Note, that setting the views option for not including "Home" in the breadcrumb will always ignored.

I have tested this and it restores the breadcrumb for me. I don't think this should cause any side affects either.

The function looks something like this:

function taxonomy_context_views_post_view(&$view) {
  if (arg(0) == 'taxonomy' && empty($_GET['from'])) {
    $context = taxonomy_context_get_context();
    switch (arg(1)) {
      case 'term':
        drupal_set_breadcrumb(taxonomy_context_get_breadcrumb($context));
        break;
    }
  }
}

Attached is patch file that resolves this issue. It also implements static caching on taxonomy_context_get_breadcrumb to reduce processing as the function is invoked atleast twice on the term view page.

nedjo’s picture

Category: support » feature
Status: Needs review » Reviewed & tested by the community

Thanks. I haven't tested but the code looks good. The caching is a good improvement. Pls feel free to commit.

lee20’s picture

Status: Reviewed & tested by the community » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)

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