Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The title says it all: a small patch and an include file to support profile.module.
Requires this patch to properly function.
--
Stefan Kudwien
www.unleashedmind.com
Comment | File | Size | Author |
---|---|---|---|
#103 | 125640-token-profile-D6-2.patch | 8.3 KB | killua99 |
#100 | 125640-token-profile-D6-1.patch | 3.34 KB | killua99 |
#91 | 125640-token-profile-D7.patch | 11.43 KB | Dave Reid |
#89 | 125640-token-profile-D7.patch | 6.5 KB | Dave Reid |
#77 | 125640-token-profile-D7.patch | 3.29 KB | Dave Reid |
Comments
Comment #1
smk-ka CreditAttribution: smk-ka commented1. Rename to token_profile.inc
2. Put in token folder
Comment #2
eaton CreditAttribution: eaton commentedI'm concerned that the method used here would be very expensive -- it might be useful to put them in an explicit 'profile' token domain rather than the general 'user' domain. Ideally, I'm trying to move away from sticking piles of .inc files into the token project itself, as modules can support tokens directly, but since profile.module is in core that's not going to happen. I'll ponder it and see if there's a way to keep things speedy. If you have any ideas on that, definitely chime in!
I am, though, committing the patch for the recursive array merging. It's a must-have. Thanks!
Comment #3
smk-ka CreditAttribution: smk-ka commentedI'd be okay with a separate 'profile' domain, if we can somehow add support for multiple $types and $objects in token_replace() and token_get_values(). That would ease the merging of results coming from multiple domains. (In fact, as I am in the process of switching invite.module to make use of tokens, this missing functionality forced me to do lots of copy 'n paste...)
What I'm thinking of is changing those two parameters to accept either single values or arrays, possibly in several combinations similar to PHP's str_replace():
- string, object (legacy - one domain, one object)
- array, array (multiple domains with matching number of objects)
- array, object (multiple domains using always the same object)
That would allow us to handle multiple domains efficiently. What do you think?
Comment #4
eaton CreditAttribution: eaton commentedHmmmm. That's an interesting idea. I'd feel more comfortable using keyed arrays rather than 'matching' arrays... something like:
token_replace('[token] string [another-token]', array('node' => $node, 'user' => $user);
This wouldn't be as cleanly forward-compatible, unfortunately. Perhaps providing a wrapper function -- token_replace_multiple() or something like that -- would be the best approach? Behind the scenes, it would be almost exactly the same, but the compatibility would be cleaner...
Thoughts?
Comment #5
smk-ka CreditAttribution: smk-ka commentedI am continuing the multiple types question over here because it has nothing to do with profile support.
However, I'd still like to see profile support get in, and discuss any performance issues separately. With the perspective of supporting multiple types, I've moved profile fields into their own type.
The drawback of this solution is, that it will be harder to handle for third-party developers. They now have to explicitly include the type 'profile', whereas before it was sufficient to include the domain 'user', that is, token.module handled the inclusion of dependent types belonging to a domain (though not very smart performance-wise).
It probably would be best to have an identifiable domain in the token ([user: id]), which would allow us to load values on demand (think of preg_replace_callback()) rather than having to prepare all associated values in advance. But that's another story...
Comment #6
smk-ka CreditAttribution: smk-ka commentedThe above blah blah should have been accompanied by a modified profile patch, so here it is. Patch is against CVS DRUPAL-5.
Comment #7
smk-ka CreditAttribution: smk-ka commentedRe-rolled patch against current DRUPAL-5 branch.
Comment #8
sun+1 for this feature since there are already related issues that would benefit from it, f.e. personalizing Simplenews newsletters.
Comment #9
recidive CreditAttribution: recidive commentedI think it should be in the 'user' token domain, because if you load a user object using
user_load()
it will have the profile properties as well. Soprofile_token_values()
would be something like:I'm going to work on a patch.
Comments?
Comment #10
recidive CreditAttribution: recidive commentedAs promised, here is the patch.
Comment #11
recidive CreditAttribution: recidive commentedOps, I mean HERE is the patch :).
Comment #12
recidive CreditAttribution: recidive commentedChanged
profile_token_list()
function so it makes use of_profile_token_profile_fields()
too.Comment #13
recidive CreditAttribution: recidive commentedSorry, needs review.
Comment #14
smk-ka CreditAttribution: smk-ka commentedJust a sidenote:
The Personalized e-mail project contains a patched token_user.inc that has support for Profile and Nodeprofile modules. Contrary to my former patches, it takes the same approach as recidive's latest efforts, ie. profile/nodeprofile tokens are put in the user domain (where they actually belong).
Comment #15
gregglesThe problem with "where they actually belong" is performance...
Has anyone done benchmarks on this?
Comment #16
grah CreditAttribution: grah commentedwould this work for 6x? if not, any plans for token to support profile fields in 6x?
Comment #17
deviantintegral CreditAttribution: deviantintegral commentedCan someone point me in the right direction for how to properly benchmark this? I'd be glad to help with testing / coding, as this is a feature I really need so Signup can use real names instead of usernames in salutations.
This patch still applies cleanly and does work from a functional level.
Thanks,
--Andrew
Comment #18
gregglesFrom the handbook: http://drupal.org/node/79237
"How to benchmark Drupal Code"
Thanks for offering to benchmark this, it would be great to include this functionality.
Comment #19
deviantintegral CreditAttribution: deviantintegral commentedOk, I finally managed to get some benchmarks done. It looks like there is no noticeable difference in performance. The steps I followed:
I've attached the results, which are virtually identical. If we want more stress testing with *lots* of profile fields, I can do it, but I doubt there will be any issues given the attached results.
--Andrew
Comment #20
greggles@deviantintegral - thank you very much for this detailed work. I'll try to test this and confirm the benchmark in the next few days at which point I would have to agree - let's add it.
Comment #21
lpol CreditAttribution: lpol commentedHi,
Could someone tell me what should be the exact syntax to point to a specific profile field value ? To make things clear :
- I used the "profile" module to create a "real name" field that users fill in when they register.
- I changed the username to display this field value.
- I've installed nodeprofile to create "public profiles" for other users. As you may know this module creates specific nodes used as user profiles.
- I'm using auto_nodetitle to automatically replace this node's title with the value of the "real name" field I created in first step (name is profile_pseudo).
- I replaced the standard token_user.inc file with that included in the Personalized mail module, as it is supposed to let me point to the profile & nodeprofile field values.
Unfortunately, when I type "[profile_pseudo]" in the automatic title generation field, it does not work.... Help please !
Comment #22
lpol CreditAttribution: lpol commentedI succeeded... If anyone's interested, I just inserted the following code :
"
"
in the PHP argument textbox.
Comment #23
mysocom CreditAttribution: mysocom commentedvery intresting
Comment #24
recidive CreditAttribution: recidive commentedUpdated patch.
Comment #25
recidive CreditAttribution: recidive commentedPatch for version 6. Untested.
Comment #26
hanoiiWhat's the status of this issue and the actual possibility of this getting into token's module? I had a stalled project related to this and now I am bringing it up to life again. My main objective is to have a working module for that would let me personalize newsletters (there's been a reference to that issue as well in this thread) and I built a token_profile module that does something very similar to what recidive's patch does. Actually I haven't got that far as to properly support all the profile fields format as he did.
I was thinking if uploading both modules (token_profile and simplenews_token) one I have them completed but was wondering if I should do that if there's plan to follow this issue into token's core.
There's also something else in my mind and that's a default replacement text for empty profile fields, as you can imagine, this is very useful but very specific to newsletters, but, by working this into a module, I can have a bit of a freedom and I was thinking in providing a helper module which would let you configure a default replacement for your profile fields. In that case, I'll need to do the profile replacement in a specific module.
What do you think of uploading it anyway?
Comment #27
greggles@hanoii - I'd say that the status is we need a review of the latest 5.x and 6.x versions uploaded by recidive.
@recidive - I assume this is a re-roll of your patch in #12. Thanks for your help with this!
Comment #28
greggles@hanoii - Also, your use of profile tokens seems very specific and therefore it might not be useful for general use.
Comment #29
recidive CreditAttribution: recidive commented@greggles, yes, this is a re-roll.
Comment #30
hanoiiIt certainly pretty specific what I wanted to do, actually I changed my mind and I am thinking in creating a custom token modules that would let user add custom tokens with PHP support for any complex replacement.
I have applied #24 and tested it a little bit and so far it's working great.
Comment #31
MGN CreditAttribution: MGN commentedI've applied the patch in #25 to 6.x-1.11, and it works as described. I haven't encountered any problems yet. I think this is a very useful addition. Thanks.
Comment #32
greg.harveyIs this patch likely to make it in to the module? If not, shouldn't it be prepared as a separate module? I like the functionality, but don't like applying patches that are not going to be adopted by the maintainers of the module, because it makes updating a pain. =(
Comment #33
greggles@greg.harvey - what we need is someone to really review the code. A review is not just "works for me" but is a review.
I'm inclined to apply this to the dev branches to let it get more tests/reviews there.
Comment #34
greg.harvey@greggles - Fair enough. I won't be able to look at this as yet, but I've put a task of reviewing this patch in to our "Maintenance" backlog of work to do here. We could definitely do with this feature (specifically to use in conjunction with Pathauto for automated user profile aliases), but it's company policy not to apply patches that aren't going to be a part of a point release, so happy to help with the process if someone doesn't beat us to it. =)
Btw, it's not clear - should this be for D6? Version is set to D5, but latest patch seems to be for D6. I won't change it, as I could confuse things!
Comment #35
recidive CreditAttribution: recidive commented@greg.harvey: patch in comment #24 is for version 5 and the one in #25 is for version 6.
Comment #36
aschiwi CreditAttribution: aschiwi commentedCould this work to give me profile fields as tokens in auto nodetitle module? It's weird, I applied the patch but no new tokens in replacement patterns of auto nodetitle. I thought those tokens in there came from token module?
Comment #37
malukalu CreditAttribution: malukalu commentedtoken_profile.inc referenced in this patch doesnt exist in the token 6 module...
Comment #38
maria_zk CreditAttribution: maria_zk commentedAfter installing the patch: (d5)
any ideas why the $mytext = token_replace($mytext,$type = 'user', $object = NULL, $leading = '[', $trailing = ']'); successfully replaces the [user] token, but returns empty if the token is [profile_name]??
I can see the new tokens from the profile module under the user object.
Comment #39
MGN CreditAttribution: MGN commentedI found a few problems with the D6 patch in #25 while trying to benchmark it.
First, there was a bug with profile date fields that was caused by unserializing the field after the profile module had already unserialized it. For url fields, the patch in #25 produces a token that has the text of the url, but no link. And for textarea fields, the newlines are stripped by check_plain, resulting in a single line textfield returned by the token.
The attached patch fixes these problems.
I repeated the benchmarking that deviantintegral described in #19 for this new patch using the latest dev code. I modified the process slightly, adding a total of 11 profile fields, 5 textfields and one of each of the other fields (date, url, textarea, checkbox, freeform list, and list selection). I then modified the code in #19 for D6 and extended it to randomly populate all of these profile fields for each of the 2000 users in the database. I used a similar testpage for the benchmark that does a token_replace on the 11 profile fields.
The benchmark results before and after the updated token_profile patch are attached. There is a slight increase in the request time (323 +/- 7.8 ms with the patch, compared to 307 +/- 9.3 ms without) that is just at the edge of being significant. Note that like deviantintegral, I could not see a difference in performance with token replace on 5 text profile fields. It took the more stressful test (probably the date field) to see a difference.
I still think this would be a very useful addition. It would be great if we could get this into the dev version. I am willing to do additional testing as needed.
Comment #40
prdsp CreditAttribution: prdsp commentedThis patch worked flawlessly for me. I was able to get the core profile fields to show up in the replacement patterns for user path settings in pathauto which is a great help. Is there any chance this will be committed soon?
Comment #41
tdombos CreditAttribution: tdombos commentedThe patch works like a charm, however, the profile fields are not available upon user registration, only on updating user profiel. I wanted to send out email with user details upon registration, but that does not work with this. Any ideas how to fix it?
Comment #42
Deciphered CreditAttribution: Deciphered commentedTested the patch at #39 (D6) and found an issue, possibly the same issue as #41.
In my case, integration with Token and Mentions, the User Object didn't have the profile fields.
To fix the issue, you simply need to add the following line after line #30 of token_profile.inc:
Other than that, patch looks good and would be a great addition to Token.
Cheers,
Deciphered.
Comment #43
BenK CreditAttribution: BenK commented+1 for this feature.
Comment #44
MGN CreditAttribution: MGN commentedI would be happy to re-roll another patch, but would like to know if the maintainers would be interested in committing this or not (once its marked RTBC, of course). If the maintainers don't intend to commit the code, there is no point in updating it.
I ask because the patch in #39 involves a small addition to token.module - though it completely parallels support for other core modules (like node, user, taxonomy and comment).
Some guidance would be appreciated.
Comment #45
gregglesNow that token is in core for 7.x (and includes this feature) I don't think we should include this in 6.x.
If anything we should just backport the token code from 7.x to 6.x and provide this feature that way.
Comment #46
JStarcher CreditAttribution: JStarcher commented6.x patch in #39 worked, but I needed the tokens to be available to Pathauto node titles. I created a custom module as so to solve the problem:
I am quite certain just adding "node" to the original patch would work as well, haven't tested this much yet but it appears to work great.
Thanks.
Comment #47
marcushenningsen CreditAttribution: marcushenningsen commentedThanks everybody for sharing your features.
I took the patch from MGN in #39 and added the suggestion from Deciphered in #42 and included the node token support as suggested by JStarcher in #46.
I just edited the patch from #39, and didn't actually create a new one (because I don't know how to make the patch make a new file). I tested the patch and it works for me.
Changing the issue to version 6.x and to 'needs review'. I would also appreciate this functionality in the module, whether that be by commiting this patch or by backporting. What's the status on this?
Marcus
Comment #48
marieconbgdlr CreditAttribution: marieconbgdlr commentedHi there,
I'm using drupal 6. After applying the patch mentioned above i got an "Array" when using the profile token with the invite module.
Can anyone help me to fix this problem?
Thanks in advance!
Comment #49
orb CreditAttribution: orb commentedadd suport checkboxes filed
Comment #50
glen201 CreditAttribution: glen201 commented@orb your patch file above can't be downloaded -- maybe its the strange filename -- please simplify the name and re-upload
-- glen
Comment #51
glen201 CreditAttribution: glen201 commentedJust confirmed a problem with this .inc for token: the cache has to be cleared whenever a node containing profile tokens is updated. I am using this patch with Mention, and the replacement [@username] to [profile_fname] results in the token appearing in the clear as text ([fieldname] instead of the profile data) in the node until the Drupal cache is cleared on admin/settings/performance
EDIT: Note that changes to the page in general seem to "clear" the cache of profile fields but Drupal is not re-acquiring them when the page is rendered the first time after it's saved.
Thoughts?
--glen
Comment #52
Coupon Code Swap CreditAttribution: Coupon Code Swap commentedSubscribing
Comment #53
glen201 CreditAttribution: glen201 commentedI created this cross-post http://drupal.org/node/531648#comment-2392346 in Mentions, in case it's a problem with the mentions module. Note the strange behavior I found was related to the input filter cache not being cleared. I handled it in mentions.module with a FIX.
-- glen
Comment #54
aidanlis CreditAttribution: aidanlis commentedWhat's going on with this patch? Could not the profile data be provided via hook_token_values in a submodule?
Comment #55
aidanlis CreditAttribution: aidanlis commentedAnyone interested in adding this support through a module (because they don't want to edit contrib modules) can use this:
Comment #56
jferjan CreditAttribution: jferjan commentedsubscribing
Comment #57
Alex Andrascu CreditAttribution: Alex Andrascu commentedsubscribing
Comment #58
robby.smith CreditAttribution: robby.smith commented+1 subscribing
Comment #59
gjmokcb CreditAttribution: gjmokcb commentedI don't mean to be impertinent, but after fooling with this fix and others for a while, I concluded that it's much easier and more effective to simply use the Content Profile module instead of Profile. With Content Profile, you can create all the custom CCK fields you wish, and they will be instantly available as tokens in myriad variations. Content profile integrates nicely with the user account, with creation of user accounts, and with the Rules module. Sweet.
Comment #60
Deciphered CreditAttribution: Deciphered commented@gjmokcb
While that's fantastic for you, it has absolutely nothing to do with the topic at hand. If you where to mention that there was Token support in Content profile maybe it would have been of some benefit to the users patiently awaiting this capability, but you did not mention anything of the like.
Comment #61
robby.smith CreditAttribution: robby.smith commentedI use Content Profile but I also use Profile and have been following the updates to this issue queue.
Content Profile is great and all but I agree with Deciphered on how this issue is about the importance of token support for Profile.
Comment #62
Dave ReidProfile is still in core for D7, so we should start supporting it there, and backport if necessary. And feature requests are never critical. :)
Comment #63
mattiasj CreditAttribution: mattiasj commentedProfile tokens would be very useful, for example on community sites that hold several content profiles its great to be able to use one single profile field for example name and for me, to be able to use that as a token would be great.
Comment #64
Anonymous (not verified) CreditAttribution: Anonymous commentedAnyone able to point a non-programming person who is able to apply ready-made patches and create modules from ready-made code in the right direction?
I am trying to use the Rules module to notify an admin team about requests for accounts and it is important that they are able to see the account-creator's username and email plus all the profile information. I have created and installed the module described at #55 (thank you aidanlis) but the profile tokens are still not available in Rules. I'm guessing that either I should have amended the code in #55 for my specific circumstances or that I have overlooked (ignorance plays a big part here) something else.
As an aside, to try and get round this I followed gjmokcb's suggestion (#59) and installed the Content Profile module. However, I have been unable to find a way to use [account:user] to show the new account username at the same time as showing all the Content Profile CCK fields.
Many thanks (in anticipation)!
Comment #65
fizk CreditAttribution: fizk commentedI've attached a new module that exposes uprofile tokens from the advanced profile kit.
Example usage:
The code looks like this:
Comment #66
fizk CreditAttribution: fizk commentedThe only thing I'm not happy with is
content_fields(NULL, 'uprofile');
doesn't limit to 'uprofile' content type like it should.I added an extra check to make sure the field is of type 'uprofile'.
Comment #67
gjmokcb CreditAttribution: gjmokcb commented@Deciphered
Golly, thanks for your helpful response. You are so generous! It's people like you that make this a true community!
Comment #68
amariotti CreditAttribution: amariotti commentedSubscribing
Comment #69
geerlingguy CreditAttribution: geerlingguy commentedSubscribe.
Comment #70
rsevero CreditAttribution: rsevero commentedHere is the Profile Tokens 6 module with the sole purpose of enabling Profile Tokens in Drupal 6 as Drupal 7 already has it as far as I understood.
It's based heavily on code presented here, mainly by marcushenningsen at #125640-47: Profile tokens.
I hope it solves a few immediate problems to others as it's solving for me.
Comment #71
fizk CreditAttribution: fizk commentedrsevero, I could create a Drupal project page for #70 if you're interested.
Comment #72
Dave ReidI'd be more than happy to help get this into token.module for D6 and D7, considering profile is a core module. But a few things:
1. This needs to be a proper patch so it can be run against our test bot
2. This needs SimpleTests for *any* new tokens, which would be all the profile tokens (see #1)
:)
Comment #73
rsevero CreditAttribution: rsevero commentedFirst of all I would like to thank both fizk and Dave Reid for their prompt answers.
I believe fizk idea is much more doable as:
Does anybody has ideas on how to deal with point 2 above?
Comment #74
fizk CreditAttribution: fizk commentedI've added your code to the token_profile module: http://drupal.org/node/783272, http://drupal.org/project/token_profile
Comment #75
Dave Reid:(
Comment #76
fizk CreditAttribution: fizk commentedSorry Dave, I should've added, when the patch is committed to token.module, I'll deprecate the token_profile version.
Comment #77
Dave ReidHere's the initial patch for Drupal 7. Let it be known I really hate profile module. I will be super glad when it's been completely deprecated with fields in D8.
Still needs work on some token formats and tests.
Comment #78
rsevero CreditAttribution: rsevero commented@ fizk
I think your idea of including the code I provided in the already existent Token Profile module is great but unfortunately the http://drupal.org/project/token_profile page doesn't show the 6.x version. Is there an expected delay?
The first link you provided (http://drupal.org/node/783272) returns an "Access denied" message to me so I don't know what it's about.
@Dave Reid
Do you think tests on profile field types are an appropriate solution?
About the lack of SimpleTests on the Token module: I was looking on the last released version. Now that I looked on the last dev version I can see there are many tests to learn from.
Comment #79
rsevero CreditAttribution: rsevero commented@Dave
Sorry for messing the the Status and Assigned fields. I believe my browser used a cached version of them.
I managed to fix the Status field but can't change the Assigned.
Comment #80
fizk CreditAttribution: fizk commentedrsevero, the dev snapshot is only created twice a day, so it should be available sometime tomorrow.
Comment #81
gregglesFor the record, Dave rocks.
Comment #82
geerlingguy CreditAttribution: geerlingguy commentedJust FYI, #70 is working perfectly for me on Drupal 6.16/latest Token. Thanks for this (hopefully temporary) solution!
Comment #83
troynt CreditAttribution: troynt commented#39: 125640_token_profile_D6_v2.patch queued for re-testing.
Comment #84
gg4 CreditAttribution: gg4 commented+1
Comment #85
zeezhao CreditAttribution: zeezhao commentedsubscribing.
Tried out both. Looks good. #74 also has a patch for node author.
Comment #86
robby.smith CreditAttribution: robby.smith commented+1 for this feature add intp D7 and D6
Regards
Comment #87
rkdesantos CreditAttribution: rkdesantos commentedsubscribing
Comment #88
Danic CreditAttribution: Danic commentedAny news for this as it does not seem to be in the nightly builds?
Comment #89
Dave ReidIt's not yet included, but I've been working on it today. However, I've discovered a blocker that we need to fix in core: #967330: The [current-user:?] token should provide the actual loaded user
Comment #91
Dave ReidFinally got a good chance to polish this up for D7.
Comment #92
Dave ReidAnd we got the green light from the testbot!
Committed #91 to Token 7.x-1.x!
http://drupal.org/cvs?commit=450438
Comment #93
BenK CreditAttribution: BenK commented@Dave Reid: Nice work. Quick question: To get profile tokens to work, does it still require manually applying the http://drupal.org/node/967330 D7 core patch?
Thanks,
Ben
Comment #94
Dave Reid@BenK: No I committed a fix to work around it in the meantime.
Comment #95
YK85 CreditAttribution: YK85 commentedSubscribing - coming from #345253: Drupal 6 stable release
Comment #96
ilo CreditAttribution: ilo commentedany plan for the backport? tokens will get updated to the D7 format (meaning [current:~])? or will be using current D6 format (meaning [user-~]?
Comment #97
Dave ReidAdding new release blocker tag.
Comment #98
Gabriel R. CreditAttribution: Gabriel R. commentedSubscribe
(Sorry)
Comment #99
killua99 CreditAttribution: killua99 commentednothing new yet?
Comment #100
killua99 CreditAttribution: killua99 commentedI just copy a paste the token_profile module into token for D6 branch. Yup I didn't know how to create the simpletest "test"
Comment #102
fizk CreditAttribution: fizk commentedkillua99, if you scroll up to #74 you'll see that the Token Profile D6 module was created using code from this issue:
http://drupal.org/node/125640#comment-2897586
Comment #103
killua99 CreditAttribution: killua99 commentedA second try with SimpleTest. If this not pass I'll try one last chance ... if not pass w/e ... the initial code works ...
Comment #104
fizk CreditAttribution: fizk commentedSee my previous comment.
Comment #105
killua99 CreditAttribution: killua99 commented@fizk: and you put "The Drupal 6 version will be removed once the issue in http://drupal.org/node/125640#comment-2897612 has been resolved." ... Well I don't want to add another module for this feature. Just sorry if I understand in another way. That was my last submit patch.
Comment #106
fizk CreditAttribution: fizk commentedkillua99, That's right, but the code that you copy/pasted into this issue is already in this issue. Why do we need the same code to be here twice?
Comment #107
killua99 CreditAttribution: killua99 commented@fizk: because is not a patch for token. Is another module. I know is idiot duplicated twice the code. I read the comment #70, #71, #72, #73, #74, #75, ... that code was supposed to be in token.module and not in token_profile.module.
Well I guess I'm late to patch that code into token.module... I'll use that code into token.module and not in token_profile.module.
and sorry for duplicated twice the code.
PS: that code was previously duplicated twice, in this thread and in another module (token_profile).