Index: filefield_paths.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield_paths/filefield_paths.module,v retrieving revision 1.19.2.11 diff -u -p -r1.19.2.11 filefield_paths.module --- filefield_paths.module 14 Apr 2009 00:17:50 -0000 1.19.2.11 +++ filefield_paths.module 15 Apr 2009 04:17:12 -0000 @@ -32,6 +32,37 @@ function filefield_paths_filefield_paths } /** + * Implementation of hook_theme(). + */ +function filefield_paths_theme() { + return array( + 'filefield_paths_token_help' => array( + 'arguments' => array('prefix' => '[', 'suffix' => ']') + ), + ); +} + +function theme_filefield_paths_token_help($prefix = '[', $suffix = ']') { + token_include(); + $full_list = array_merge(filefield_token_list(), token_get_list('node')); + + $headers = array(t('Token'), t('Replacement value')); + $rows = array(); + foreach ($full_list as $key => $category) { + $rows[] = array(array('data' => drupal_ucfirst($key) .' '. t('tokens'), 'class' => 'region', 'colspan' => 2)); + foreach ($category as $token => $description) { + $row = array(); + $row[] = $prefix . $token . $suffix; + $row[] = $description; + $rows[] = $row; + } + } + + $output = theme('table', $headers, $rows, array('class' => 'description')); + return $output; +} + +/** * Implementation of hook_form_alter(). */ function filefield_paths_form_alter(&$form, $form_state, $form_id) { @@ -175,7 +206,7 @@ function filefield_paths_form_alter(&$fo '#title' => t('!title replacement patterns', array('!title' => $field['title'])), '#collapsible' => TRUE, '#collapsed' => TRUE, - '#description' => theme('token_help', 'field') . theme('token_help', 'node'), + '#description' => theme('filefield_paths_token_help'), '#weight' => ($count - 1) * 3 + 2, '#attributes' => array( 'class' => $name .' tokens' @@ -512,7 +543,7 @@ if (!module_exists('filefield')) { /** * Implementation of hook_token_list(). */ - function filefield_paths_token_list($type = 'all') { + function filefield_token_list($type = 'all') { if ($type == 'field' || $type == 'all') { $tokens = array(); $tokens['file']['filefield-onlyname'] = t("File name"); @@ -524,7 +555,7 @@ if (!module_exists('filefield')) { /** * Implementation of hook_token_values(). */ - function filefield_paths_token_values($type, $object = NULL) { + function filefield_token_values($type, $object = NULL) { if ($type == 'field') { $item = pathinfo($object[0]['filename']); $tokens['filefield-onlyname'] = $item['filename']; @@ -539,16 +570,8 @@ if (!module_exists('filefield')) { */ function filefield_paths_process_string($value, $type, $object, $settings) { - // Process string tokens via Pathauto module - if (module_exists('pathauto') && $settings['pathauto']) { - $placeholders = _filefield_paths_get_placeholders($type, $object); - $value = str_replace($placeholders['tokens'], $placeholders['values'], $value); - } - - // Process string tokens via Token module - else { - $value = token_replace($value, $type, $object); - } + $placeholders = _filefield_paths_get_values($type, $object, (module_exists('pathauto') && $settings['pathauto'])); + $value = str_replace($placeholders['tokens'], $placeholders['values'], $value); // Transliterate string if (module_exists('transliteration') && $settings['transliterate']) { @@ -572,27 +595,27 @@ function filefield_paths_process_string( return $value; } -/** - * Temporary workaround for http://drupal.org/node/324736 - * @TODO: Implement non-hacky fix. - */ -function _filefield_paths_get_placeholders($type, $object) { - if (function_exists('token_get_values')) { - $full = token_get_values($type, $object, TRUE); - - foreach ($full->values as &$value) { - if (is_array($value)) { - $value = $value[0]; - } - } - - $tokens = token_prepare_tokens($full->tokens); - $values = pathauto_clean_token_values($full); - return array('tokens' => $tokens, 'values' => $values); +function _filefield_paths_get_values($type, $object, $pathauto = FALSE) { + switch ($type) { + case 'node': + $full = token_get_values($type, $object, TRUE); + break; + + case 'field': + $all = filefield_token_values($type, $object); + + $full = new stdClass(); + $full->tokens = array_keys($all); + $full->values = array_values($all); + break; + } + + $full->tokens = token_prepare_tokens($full->tokens); + if ($pathauto) { + $full->values = pathauto_clean_token_values($full); } - watchdog('Pathauto', 'It appears that you have installed Pathauto, which depends on Token, but Token is either not installed or not installed properly.'); - return array('tokens' => array(), 'values' => array()); + return array('tokens' => $full->tokens, 'values' => $full->values); } /**