I'm trying to render an email template using files attached to the node. There's a CCK field that holds the HTML for the email template, and a CCK file field that has multiple values (all the images for the template).

I'm trying to merge the attached filefield images in one at a time.

in filefield_token_values, the $object being passed in is indexed for all the files, but the function hard-codes an index of 0. I can see that this is likely complicated. How could I patch this to support multiples? Basically, I'd like to be able to specify what the index of object should be.

function filefield_token_values($type, $object = NULL) {
  if ($type == 'field') {
    $item = $object[0];

I am more than willing to write it, test it, make it work for me, and submit a patch, but could use a little pointing in the right direction.

I want to say I've seen other modules do something like [yourtoken-1] where the -1 is the specified index. I can't locate anything like that now that I need to, though.

Comments

chrisfromredfin’s picture

Status: Active » Needs review
StatusFileSize
new2.85 KB

OK, I took hints from the date module and how it sort of dynamically generates the "to-date" tokens, if they're available.

My patch does a lot of code copying, but this way it keeps the tokens intact and simple when there's not multiple values.

Patch is against 3.1, but should work against HEAD too based on the latest -dev snapshot, since the file is the same.

chrisfromredfin’s picture

StatusFileSize
new5 KB

This is just another option; adding the branch to generate one or the other... not sure which is the best solution.

I'm sure this can be cuter/cleaner, maybe by dynamically generating a string to append?

jday’s picture

was this committed to the latest filefield release? if not can you update the patch?

chrisfromredfin’s picture

Priority: Normal » Critical

No, I've not seen any activity/interest in getting it into filefield. I would like to, though, or see if the maintainer has another idea.

quicksketch’s picture

Version: 6.x-3.1 » 6.x-3.2
Priority: Critical » Normal

This is not a critical feature. I'm not particularly keen on including it, to be honest. It adds excessive tokens than I think are necessary for the 80%+ use-case. Though another module can always provide these tokens if needed.

chrisfromredfin’s picture

Priority: Normal » Minor
Status: Needs review » Postponed

OK, that's what I was wondering. I'll see about creating (and hopefully contributing) something like "multi-tokens" module or something. Thanks for the feedback.

quicksketch’s picture

Status: Postponed » Closed (won't fix)
roderik’s picture

Linkspam for people googling this subject: a module like #6 is at http://drupal.org/project/token_array. I'm using it for filefield tokens.