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.
If possible with the new Field API, it would be helpful to be able to use tokens in the default values for fields. This was requested by Bevan in the comments on another issue (http://drupal.org/node/691078#comment-3813316), but I couldn't find where a separate issue was ever opened for it.
For Drupal 7, see http://drupal.org/project/field_default_token.
For Drupal 9/10 Entity Prepopulate can be used, see Entity Prepopulate examples.
Comment | File | Size | Author |
---|---|---|---|
#24 | token-support-default-field-settings-1070878-24.patch | 667 bytes | Pascoual |
#20 | token-support-default-field-settings-1070878-20.patch | 599 bytes | Pascoual |
#8 | tokens_as_default.zip | 2.41 KB | kmh |
Comments
Comment #1
Dave ReidI thought I had looked into it before and found it almost impossible to be able to do this on a consistent basis. I'll take a look again.
Comment #2
Dave ReidAlso considering CCK in D6 didn't support tokens in it's provided fields (text, etc) this isn't too high a priority.
Comment #3
jide CreditAttribution: jide commentedSubscribe
Comment #4
manoloka CreditAttribution: manoloka commentedsubscribe
Comment #5
Wario CreditAttribution: Wario commentedsubscribe
Comment #6
Dave ReidComment #7
clashar CreditAttribution: clashar commented+1 came from #1248306: Use of Tokens in CCK Field Help Text in D7
Comment #8
kmh CreditAttribution: kmh commentedHi guys, I wrote a small module for supporting tokens in default values of fields. Its quite a bruteforce solution - its checking all "*_node_form" forms and alters the content by replacing all occurances of tokens by their specific values using token_replace(), but maybe it will be usefull anyways.
Its actually my first post here on drupal.org so if I did something wrong by posting here a minimodule I am sorry for that!
Comment #9
amonteroHi, guys.
For the help text part, you might be interested in #1308564: Basic token support in fields' help texts.
It is a trivial patch (take a look yourself) and it works for me, but more peer reviewing is definitely needed.
Maybe it gets into core if there is enough peer review.
HTH.
Comment #10
grasmash CreditAttribution: grasmash commentedamontero, I revised your patch a bit. check issue #1308564: Basic token support in fields' help texts (patch provided)
If you're interested in this feature, please support the issue!
Comment #11
amfriedman CreditAttribution: amfriedman commentedSubscribe
Comment #12
magpie5212 CreditAttribution: magpie5212 commentedSubscribe
Comment #13
krisrobinson CreditAttribution: krisrobinson commentedSubscribing
Comment #14
deggertsen CreditAttribution: deggertsen commentedCan we move this issue to active? This seems like a perfectly valid feature request and it's not like it's being postponed based on any other pending issues right?
@khm I have not tested your module, but it would obviously be better if we could integrate your work into a patch somehow for this module as that would be more easily tested and helpful.
Comment #15
rogical CreditAttribution: rogical commentedQuite agree!
See default value with token replacements, it has been solved in D6.
Currently, only viewfield supports this:
Comment #16
amonteroAs mentioned above, there is an ongoing issue for #1308564: Basic token support in fields' help texts. madmatter23 added there a patch to support them in default values that might be of interest here.
As described in this comment I've split token support in help text and default values in different issues to ease them.
Token support for help text patch passed tests successfully. You might be interested in reviewing it, also.
Issue linked and title updated.
Comment #17
fpedraza CreditAttribution: fpedraza commentedsubscribing
Comment #18
andreic CreditAttribution: andreic commentedsubscribing
Comment #19
Sk8erPeter CreditAttribution: Sk8erPeter commentedI'm begging all the "subscribers" to finally realize that BIG GREEN "Follow" BUTTON, and PLEASE read this:
Stop subscribing, start following
The "Follow" buttons look like this at the top of the issues:
You can also unsubscribe with hovering over the "Following" button, when "Unfollow" appears:
It's really annoying to see a new post on the dashboard, and clicking on it interestedly , and after that, seeing another unnecessary "subscribing" text...
Thanks!
Comment #20
Pascoual CreditAttribution: Pascoual commentedInspired from madmatter23 patch, I've just made a patch to allow uses of token in default value of fields.
Test it.
Comment #21
amonteroSetting status to NR in order to let the tests run.
Comment #22
drupalycious CreditAttribution: drupalycious commentedI tested the patch and it seems some part is failing:
Comment #23
amontero@sp-drupy: Patch applies cleanly against latest 7.x-dev for me. Which version are you applying the patch to?
Comment #24
Pascoual CreditAttribution: Pascoual commentedI've also add the clear option : a boolean flag indicating that tokens should be removed from the final text if no replacement value can be generated.
l.498 :
$items[$key][$innerKey] = token_replace($innerValue, array(), array('clear'=>true));
Comment #25
amonteroPatch failed to apply.
Comment #26
pokurek CreditAttribution: pokurek commentedPatch #24 works well. But if the field needs value validation, it is not being saved. LIke email field, numeric ...
There is another problem with value max length. If I have a ZIP field with for example 6 characters max, so the token is not inserted into the field when token is longer than 6 characters.
And what about select options?
This could be used only for clear text longer than token.
Comment #27
pokurek CreditAttribution: pokurek commentedSorry, for assign. :( My fault.
Comment #28
GiorgosKIt does not work for custom entity fields only for core drupal entities
Comment #29
_vid CreditAttribution: _vid commentedThanks @Pascoual and @madmatter23;
Patch in #20 worked great for me in a fresh D7.19.
I won't change the status because of potential changes to the patch in #24, but I'm excited to have token defaults available.
Comment #30
sebto CreditAttribution: sebto commentedThanks. I used this patch. It works for me.
Comment #31
balatin CreditAttribution: balatin commentedGreat module! Patch in #20 worked.
Comment #32
szantog CreditAttribution: szantog commentedTemporary (and ugly a bit) workaround:
I didn't check the patch, but are you sure, the tokens aren't replaced on field settings form? (admin/structure/types/manage/[type]/fields/[field_name]
I think, also needs test. And are we sure, the token replacement should be run automatically on every fields? Maybe a checkbox in field settings form to turn it on/off?
And how is this feature in drupal 8? Is the d7 the proper version to work on?
Comment #33
cuman CreditAttribution: cuman commented#24
It works for me. Thanks!
Comment #34
_vid CreditAttribution: _vid commentedI got an error when I did a --stat on the patch in 24.
Maybe it's just missing the blank line at the end of the file.
Comment #35
maximpodorov CreditAttribution: maximpodorov commentedThe new module http://drupal.org/project/field_default_token can be used as a solution. It's based on #32 and supports even entityreference fields.
Comment #36
amontero@maximpodorov: Thanks! Updated summary to add your link.
Since this issue is filed against Drupal Core and we're past feature freeze with no 8.x working code, let's push it to 9.x .
Comment #37
maximpodorov CreditAttribution: maximpodorov commented@amontero: Unfortunately, my module does not address all issues yet. I expect to release new version soon.
Comment #38
maximpodorov CreditAttribution: maximpodorov commentedCurrent version of https://drupal.org/project/field_default_token is quite good, IMHO.
Comment #39
katannshaw CreditAttribution: katannshaw commented@maximpodorov: Nice module! Thanks.
Comment #39.0
katannshaw CreditAttribution: katannshaw commentedAdd module link
Comment #40
jetwodru CreditAttribution: jetwodru commentedHopefully included in D8, NOT postponed to D9, often, I found Views very flexible with rewrite results and token support whereas the core Fields module are pretty useless without token support, hidden field, read-only fields and etc.
Hence, I switched to use Webforms which support some tokens in fields though I'm supposed to do it in Content Types.
Comment #41
jetwodru CreditAttribution: jetwodru commentedThanks, #38 works for both node and Entity Forms, great. Since D6 does support tokens in fields, no reasons that D7 removed this critical support and then postponed to D9. It makes Drupal fields pretty useless and worse than previous versions. This issues was raised in 2011, wondering why it was not taken into D8. Thanks
Comment #42
christofa CreditAttribution: christofa commented20: token-support-default-field-settings-1070878-20.patch queued for re-testing.
Comment #43
drummSorry, automated testing is not yet set up for 9.x.
Comment #44
docans CreditAttribution: docans commentedHi i need to be able to do this in drupal 7 for ubercart attribute options names to use token. Can any one help
Comment #45
Xano@docans: This is the issue queue, where we work on Drupal core. Please ask your questions in the support forums or the #drupal-support channel on IRC.
We can probably still get this into Drupal 8 in a minor version, so moving to the 8.x queue.
Comment #46
alibama CreditAttribution: alibama commentedI'm wondering whether https://www.drupal.org/project/token_embed_views + https://www.drupal.org/project/field_default_token would allow for a dynamic tokenized value in a field... has anyone tested this?
Comment #47
maximpodorov CreditAttribution: maximpodorov commentedWhat is "dynamic tokenized value"?
Comment #48
alibama CreditAttribution: alibama commenteda token value that can be updated- use case: I want a form to be prepopulated with the values from the previous submitted content submission. so the way I would do that is to create a view that shows the most recent submission and inserts those values in the form. those values would be editable, so if someone wanted to update the values they could, and the next time they went to the form after that those new values would be in place.... not sure if this is entirely clear, thanks for following up
Comment #49
maximpodorov CreditAttribution: maximpodorov commentedhttps://www.drupal.org/project/field_default_token works with any tokens which are either global, or based on entity being edited. If you can provide the correct token with your case, it will work.
Comment #50
nithinkolekar CreditAttribution: nithinkolekar commentedanother issue #2022785: Advance this module to an "Automatic field" module, to give automatic pattern/choices for any field is in the race and IMO this feature should be implemented in Auto Entity Label instead of tweaking core. any suggestion?
Comment #51
blogers CreditAttribution: blogers commentedIts amazing this module thanks so much
Comment #53
jonathanshawComment #54
budda#2727679: Email field default value validation prevents use of tokens like [current-user:mail] may be related to this topic too.
Comment #55
grguth CreditAttribution: grguth commentedThis is now even more confusing that a token can be placed in the help text for a field, but not in the default value in 8.1. If either eform or contact form is going to be a replacement for webform, you need a way to move various values, such as user names, email, etc., into a form to populate it with reasonable values to avoid burdening the user with reentering information that the system already has.
Comment #56
maximpodorov CreditAttribution: maximpodorov commentedMaybe it's time to port https://www.drupal.org/project/field_default_token to D8?
Comment #61
Kris77 CreditAttribution: Kris77 commentedI'm tried https://www.drupal.org/project/field_default_token with Drupal 8.5 and same to work.
Official Version of this module for Drupal 8?
Comment #62
imingridm CreditAttribution: imingridm commentedHi guys, I have made a request form and for people who are logged in they do not need to type "name" and "login" in a way that these fields are filled in according to the person who is logged in. I downloaded this module and tried several in defalt value like [user: name] etc ... Does anyone know how I can do this? Thank you in advance
Comment #63
jonathanshawHi ingrid.martins, please don't use existing issues like this that are bug reports or feature requests in order to get support. For that, Drupal Answers on stackexchange is often best.
Comment #64
imingridm CreditAttribution: imingridm commentedFor some days I've been asking for help, if I had known that asking in the wrong place would have a jet response I would have done before;) Sorry
Comment #70
JasonLuttrellHi all, I see this is still Active with the latest version of Drupal 9. I tried the module Field Default Token. It would not install because of an error. I don't recommend it because the module doesn't appear to have good support, it has not been updated in years, and there are a number of open issues. I know it's been a while but it would be great if this could still be addressed. Thanks.
Comment #75
ressa CreditAttribution: ressa at Ardea commentedAdding Entity Prepopulate for Drupal 9/10 in the Issue summary, and default value example.