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.
From sun in #375907-32: Make text field use D7 '#text_format' selector :
- #value_callback is a yet-undocumented FAPI feature (I guess this is about http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/7 ?)
- The signature of core's existing implementations is :
function form_type_checkbox_value($form, $edit = FALSE) {
while the $form should actually be $element.
Comment | File | Size | Author |
---|---|---|---|
#17 | 447930_value_callback_docs.patch | 2.14 KB | Mile23 |
#17 | 447930_value_callback_docs_d7.patch | 2.14 KB | Mile23 |
#16 | 447930-value_callback_documentation.patch | 1.28 KB | franz |
#6 | value_callback_documentation-447930.patch | 1.45 KB | cfennell |
Comments
Comment #1
sunsubscribing and tagging
Comment #2
JamesAn CreditAttribution: JamesAn commentedWith respect to the signature of form_type_checkbox_value(), should we also consider renaming $form to $element for all these similar functions:
form_type_checkboxes_value(),
form_type_image_button_value(),
form_type_password_confirm_value(),
form_type_select_value(),
form_type_textfield_value(), and
form_type_token_value?
Reading the code that processes the FAPI feature, #value_callback, I just want to clarify my understanding of it. #value_callback is:
* not used if #value is set (they should not both be set simultaneously for any form element.),
* called and #value is set to its return value, and
* used by all special elements that use #value (button, hidden, image_button, submit, and value).
Both these fixes need to be done for D6 and 7, right?
Unfortunately, there are no examples in core to showcase the use of #value_callback.
Comment #4
sunTagging for feature freeze.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedOh hey there undocumented Form API property #value_callback which I need very much to use. Looks like I will be documenting this before I can justify getting around to using it.
Comment #6
cfennell CreditAttribution: cfennell commentedA stab at documenting the callback and a fix for another small documentation error ("@param $form" becomes "@param $element").
Comment #7
Dries CreditAttribution: Dries commentedThe documentation should explain _why_ and _when_ this should be used. It lacks context right now. Thanks! :)
Comment #8
ldweeks CreditAttribution: ldweeks commentedI found '#value_callback' in looking through the D6 version of CCK, and I assume that it appears here because fields are now in core. I am trying to figure out the answers to "why" and "when" (as Dries put it), and came across this information:
That snippet is from the d6 example form section of the drupal handbook: Creating Custom Elements Using Drupal 6.x , under "Value callback or form_type_hook_value()".
I don't know if that information is correct - someone more knowledgable needs to vouch for it - but if it is, perhaps we can re-use some of that documentation in the D7 docs.
Comment #9
Dave Kopecek>> Unfortunately, there are no examples in core to showcase the use of #value_callback.
For future searchers: #value_callback is used in D6 nodereference.module
read nodereference.module code alongside: http://drupal.org/node/169815 ( Creating Custom Elements Using Drupal 6.x ) per #8.
Comment #10
chx CreditAttribution: chx commentedDries' question cries for a FAPI expert not a novice...
Comment #11
howto CreditAttribution: howto commented#6: value_callback_documentation-447930.patch queued for re-testing.
Comment #13
franz#6: value_callback_documentation-447930.patch queued for re-testing.
Comment #14
franzComment #16
franzre-rolled
Comment #17
Mile23API docs still missing from http://api.drupal.org/api/drupal/modules--system--system.api.php/functio... and the D7 version as well.
Assuming the content is correct, here it is.
Comment #18
chx CreditAttribution: chx commentedThanks for working on the patch! However, by now the doxygen of form_builder seems to mention
#value_callback
. That documentation however needs a signature. So this patch says "+ * Such callbacks are passed three values: $element, $input, and $form_state" which is correct but it needs to explain that $input will be FALSE when the default value needs such mapping. Also needs to mention that you need to return the value. Also if you look there then the #process and the #after_build functions also lack signatures and return values. #process gets$element, $form_state, $complete_form
these arguments and needs to return the $element. #after_build gets$element, $form_state
and also needs to return the $element (here the complete form can be found in $form_state['complete_form']).Thanks again.
Comment #19
joachim CreditAttribution: joachim commentedThis should probably be in the docs component, and unassigned now chx has reviewed it.
Comment #20
jhodgdonThere are also some formatting problems at the top of this patch:
- First line: see http://drupal.org/node/1354#functions
- Don't indent stuff in paragraphs randomly. Use @code for code, or a bullet list, or just wrap it within the paragraph (which is what will happen on api.drupal.org for random indents anyway).
- Code fragments probably should not end in ; (such as that first one, which is not an assignment).
- The second-to-last line repeats information that is in the last line unnecessarily.
In the last hunk of the patch:
This should not end in ; and maybe something should be added there about what the function takes as arguments?
Comment #21
johnvITMT this is already fixed in D8 in FormBuilderInterface.php:
I I guess this won't make it into D7. It's already on the Form API documentation, and all efforts are in D8.
Also, there's better info on the net, see:
https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.h...
http://drupal.stackexchange.com/questions/125386/how-does-value-callback...
(I wish I found this property earlier - years ago. )
Comment #22
jhodgdonActually, since this is a documentation issue, there is no reason we cannot fix it in Drupal 7. We just need a viable patch.
Comment #23
johnvLet's set the version accordingly. Is missing documentation a bug?
Comment #24
jhodgdonYes, missing or incorrect documentation is a bug. Thanks!