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.
API page: http://api.drupal.org/api/drupal/modules--field--field.module/group/field/7
Describe the problem you have found:
Comments
Comment #1
SilviaT CreditAttribution: SilviaT commentedHow to define the default_value_function for a field? The documentation doesn't explain it.
More details for my issue: http://drupal.org/node/1054702
(Also, there's a problem with the preview when you report an issue: if you preview your message before posting it, the message itself is not included in the form after the preview, so that if you don't check and just save your post, your text is not published. In this post I report the text for my issue in the comment in fact.)
Comment #2
jhodgdonAgreed, the default value function needs more information, like what the arguments and return value should be. Maybe there are other functions in that section that need expansion as well?
Regarding your problem with filing the issue, I can confirm that it is a problem, and I've filed a separate issue about it:
#1112110: Preview resets information entered, if issue filing URL has query strings
Thanks for reporting both of these issues!
Comment #3
hefox CreditAttribution: hefox commentedSubscribe; trying to find out information about this functionality at the moment.
Comment #4
fizk CreditAttribution: fizk commentedbump
Comment #5
jhodgdonfizk: thanks for your interest. Someone needs to figure out how to document this, and write the documentation... and at this point, it needs to be a Drupal 8 patch first... bumping probably won't help, but if you would like to take a stab at writing a patch, that would help. :)
Comment #6
fizk CreditAttribution: fizk commentedThanks for the tip Jennifer.
Here's something to start with:
If you want to set the default value using the default value function, use something like this:
Comment #7
fizk CreditAttribution: fizk commentedI think there's a bug in the field module. See #1342984: Field API: Default value function not called
Comment #8
jhodgdonPlease file that as a separate issue in the field module component.
Comment #17
quietone CreditAttribution: quietone as a volunteer commentedI think this is fixed for Drupal 9.3.x
See
protected property FieldConfigBase::$default_value
protected property FieldConfigBase::$default_value_callback
but is still valid for Drupal7.
Changing version.