Download & Extend

The pattern overwrite the custom title

Project:Page Title
Version:6.x-2.3
Component:Miscellaneous
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs work

Issue Summary

I set a pattern for the taxonomy title and I set the check on the "show field" checkbox.
After that I go to the taxonomy "edit term" page for my term and I try to write a custom title valid only for that term.
I see that my custom title has not overwritten by the module but my page has again the default pattern for taxonomy that I set.

Is this the correct behavior?

I think that the custom title for a term must overwrite the default pattern I set in module configuration.

Have anyone seen this behavior?

Comments

#1

Am having the same problem.

#2

Looking at what's going on in the code, I don't see it even trying to load the overridden value for terms (or anything else for that matter) in page_title_page_get_title(). I'll see if I can come up with a patch to fix it.

#3

Priority:minor» critical
Status:active» needs review

Changing the priority to Critical as this key functionality does not work in 6.x-2.3.

Here's a patch that makes the following changes to page_title_page_get_title():

  • Wrapped comments to a maximum of 80 chars per the Drupal coding standards,
  • Allowed for space for special cases, e.g. the forum root just loads a variable so no need to do any other heavy processing.
  • While identifying the type of object being viewed, it checks if that object can have its title overridden by the user.
  • Additional special case: node titles can be loaded via hook_nodeapi, so load it there.
  • If the object being viewed can be overridden it tries to load the appropriate title record.
  • If no title was found it processes the title pattern as usual.

Also:

  • Fix a bug in hook_nodeapi that would load the page_title even if the type did not allow it to be overridden.

This has allowed the page title to work as intended: if a page title is manually overridden load it first, otherwise use the pattern structure.

AttachmentSize
page_title-n654758.patch 7.7 KB

#4

In the interests of making it easier for beginners, I've bundled the latest code from the v6.x-2.x branch together with my patch: http://www.mc-kenna.com/drupal/2010/01/archive-of-page-title-module-with...

#5

FYI this also rolls in the fix from #654672: Invalid title on forum root.

#6

Looking at the code again, should the manually configured titles also be processed for tokens? Is there a reason why I can't set the title for a node to "something | [site-name]" and expect it to process the token?

#7

I've added a new ticket for processing manually-assigned titles: #689620: Pattern for processing manually-assigned page titles

#8

Status:needs review» closed (fixed)

An "undocumented feature" in Panels and a page_title misconfiguration was causing this for me.

#9

To clarify:

  • When using Panels to customize the taxonomy-term pages you must use e.g. "%term:name" as the panel's title.
  • The overridden page title gets loaded correctly as normal and is assigned as the token "[page-title]".
  • If set the vocabulary's page_title's pattern is set to e.g. "[cat] | [site-name]" it won't pick up the existing page title value as the "[page-title]" token doesn't exist; this includes the overridden value.

#10

Status:closed (fixed)» needs work

I'd like the field on the taxonomy term page to provide the token substitution for [page-title], but I want my $head_title to print out [page-title] | [site-name] (just like we can do with nodes).

I'm not sure this is possible with the current patch, though I may be mistaken.

I've set my default pattern to be: [page-title] | [site-name].
I've entered in my custom page title text on the term's edit form.

And my resulting page title is only [page-title].
The " | [site-name]" part is missing.

I think the behavior should be the same for nodes and terms, but I'm not really sure how to get there.

#11

FWIW, we ended up writing our own token. If the pattern is set, and the "show field" is checked, it will use the custom page_title if set, otherwise it will use the set pattern.

Here's an example of the token we setup:

hook_token_list().
*/
function mymod_token_list($type = 'all') {
$tokens = array();

if ($type == 'taxonomy' || $type == 'all') {
if (module_exists('page_title')) {
$tokens['taxonomy']['mymod-page_title'] = t("Page title because ignores defaults.");
}
}
return $tokens;
}

/**
* Implementation of hook_token_values().
*/
function mymod_token_values($type, $object = NULL) {
$values = array();

if ($type == 'taxonomy') {
if (module_exists('page_title')) {
$term_title = page_title_load_title($object->tid, 'term');
$values['mymod-page_title'] = !empty($term_title) ? $term_title : $object->name;
}
}

return $values;
}

#12

Neither of the 2 approaches work for me.
Firstly I tried from project's page the 6-dev version, then I tried the code from McKenna's site.
Finally I tried added the techgirlgeek's code in my page_title.module file which gave me a WSOD.

#13

@chefarov the code from @techgirlgeek was missing some comment markers at the beginning. Did you catch that? Try this:

/**
* Implementation of hook_token_list()..
*/
function mymod_token_list($type = 'all') {
  $tokens = array();

  if ($type == 'taxonomy' || $type == 'all') {
    if (module_exists('page_title')) {
      $tokens['taxonomy']['mymod-page_title'] = t("Page title because ignores defaults.");
    }
  }
  return $tokens;
}

/**
* Implementation of hook_token_values().
*/
function mymod_token_values($type, $object = NULL) {
  $values = array();

  if ($type == 'taxonomy') {
    if (module_exists('page_title')) {
      $term_title = page_title_load_title($object->tid, 'term');
      $values['mymod-page_title'] = !empty($term_title) ? $term_title : $object->name;
    }
  }

  return $values;
}