I have a custom module that registers custom tags.

When I enter [mycustomtag] in Pattern for Story (or any content type) but override it on the node form by populating the page title field I see [mycustomtag] instead of the custom text for the title.

Although this patch does what I need it to do, I'm not confident that this is a good way to solve the problem.

CommentFileSizeAuthor
page_title.module.patch939 bytesj0hn-smith

Comments

nicholasthompson’s picture

Status: Active » Closed (works as designed)

The Page Title field on the nodes does not accept tokens in it. It is simply a field which can be used AS a token when you configure the pattern for the node.

j0hn-smith’s picture

I'm not entering a token in the Page Title field on the node form.

Page Title default settings (Default Pattern): [mycustomtag]
node form Page Title field: 'I want this text to replace the custom tag.'

When I try this the title shows as '[mycustomtag]', but I'm not sure why. When the field on the node form is blank the title shows the custom tag as expected. The problem only occurs when text is input into the node form field.

Basically the field in the node form only overrides [page-title], I'd like to be able to choose a different token to override instead. Maybe this should be a feature request?

Many thanks

nicholasthompson’s picture

Err... Why do you want to override a different token? Whats wrong with [page-title]?

If you create your own module which implements the token hooks and is in either the global or the node scope then you can declare your OWN [mycustomtag] which can be used in the default pattern...

Apart from that, the Page Tile field overrides the [page-title] and nothing else. I cant see a genuine use-case for having a configurable token placeholder. Maybe I'm missing something?

j0hn-smith’s picture

If you create your own module which implements the token hooks and is in either the global or the node scope then you can declare your OWN [mycustomtag] which can be used in the default pattern...

That is exactly what I'm doing. But as I specified [mycustomtag] in the defaults, this is the tag I want to override to change the html page title.

I should just overwrite [page-title] in my module instead of creating a custom tag I think.

Sorry for wasting your time.

nicholasthompson’s picture

Status: Closed (works as designed) » Postponed (maintainer needs more info)

Can you provide your [mycustomtag] token implementation code please? I have a feeling this is more of a token issue than a Page Title issue as any token which is in the global scope or the node scope (assuming its a node page) will have complete access to the tokens...

Page Titles Token implementation is:

/**
 * 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;
}
j0hn-smith’s picture

If I use either [page-title] or [longname] in the admin/content/page_title/settings defaults they display correctly, but neither gets overridden by text entered in the page-title field on the node form. I understand that this field only overrides [page-title] so there's no reason why it should change [longname].

Here's the code I'm using to create the tokens.

function general_page_token_values($type, $object = NULL, $options = array()) {
  if($type == 'node') { // if I change the scope to global I get Array due to array_merge in tokens (see below)
    $node = $object;
    
  	$masternode = hotel_master_object($object->hotel_id);
      $tokens['page-title'] = $masternode->hotel_long_name;  // this line is preventing the page title field on the node edit page from working with node scope
      $tokens['longname'] = $masternode->hotel_long_name;
    
    return $tokens;
  }
}

I think the problems are caused by different token scopes, the use of array_merge in the tokens module and possibly the module weight in the system table. I've created a support request against tokens #304333: How can I overwrite [page-title] from my custom module? re the array_merge issue, maybe a patch for tokens is necessary to overwrite the duplicates instead of merge them?

I just want to be able to overwrite [page-title] with for all nodes, and override [page-title] for a specific node using the field on the node form - drupal should be able to handle this.

j0hn-smith’s picture

Nicholas, can I discuss this with you on IRC? What time of day are you around (UTC)?

Thanks

nicholasthompson’s picture

I might be around today, right now i'm HUGELY busy migrating several dozen websites between 2 servers.

I'm wondering if your problem here is that - alphabetically speaking - your module gets run before mine. If you're module either had a higher weight OR was called "zzzz_general_page" then it would probably get run after...

j0hn-smith’s picture

Thank for taking the time to discuss this, I appreciate that you're busy.

I played with the weights but that didn't change anything.

I'd started hacking both page-title and tokens which isn't a good idea so I decided to leave tokens alone and make my own custom version of page-title that does what I need it to do. It's not a large module so the maintenance should be minimal.

Page-title, as it stands, is a great module - it's just that my requirements for it are obscure.

Many thanks for your help.

nicholasthompson’s picture

The do seem a little "edge" ;-)

I'm still a little hazy why you want to create a new field with a new token instead of using the [page title] token/field. You could probably even use a CCK field as an alternative if you really want a separate field?!

The conversation has spawned another thought though... I might implement a "hook_page_title_alter" where other modules can be written to modify the page title after is generated. I might even create an earlier hook so that other modules can DEFINE their page title.

j0hn-smith’s picture

I didn't want another field, I wanted to use the page-title field but for a different token.

I already had another token that contained the value I wanted to use, my original thinking was to use that token but when I realised that would 'go against the grain' I decided to use [page-title]. I thought it would be as simple as [page-title] = [mytoken], unfortunately not.

The conversation has spawned another thought though... I might implement a "hook_page_title_alter" where other modules can be written to modify the page title after is generated. I might even create an earlier hook so that other modules can DEFINE their page title.

That sounds like the sort of functionality I'm after, especially the second part.

If you're interested I can show you my custom page-title module.

nicholasthompson’s picture

Status: Postponed (maintainer needs more info) » Fixed

That'd be good. You can either attach it here or if you use my contact form I will reply back so we can contact via email.

Marking this as fixed for now. Will start a new thread about the features.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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