Use case:
A views page whose path is myview/1 (1 is an uid). The views path is actually myview/%, with an argument. I don't want to build a menu item for this view because it has no sense, as the path 'myview' (with no arg) is not allowed in this use case. So I don't set any menu settings for my view.
The view has a global title: "My view". The argument is set to not override the view's title (checkbox unchecked).
I expect the breadcrumb to be :
Home (link to front page) / My view (no link, title of the current page)
I actually get :
Home / 1
This is because the findTitle() method of the views plugin (coming from #1914718: Crumbs on Views with Arguments/Contextual Filters) does not handle the use case. I managed to get what I wanted by replacing this:
// Trigger the argument calculation by calling build_title().
$view->build_title();
// Check the last argument for a breadcrumb item title.
$argument = $view->argument;
while (!empty($argument)) {
$last_arg = array_pop($argument);
if (1
&& is_object($last_arg)
&& !$last_arg->is_exception()
&& isset($last_arg->argument)
) {
if ($last_arg_title = $last_arg->get_title()) {
// Use decode_entities() to undo duplicate check_plain().
// See https://drupal.org/comment/7916895#comment-7916895
return array("$view_name.$view_display_id" => decode_entities($last_arg_title));
}
break;
}
}
with this:
// Trigger the argument calculation by calling build_title().
$view->build_title();
// Check the last argument for a breadcrumb item title.
$argument = $view->argument;
while (!empty($argument)) {
$last_arg = array_pop($argument);
if (1
&& is_object($last_arg)
&& !$last_arg->is_exception()
&& isset($last_arg->argument)
&& !empty($last_arg->options['title_enable'])
) {
if ($last_arg_title = $last_arg->get_title()) {
// Use decode_entities() to undo duplicate check_plain().
// See https://drupal.org/comment/7916895#comment-7916895
return array("$view_name.$view_display_id" => decode_entities($last_arg_title));
}
break;
}
}
if ($title = $view->get_title()) {
return array($title);
}
i.e. I added the condition !empty($last_arg->options['title_enable'])
to check if the argument is set to override the default title, and a fallback to default to the view's global title.
Comment | File | Size | Author |
---|---|---|---|
#1 | crumbs-7.x-2.x-2235691-1-views.patch | 8.04 KB | donquixote |
Comments
Comment #1
donquixote CreditAttribution: donquixote commentedTotal rewrite of the Views stuff.
Could you give it a try?
Comment #2
donquixote CreditAttribution: donquixote commentedSee also
https://github.com/donquixote/drupal-crumbs/tree/7.x-2.x-views
Comment #3
donquixote CreditAttribution: donquixote commentedShould be fixed in new release 7.x-2.0-beta14.
Please reopen if not.
Comment #4
donquixote CreditAttribution: donquixote commentedSorry, I forgot to merge. So beta14 does NOT contain the fix.
7.x-2.0-beta16 should do it.
Comment #5
donquixote CreditAttribution: donquixote commentedAnd 7.x-2.0-beta17 ..