Community Documentation

Using path style tokens

Last updated October 8, 2010. Created by Dave Reid on October 8, 2010.
Log in to edit this page.

Pathauto enforces a couple standards when writing or using 'path' style tokens like 'root/subpage/page'.

Path and URL tokens are left alone by Pathauto...

Token names that end with the word 'path', 'alias', 'url', 'url-brief' (or any of the previous words with '-raw' appended) will be left untouched and not have pathauto_cleanstring() applied to it. This is because these tokens are assumed to be actual aliases or URLs and therefore may have already be processed by Pathauto.

...except for tokens with 'path' in the name and who's corresponding value is an array of segments

For example, if your module provides a token called 'object-path' that provides a 'fake' path-style token composed of separate components, and you want Pathauto to be able to clean the individual segments, you'll need to provide the token value as an array of segments if $options['pathauto'] = TRUE.

This is available only when using Pathauto 1.5+ or 2.0-alpha3+ in combination with Token 6.15+. A more proper solution is being considered for D7 token API.

Before:

<?php
function mymodule_token_values($type, $object = NULL, $options = array()) {
 
$values = array();
 
$object_path_raw = array($object->root_name, $object->parent_name, $object->name);
 
$object_path = array_map('check_plain', $my_token_path_raw);
 
$values['object-path-raw'] = implode($object_path_raw, '/');
 
$values['object-path'] = implode($object_path, '/');
  return
$values;
}
?>

After:

<?php
function mymodule_token_values($type, $object = NULL, $options = array()) {
 
$values = array();
 
$object_path_raw = array($object->root_name, $object->parent_name, $object->name);
 
$object_path = array_map('check_plain', $my_token_path_raw);
 
$values['object-path-raw'] = !empty($options['pathauto']) ? $object_path_raw : implode('/', $object_path_raw);
 
$values['object-path'] = !empty($options['pathauto']) ? $object_path : implode('/', $object_path);
  return
$values;
}
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Programmers, Site administrators
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.