I'd like to have support for fields which take multiple values. Currently, I looked at the code:
function text_token_values($type, $object = NULL) {
if ($type == 'field') {
$item = $object[0];
$tokens['raw'] = $item['value'];
$tokens['formatted'] = $item['view'];
return $tokens;
}
}
IMHO, this should at least be made clear in the documentation that this only retrieves the first value. Ideally though, I was thinking it should generate two tokens, one being a dynamic token (can this be done?) where if the field was Food the token would be: [node:field_food-raw-x], and someone could use Hi, I like node:field_food-raw-0 and node:field_food-raw-1. It would also be nice to have something like: node:field_food-raw-all which would return the values with a delim of some sort, of rendered through cck's theme_field.
What do you think? I can take this on, but I'd like some direction on what would be preferred.
Comment | File | Size | Author |
---|---|---|---|
#14 | cck_2-156860-14.patch | 18.55 KB | Agileware |
#14 | cck_3-156860-14.patch | 21.57 KB | Agileware |
#12 | cck_2-156860-12.patch | 12.18 KB | Agileware |
#12 | cck_3-156860-12.patch | 12.18 KB | Agileware |
#11 | cck-content.token_.inc_.patch.txt | 1.77 KB | ayalon |
Comments
Comment #1
JacobSingh CreditAttribution: JacobSingh commentedOkay, I made a little patch for this (as a proto, only works with the text fields for now):
Comment #2
JacobSingh CreditAttribution: JacobSingh commentedCan someone look at this?
Comment #3
gregglesThe way that you've described it, my opinion is that this should be implemented in token2.x (see some discussion at token group page).
If you'd like to work towards that effort I personally would be very excited about it.
Comment #4
suit4 CreditAttribution: suit4 commented+1 for integration!
Great job! works absolutely flawless!
There is a typo in the path, the second line starting with
$tokens['text']['formatted-all']
should read
$tokens['text']['formatted-n']
Comment #5
doublejosh CreditAttribution: doublejosh commentedYou can also solve it like this...
Choose "Evaluate PHP in pattern."
My context is a list of colors to create a palette, where the title becomes a list of the colors chosen.
Comment #6
rdmillner CreditAttribution: rdmillner commentedDoes the OP's code work in 6?
Comment #7
ptrepoff CreditAttribution: ptrepoff commentedIs this a feature that is going to be implemented into tokens. If not what adjustments need to made to use this patch to work with the v6 version of tokens?
Comment #8
gregglesAll Token related code for 6.x is basically the same. CCK code has changed a bit and, one important distinction, all token code for 6.x should be in CCK directly.
Comment #9
markus_petrux CreditAttribution: markus_petrux commentedThis is related to #272949: Token for mail address of user in CCK user reference field
(probably, the title on that issue will change when token is ready for CCK to implement these enhancements).
Comment #10
crusher82 CreditAttribution: crusher82 commentedHave you some news about that problem ?
Comment #11
ayalon CreditAttribution: ayalon commentedI wanted to add a checkboxfield with multiple possibilities to an Email with token. This is not possible unless you use the patch.
I updated the patch for the latest cck version.
It's working perfect and it would be very good, if this could be committed.
Comment #12
Agileware CreditAttribution: Agileware commentedI have another very similar solution to this problem.
When I started I forgot that I'd previously noticed this issue.
Anyway, here is my patch with a version also made for 6.x-3.x-dev.
I plan to make some additional modifications for 6.x-3.x-dev so that the
multiple values can be properly grouped by their multigroup, which is my original use case.
It provides support for text, number, node reference & user reference fields and
also uses a theme function for the token so that the separation of each value
can be customised. For example a themer can override it to output as an unordered list.
Note that it needs some testing for the reference fields as I am primarily using it for text.
I have currently made the default separator a
tag due to my requirements but
that can be changed to whatever people think is best.
Both patches are against latest dev versions.
Comment #13
Agileware CreditAttribution: Agileware commentedComment #14
Agileware CreditAttribution: Agileware commentedI have changed my approach a bit since tackling the task of fieldgroup tokens.
Here are new patches that include the following:
* Tokens for all values (for example raw-all & formatted-all)
* Tokens for individual deltas of fields for example (for example raw-# & formatted-# where you replace # with the delta you want)
* Tokens for fieldgroups, and multigroups in the case of cck 3. (for example raw, formatted, raw-titles & formatted-titles)
These tokens will print all fields of a specified group
The raw-titles & formatted-titles tokens also print the field names before each field of the group.
The fields will appear in the order they appear in the group for fieldgroups and multigroups.
Any tokens with multiple fields in them will run through the theme function:
where type is either field or group so the different token types can be differently themed.
This allows users to change the separator of the fields.
Both patches against latest devs.
Comment #15
Agileware CreditAttribution: Agileware commentedComment #16
jday CreditAttribution: jday commentedApplied the patch, works GREAT, Thank YOU!
Update:
spoke too soon, the patch works great for multiple text value tokens, but I also have a filefield that allows multiple values and I'm not getting tokens for each file...
Comment #17
Agileware CreditAttribution: Agileware commentedmmm, originally I was thinking that other modules like filefield & date do their own
tokens but in the case of fieldgroups & multigroups it needs to be handled by cck.
So the best way to do it without duplicating code would be to make cck call
the normal token_values functions for each field of the group from within
the groups token_values function.
Then it should work properly for all cck fields.
I was going to do it that way at one point anyway.
I will do another version of this patch to address this.
PS: However, these parts:
will still have to be done by the other modules, so filefield has to implement that.
Ideally in the same manner as whatever is decided on here so it all works together well.
Comment #18
3dloco CreditAttribution: 3dloco commented+1
Comment #19
jsm174 CreditAttribution: jsm174 commentedJust applied the patch from #14 for 2.x. Awesome! Works great.
This patch should get committed.
Comment #20
Agileware CreditAttribution: Agileware commentedYeah, but I still need to do a little bit more work on it Re: #16 & 17
I just haven't had time lately.
Comment #21
simonmetacci CreditAttribution: simonmetacci commentedsubscribing, really need this to get fixed.
Im using the date module and want to print 'all' values out and as I can see they have to implement this aswell..
Looking forward for a patch for this issue<3
Comment #22
interestingaftermath CreditAttribution: interestingaftermath commentedI cannot get the patch in #14 to work correctly. I know I am doing something wrong. Please help.
I have run the patch and I see the tokens in the list to choose from. I am using Notifications/Messaging to send out node creation emails. All of the tokens work except for the new tokens provided by this patch. They do not print anything in the e-mail.
It's a plain text e-mail and I have tried raw and formatted. I've tried many options in the Tokens/Displays options as well. Here is the latest of my email:
I have a couple extra fields printing (as you can see) because I would like to see what they do. From that above this is what the e-mail looks like when it hits my inbox:
What am I missing?
Comment #23
interestingaftermath CreditAttribution: interestingaftermath commentedComment #24
Agileware CreditAttribution: Agileware commentedPlease don't change the status unless there is reason, this patch still needs work (See #16 & #17)
See here for information regarding what each of the statuses mean - http://drupal.org/node/156119
Comment #25
interestingaftermath CreditAttribution: interestingaftermath commentedSorry about that and thank you for the link. I wasn't sure of the meaning of the status options.
That said, I think the issues addressed in 16/17 do not apply to my issue. I believe I am just missing something because it seems you claimed that the patch does what I need it to. Any help?
Comment #26
interestingaftermath CreditAttribution: interestingaftermath commentedI have figured this out. Not really sure how. Just upgraded to the latest dev version and it started working. Any idea how to do something like this?
But instead of those static delta numbers do some sort of a counter? If I do this...
...it does exactly what it says. It prints ALL jb_part_number in a row, then ALL quantity_ordered in a row, etc.
I'm wanting to theme the contents of this multigroup in a table of some sort in an html e-mail. The results need to come out so that I can wrap them in tr/td tags, etc.
raw & raw-titles almost do the trick but for me they just print the fields down a straight line. How am I able to theme that somehow?
Comment #27
Agileware CreditAttribution: Agileware commentedif you are somewhere you can use php you could do something like this possibly (provided you have access to the $node)?
$output would be a table like you require, but it depends on your situation as to whether you can use php like that.
Another way you could probably get what you want would be to use cck 6.x-3.x-dev and put your fields into a multigroup.
Then use the 6.x-3.x-dev version of this patch.
That would depend on if cck 6.x-3.x-dev is good for your situation.
Comment #28
interestingaftermath CreditAttribution: interestingaftermath commentedThank you for your response. This information is being sent out as an e-mail so I don't know if I am able to use PHP.
That said, I am using cck 6.x-3.x-dev and the 6.x-3.x-dev version of the above patch AND I have these fields in a multigroup. What am I doing wrong?
Comment #29
interestingaftermath CreditAttribution: interestingaftermath commentedAs I mentioned above, I am using the CCK and PATCH versions that you recommend so many there is an easier way to go about doing this.
I tried the PHP code that you so kindly wrote for me. I made sure that all filters were set to PHP code (I am using the Messaging & Notifications module to send out a e-mail containing the contents of this multigroup on node creation). However, the PHP is not printing anything in the e-mail and I am getting an error on node creation.
This may be pointless information, but as I change the line that the PHP snippet appears in the e-mail body, the error code "line" number changes accordingly.
Any ideas would be very appreciated!
Comment #30
interestingaftermath CreditAttribution: interestingaftermath commentedI'd still like to know what the other method you mention was when you weren't sure if I was using the 3.x-dev version of CCK and the PATCH. I did figure out the issue when using Rules to send the e-mail. I added "node:" to your code. Thanks!
Comment #31
interestingaftermath CreditAttribution: interestingaftermath commentedHello again. The code posted above works great in Rules -> Mail to Arbitrary address -> event "after saving new content". However, it does NOT work for event "after updating existing content".
Here is what I found by doing print_r($node) in both e-mails.
"After saving new content" prints
"After updating existing content" prints
Any ideas?
Comment #32
jday CreditAttribution: jday commentedapplied the patch in #14 to cck 6.x-2.7,
but multiple value tokens are blank ( [node:field_myfield-formatted-all] )
Comment #33
twistedindustries CreditAttribution: twistedindustries commentedSame here...
Comment #34
letzel CreditAttribution: letzel commentedsubscribe
Comment #35
Itangalo CreditAttribution: Itangalo commentedI'm feeling a bit stupid finding a lot of issues about Token and multiple value CCK fields and multiple taxonomy terms. I took as an exercise to code this myself, and ended up with something that looks pretty decent.
Code and demo screencast can be found here, if anyone's interested: http://nodeone.se/blogg/learning-to-code-array-tokens-module
Comment #36
roderikItalango has now turned this into a project on d.o, check out http://drupal.org/project/token_array
w.r.t. the original subject: token_array generates tokens for 'multiple entry fields', not for 'field groups'.
Comment #37
NancyDrusub
Comment #38
mjstone323 CreditAttribution: mjstone323 commentedsubscribe
Comment #39
mjstone323 CreditAttribution: mjstone323 commentedI wish to use tokens for multigroups in some triggered actions. I'm hoping very fervently that someone is working on this, since an important aspect of the project I'm currently working on is not functioning due to the fact that there are no tokens for multigroups, and I don't know how to create them, although I'm trying to learn.
I took a look at the way the information is stored in the database. Unlike single-field content, which is all stored in one row of a table, with a key that indicates the id of the main node, each field in multigroup field content is normalized an additional level, and is stored in its own table, with two keys (the main node id and a "delta" indicating the placement of each item of data in an array).
I would like to try my hand at creating tokens myself, but my understanding of PHP is so rudimentary that I can't yet even write a token for a regular field, let alone one with two keys.
Also - could Rules handle any kind of token, or would a token for a multigroup would be incompatible without a change to Rules? Finally, would the Token module need to be updated with some protocol for handling this type of token?
I will continue to try to figure this out, but if anyone is working on this, please share what you have learned so far.
Edit: Just found this: http://drupal.org/node/690140#comment-3541778
and I'm realizing I just don't have the skills to figure this out on my own. Really need tokens for multigroup fields included in the CCK module.
Comment #40
Itangalo CreditAttribution: Itangalo commented@mjstone323: I think it's a good idea to start a new issue for this – your feature request risks being forgotten here (since this issue deals with field groups and multiple entry fields).
Rules *will* work with any kind of tokens - no worries there.
Good luck!
Comment #41
mjstone323 CreditAttribution: mjstone323 commentedThanks! I appreciate your advice - I'll open a new feature request.
Comment #42
Murzsubscribe
Comment #43
creando sensaciones CreditAttribution: creando sensaciones commentedsubscribe