I have been trying to make a module to have a new token: [menupathortitle-raw] and [menupathortitle]
The idea is to have a token in pathauto replaced by the [menupath-raw] and if it is empty, use the [title-raw]

I have copy most of my code from token_node.inc


/**
 * Add a token for node with the path it mas have
 */
function token_customized_token_values($type, $object = NULL, $options = array()) {  
  $values = array();  
  switch ($type) {
    case 'node':
      $node = $object;
      
      /*************** CODE FROM token_node.inc ************/
      
      // Now get the menu related information.
      global $_menu;
      $trail = array();
      $trail_raw = array();
      $original_mid = token_menu_get_mid('node/'.$node->nid);
            
      $mid = $original_mid;
      while ($mid && $_menu['visible'][$mid] && $_menu['visible'][$mid]['pid'] != 0) {
        array_unshift($trail, check_plain($_menu['visible'][$mid]['title']));
        $mid = $_menu['visible'][$mid]['pid'];
      }

      // One more time, unfiltered
      $mid = $original_mid;
      while ($mid && $_menu['visible'][$mid] && $_menu['visible'][$mid]['pid'] != 0) {
        array_unshift($trail_raw, $_menu['visible'][$mid]['title']);
        $mid = $_menu['visible'][$mid]['pid'];
      }
      
      /******************** END CODE FROM **********************/
      
      print '<pre>';
      print_r(token_get_values($type,$object,FALSE,$options));
      print '</pre>';
      if (isset($trail) && count($trail) > 0) {
        $values['menupathortitle']     = implode('/', $trail);
        print $values['menupathortitle'] . "<br/>";
        $values['menupathortitle-raw'] = implode('/', $trail_raw);
        print $values['menupathortitle-raw'] . "<br/>";
      }
      else {
        $values['menupathortitle']     = check_plain($node->title);
        $values['menupathortitle-raw'] = $node->title;
      }
     
      break;
  }
  
  return $values;
  
}

/**
 * Add a description for our custom nodes
 */
function token_customized_token_list($type = 'all') {
  if ($type == 'node'|| $type == 'all') {
    $tokens['node']['menupathortitle']      = t("A custom token which provides the menupath and if it is blank, it provides the title");
  	$tokens['node']['menupathortitle-raw']      = t("The same as [menupathortitle] but with raw entry");
    return $tokens;
  }
}

The problem is that [menupathortitle-raw] gets the '/' escaped when it is print, so i get thinks like 'sectionAtitleA'. Since [menupath-raw] works well ('sectionA/titleA') and I am using the same code, I am really a bit lost.

Comments

josuealcalde’s picture

Status: Active » Closed (fixed)

Sorry if I have made someone lost time.
I have realized this is not a token issue. It is a pathauto issue.
If you want your '/' to be preserved, the name of the token must end in path or path-raw.

I will close this issue