I was trying to add a "file" token and noticed it wasn't working with filefield_paths. Looking into the code, I see the token values are retrieved in _filefield_paths_get_values like this:

switch ($type) {
    case 'node':
      $full = token_get_values($type, $object, TRUE);
      break;

    case 'field':
      $all = filefield_paths_token_values($type, $object);
      if (function_exists('filefield_token_values')) {
        $all = array_merge(filefield_token_values($type, $object), $all);
      }

      $full = new stdClass();
      $full->tokens = array_keys($all);
      $full->values = array_values($all);
      break;
  }

Is there any reason the values can't be retrieved in 'field' the same way as for 'node'?:

$full = token_get_values($type, $object, TRUE);

This would give people the ability to add their own tokens instead of being restricted just to filefield and filefield_paths. Further, is there any reason not to use token_replace() instead of str_replace() + token_get_values() ?

Comments

deciphered’s picture

Issue tags: +FileField Paths 2.x

I'm positive I had a very good reason for this at the time, however I have no idea what that reason is now, and I have already done what you have asked in my local development copy of the upcoming 2.x branch.

If I do remember the reason I will be sure to let you know and document it so I don't forget it next time :)

Cheers,
Deciphered.

xurizaemon’s picture

I'm interested in this feature too, as I have to build some custom tokens based on altered node title + field name.

@Deciphered, I would probably be an avid tester of filefield_paths 6.x-2.x if it was in CVS (that's assuming you're doing 2.x for Drupal 6, of course).

deciphered’s picture

Grobot,

Expect the 2.x branch (yes for Drupal 6, although I really should have built for 7 and backported to 6) to be committed within the week, I'm really hoping to get it in by Friday.
One thing to note, which will have to be put somewhere in big letters for a while, is that I am dropping support for non-CCK modules, which considering most people not even knowing that they where supported probably isn't going to be a massive deal.

 

As a side note, I just remembered why I wrote that code the way I did, and it's because 'Field' type tokens can relate to any type of field, not just a FileField, so it would not only provide un-usable tokens, it would also have modules redeclaring the same tokens which causes an issue for the Token module.

I did come up with a solution for this issue in another module (Custom Formatters I believe) which provides a hook for other modules to register with the module to have their own tokens included. I'll provide further information on this once I get to that stage in development/testing.

Cheers,
Deciphered.

crea’s picture

Subscribing.
Any news on 2.x ?

deciphered’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)

No longer supporting Drupal 6 issues for this module.