Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 779747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:58:28+00:00 2026-05-14T19:58:28+00:00

I have Pathauto configured to generate an alias based on the title of a

  • 0

I have Pathauto configured to generate an alias based on the title of a node, for a specific content type. The problem is that I want to make small changes in this title before Pathauto uses it to generate the alias.

The first comment in this post suggests the use of hook_token_values, but I couldn’t really understand how to use it, even after reading the docs. In my tests, when I implement this hook, the alias generated is always “array”, which means I’m missing something.

Any help? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:58:28+00:00Added an answer on May 14, 2026 at 7:58 pm

    It might be that you missed to implement hook_token_list as well. Providing a new token is a two step process:

    1. Implement hook_token_list to declare the tokens you are going to provide. This will just be the name of the tokens, along with a short explanation, and the information to what type of objects the tokens will apply (e.g. node, user, taxonomy, …)
    2. Implement hook_token_value to actually generate the content of the tokens. This will be called when the tokens are to be replaced with the content they should stand for.

    As you just want to provide an alternative version of the title token already provided by the token module, it is probably best to just copy the relevant portions from token_node.inc, stripped down to the relevant cases and adjusted to be used in another module:

    /**
     * Implementation of hook_token_list().
     */
    function yourModule_token_list($type = 'all') {
      if ($type == 'node' || $type == 'all') {
        $tokens['node']['yourModule-title'] = t('Node title (customized version by yourModule)');
    
        return $tokens;
      }
    }
    

    This simply says that yourModule provides a token for node objects, named yourModule-title, along with a short description. The main work gets done in the other hook:

    /**
     * Implementation of hook_token_values().
     */
    function yourModule_token_values($type, $object = NULL, $options = array()) {
      $values = array();
      switch ($type) {
        case 'node':
          $node = $object;
          // TODO: Replace the check_plain() call with your own token value creation logic!
          $values['yourModule-title'] = check_plain($node->title);  
          break;
      }
    
      return $values;
    }
    

    This will be called whenever the tokens for node objects are needed, with the node in question being passed as the $object parameter (for a user token, the $type would be ‘user’, and $object would be the user object, and so on for other types). What it does is creating an array of values, keyed by the token name, with the replacement for that token as the value. The original code from token_node.inc just runs the title through check_plain(), so this would be the place to insert your own logic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a community based site, which is Drupal's strength. However I
for example , i have node with title 'services & containers' , drupal path
Have a look at one of my websites: moskah.com The problem is that it
I'm having a problem working out how drupal structures content. I have a content
Have a problem with agsXMPP. What I want to do, is connect to openfire
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
have a nice day. I got problem when trying to create an image from
Im using pathauto so user profiles have a clean URL in the format /user/name-name
If I disable pathauto in my Drupal installation, am I going to have any
I made a customized template called node-mynode.tpl.php Whenever a node of type mynode is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.