pathauto.tokens.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * @file
  4. * Token integration for the Pathauto module.
  5. */
  6. /**
  7. * Implements hook_token_info().
  8. */
  9. function pathauto_token_info() {
  10. $info = array();
  11. $info['tokens']['array']['join-path'] = array(
  12. 'name' => t('Joined path'),
  13. 'description' => t('The array values each cleaned by Pathauto and then joined with the slash into a string that resembles an URL.'),
  14. );
  15. return $info;
  16. }
  17. /**
  18. * Implements hook_tokens().
  19. */
  20. function pathauto_tokens($type, $tokens, array $data = array(), array $options = array()) {
  21. $replacements = array();
  22. if ($type == 'array' && !empty($data['array'])) {
  23. $array = $data['array'];
  24. foreach ($tokens as $name => $original) {
  25. switch ($name) {
  26. case 'join-path':
  27. module_load_include('inc', 'pathauto');
  28. $values = array();
  29. foreach (element_children($array) as $key) {
  30. $value = is_array($array[$key]) ? render($array[$key]) : (string) $array[$key];
  31. $value = pathauto_cleanstring($value);
  32. $values[] = $value;
  33. }
  34. $replacements[$original] = implode('/', $values);
  35. break;
  36. }
  37. }
  38. }
  39. return $replacements;
  40. }