As soon as I set a custom breadcrumb for a specific path, I loose the page title in the browser bar. The title should be '[page-title] : [site-name]' however, All I get is ': [site-name]'. If I delete the custom breadcrumb, I get the title back to normal.

Comments

mrfelton’s picture

Title: PAge titles disapear for specify path breadcrumbs » Page titles disapear for specify path breadcrumbs

typo in title

mrfelton’s picture

I should also note that I am also using the page_title module to control the page titles. I have it set to '[page-title] : [site-name]'. This works everywhere, except where a specify path breadcrumb has been set.

mrfelton’s picture

I should also note that the page that I am trying to use custom_breadcrums_path for is generated by a View, and the title of that View is set dynamically base on one of its arguments, by using the following code in the PHP argument handling section of the View:

$title = db_result(db_query("SELECT nodequeue_nodes_node__nodequeue_subqueue.title
FROM node node
INNER JOIN nodequeue_nodes nodequeue_nodes_node ON node.nid = nodequeue_nodes_node.nid
LEFT JOIN nodequeue_subqueue nodequeue_nodes_node__nodequeue_subqueue
ON nodequeue_nodes_node.sqid = nodequeue_nodes_node__nodequeue_subqueue.sqid
WHERE nodequeue_nodes_node__nodequeue_subqueue.reference = %d", $argument));
$handler->validated_title = $title;
return TRUE;

now, commenting out custom_breadcrumbs_set_breadcrumb($breadcrumb) in custom_breadcrumbs_views_pre_view() in custom_breadcrums_path.module stops the title being deleted - but also stops the breadcrumb being set (obviously!)..

And while I'm at it... why is custom_breadcrumbs_views_pre_view</code in custom_breadcrums_path.module? That doesn't seem right... surely it should be <code>custom_breadcrumbs_path_views_pre_view if anything?

mrfelton’s picture

and a little further digging shows that commenting out the following lines in custom_breadcrumbs_set_breadcrumb() fixes.

      $titles = token_replace_multiple($titles, $types);
      $paths = token_replace_multiple($paths, $types);

Clearly this is the wrong thing to do as it will break token support - but thats where the problem is

MGN’s picture

Status: Active » Postponed (maintainer needs more info)

You are correct that custom_breadcrumbs_views_pre_view in custom_breadcrumbs_paths.module should be custom_breadcrumbs_paths_views_pre_view.

I would start by changing that (I'll also commit a fix for the nightly snapshot).

I am not familiar with the page_title module. Can you tell me if [page-title] is a token, and if so, what is its scope (node or global or ...)?

Also, is the view embedded in a node?

EDIT: Additional questions:

Does the same thing happen when you use node_type custom breadcrumbs? custom_breadcrumbs_views breadcrumbs? or does this only happen with path breadcrumbs?

mrfelton’s picture

It only seems to happen with path breadcrumbs. [page-title] is indeed a token, provided by the page_title module. It is a global scope token:

/**
 * Implementation of hook_token_values().
 *
 * @param
 *   string The type of token being generated
 *
 * @return
 *   array An array of Token ID and Token Value pairs
 */
function page_title_token_values($type) {
  $values = array();

  if ($type == 'global') {
    $values['page-title'] = page_title_get_title();
  }

  return $values;
}


/**
 * Implementation of hook_token_list().
 *
 * @param
 *   string Which type of token list are we generating?
 *
 * @return
 *   array Nested array of Token ID and Token Name pairs.
 */
function page_title_token_list($type = 'all') {
  $tokens = array();

  if ($type == 'global' || $type == 'all') {
    $tokens['global']['page-title'] = t("The page title.");
  }

  return $tokens;
}

I think that what is happening is related to token caching - if I stop the token module from caching it's results (by hacking the code), then the problem goes away and I get both a custom breadcrumb, and the correct page title. Perhaps custom_breadcrumb, or page_title is passing token an incomplete object in $type, that is, an object which has a blank value for ->title? I initially thought that it may be because you are running this at such a point in the views hooks, that the custom argument handling code hasn't run yet, and therefore my title hasn't been set - but I tried altering it to use other views hooks and id made no difference. I also tried setting a static title on my view, just to rule out the views argument handing as the source of the problem, and still, no change. See http://drupal.org/node/213548#comment-822926 for info on a similar problem.

MGN’s picture

Title: Page titles disapear for specify path breadcrumbs » [page-title] tokens do not work in custom_breadcrumb_paths breadcrumbs on views pages
Category: bug » support
Status: Postponed (maintainer needs more info) » Active

In reading through the page_title module code in cvs, It seems that page_title doesn't support views pages. There is an issue (in progress) to do this at #176985: Support For Views. Of course if your view is embedded in a node then this might not matter.

The fact that one global scope token is working [site-name] indicates that the problem must have to do with the way that [page-title] is being created.

At this point I don't think this is a problem with custom_breadcrumbs_paths, but I'll change my mind if the same problem occurs with other (global) tokens.

mrfelton’s picture

There is indeed no support in page_titles for overriding the page title for Views pages. However, [page-title] will default to the value returned from drupal_get_title() if there is no overriden page title (from the modules hook_help, below) - this goes for views pages too. The lack of views support (as I understand it) is simply about being able to override the default page title per view...

So that doesn't explain why the [page-title] token works for all cases (Including for Views pages, where the [page-title] is set to the value of drupal_get_title()), except when a path custom_breadcrumb is set.

It also doesn't explain how forcing token.module to NOT cache its results results in both the breadcrumb AND the page title being set correctly. This seems like an indication of the cause... that either custom_breadcrumbs or page_title is doing something wrong, and a blank value for [page-title] is being set somewhere along the way, and cached.

For reference, this is from the modules hook_help

The Page Title module lets you change these defaults in two ways. First, you can adjust the patterns below using the placeholders given. This will change the way the default page titles are created. Second, on every content creation form you can have the option of specifying a title that is different than the title of the node. If a value is provided, this will be used to generate the [page-title] placeholder. If left blank, [page-title] will inherit the node's title.

[page-title] will default to the value returned from drupal_get_title if there is no overriden page title.

MGN’s picture

Category: support » bug
Status: Active » Postponed (maintainer needs more info)
StatusFileSize
new7.23 KB

Thanks for the clarification. I ran across another bug in the custom_breadcrumbs_paths code that may or may not relate to this issue.

I noticed that when a page had block views displayed with a node, cb_paths_nodeapi and cb_paths_views_pre_view were both setting the breadcrumb. The custom breadcrumb was written with node-scope tokens, and these were not being replaced because the views code was executed after nodeapi.

This patch modifies the hook_views_pre_view to check to first check if the view has a display with a path that matches the current path before trying to set the breadcrumb.

Its a long shot, but I thought this might be related to the [page-title] token issue.

I don't like mixing issues, but I was actually in the middle of another feature request when I found the problem. So, free of charge, the patch also adds wildcard matching to cb_paths. If desired, this feature can be activated at the custom breadcrumbs settings page (admin/settings/custom-breadcrumbs).

Sorry to combine these issues, but would appreciate it if you would be willing to test the patch and let me know if helps...

mrfelton’s picture

When I read your post:

I noticed that when a page had block views displayed with a node, cb_paths_nodeapi and cb_paths_views_pre_view were both setting the breadcrumb. The custom breadcrumb was written with node-scope tokens, and these were not being replaced because the views code was executed after nodeapi.

I thought that really sounded promising. But, unfortunately this didn't fix the problem...

I thought that the issue may be related to something else, sine the site I was having the trouble on has over 120 modules installed! However, I was able to easily reproduce this in a sandbox, and I now have some more info that may help. I have been able to further isolate the problem - it's only an issue if the Specific Path that I am trying to set a cb for is an alias of a view... you should be able to reproduce this:

1) enable page_titles, custom_breadcrumb
2) create a view with page display at /somepath and the the view a title
4) create a path cb for /somepath
3) visit /somepath and confirm that the title in your browser bar is as per you page_titles settings (that [page-title] is resolving to the title of the view) and that your breadcrumb has been applied
3) create an alias to this view at /somepath-alias
4) create a path cb for /somepath-alias
5) visit /somepath-alias and notice that the breadcrumb still works, but [page-title] is now being replaced with an empty string.

mrfelton’s picture

Status: Postponed (maintainer needs more info) » Active
mrfelton’s picture

Actually, I take that back - it doesn't work for the View weather its accessed directly or via an alias.

MGN’s picture

Status: Active » Postponed (maintainer needs more info)

Thanks for the great directions. I can reproduce the problem now and should be able to figure this out. Stay tuned....

MGN’s picture

Status: Postponed (maintainer needs more info) » Active
mrfelton’s picture

StatusFileSize
new7.41 KB

Right, think I cracked it:
this patch is exactly the same as your last one, with 2 small alterations...

1) use hook_views_pre_render() instead of hook_views_pre_view() - this seems to stop the token breakage. I think the problem was that at hook_views_pre_view(), a lot of stuff about the view (including it's title) hasn't been set yet... by the time it gets to hook_views_pre_render() all the information is there.

2) use drupal_get_normal_path() in custom_breadcrumbs_paths_views_pre_render() to get the system path - this allows the views path checking to work with aliases, allowing breadcrumbs to be set for views that are accessed at their system path as well as at an alias of that location.

MGN’s picture

Status: Active » Fixed

Great. I agree with both changes and can confirm that [page-title] now works as expected. Thanks for hunting that down. I'll commit the changes.

mrfelton’s picture

I'm now wondering if we should actually be using drupal_get_normal_path instead of drupal_get_path_alias...?

mrfelton’s picture

Actually... thanking about this again, we should really just use drupal_get_destination() - since we are interested in applying the cb based on the path the user enters, regardless of weather that is a system path or an alias (i think).

mrfelton’s picture

Status: Fixed » Active

OK... scratch that. The problem I'm encountering is not actually to do with the way of looking up the alias. It's todo with this code in hook_views_pre_render()

  $viewpage = TRUE;
  foreach ($view->display as $display) {
    $viewpage = $viewpage || ($display->display_options['path'] == $curpath);
  } 

It doesn't allow you to work with views with arguments. For example, a view could be accessed at /someview or /someview/arg1 or /someview/arg2 - all of which are different paths, and I need the ability to set the breadcrumb based on the path to the view, including its arguments. So /someview may have a different breadcrumb to /someview/arg2. However, $display->display_options['path'] only ever contains the base path of the view, so it is impossible to set a breadcrumb for /someview/arg2

mrfelton’s picture

I managed to fix this by altering the check like so:

  foreach ($view->display as $display) {
    $viewpath = $display->display_options['path'];
    // if arguments have been passed to the view, include these
    if ($view->args) {
      $viewpath .= '/'. join('/', $view->args);
    }
    $viewpage = $viewpage || ($viewpath == $curpath);
  }

However, since you have committed this already, I'm going to open a new ticket for this issue.
ps. thanks for your work on this.

mrfelton’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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