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.
Problem/Motivation
form_type_textarea_value() behaves differently than form_type_textfield_value(), it does not ignore input that is set to NULL instead of FALSE. Example: if you have a body field on a node with a textarea element and you set the #type to 'hidden' on the outer field form element, then _form_builder_handle_input_element() will invoke the value_callback form_type_textarea_value() with input set to NULL.
Proposed resolution
Make form_type_textarea_value() behave the same as form_type_textfield_value() and ignore NULL input.
Remaining tasks
Review patch, write tests
User interface changes
none.
API changes
none.
Comment | File | Size | Author |
---|---|---|---|
#33 | interdiff.txt | 1.29 KB | David_Rothstein |
#33 | form-textarea-value-2502263-33.patch | 1.73 KB | David_Rothstein |
#33 | form-textarea-value-2502263-33-tests-only.patch | 1.15 KB | David_Rothstein |
#31 | form-textarea-value-only_test-2502263-31.patch | 1.24 KB | hgoto |
#31 | form-textarea-value-2502263-31.patch | 1.82 KB | hgoto |
Comments
Comment #1
klausiPatch attached.
Comment #2
klausiDrupal 7.36 actually.
Comment #3
Rajab Natshah CreditAttribution: Rajab Natshah at Vardot commentedTesting too :)
Not sure. If we are going to have this in 7.38 .
we had this from #2380053
Comment #4
ckngPatch #1 is working for bugs seen in Invite module, where the Invite type entity body field is missing when it is hidden.
Comment #5
cilefen CreditAttribution: cilefen commented@ckng Can you please review it so it can be committed?
Comment #6
ckngPatch #1 is reviewed and working as described.
Comment #7
klausiCool, so the next steps is to write tests for this.
Comment #8
pwolanin CreditAttribution: pwolanin as a volunteer and at Acquia commentedI'm not sure I understand the bug - the problem is that NULL input is cast to empty string which is set?
Comment #9
ckngThe issue is the input is not null, has actual default value, just hidden. So the function returns empty when it should be the default value of the hidden control.
Comment #10
n_vashenko CreditAttribution: n_vashenko commentedHi, i'm getting the same bug. Solution in #2 works well
Comment #11
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedLet's see if a test was added when this was fixed in Drupal 8. If so, we can backport that. If not, I'm tempted to say we should just commit this to Drupal 7 also (since it fixes a regression) and then have a followup issue to write tests for both Drupal 7 and Drupal 8.
Comment #14
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedOK, the answer is that Drupal 8 does test this - Drupal\Tests\Core\Render\Element\TextareaTest.
Looks like a unit test only which for an issue like this is not quite as useful (by itself) compared to actually testing an actual practical effect, but it's better than nothing and I think backporting that would be good enough.
Comment #15
deanflory CreditAttribution: deanflory as a volunteer commentedPatch "form-textarea-value-2502263-1.patch" (#1) when applied to D7.42 deletes includes/form.inc entirely.
Comment #16
maximpodorov CreditAttribution: maximpodorov commented@deanflory, the patch is correct. You make something wrong.
Comment #17
deanflory CreditAttribution: deanflory as a volunteer commentedThanks maximpodorov, I think you're right since it happened to another patched file the other day as well. New Mac OS El Capitan. Not liking it. Haven't tried this again though.
Comment #18
Anonymous (not verified) CreditAttribution: Anonymous commentedThe patch from #1 works for me with the latest Drupal. RTBC.
Comment #19
klausiTests are missing.
Comment #20
hgoto CreditAttribution: hgoto as a volunteer commentedFollowing David_Rothstein's guide, I wrote a test for the patch #1 with unit test.
To confirm that the test works well, I'd like to upload patches with and without code fix.
Comment #23
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedI queued these for retesting; the testbot seems to be having a bad day.
Comment #28
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedOh wait, the failure is real. Clicking through to the test results at https://dispatcher.drupalci.org/job/default/163462/console the patch has a syntax error:
Comment #29
hgoto CreditAttribution: hgoto as a volunteer commented@David_Rothstein, thank you for your reaction. I see... To check it, I created a new Drupal instance with the latest 7.x branch and applied the patch #20. What is strange is I can see the tests works without syntax error after applying the patch... Could anyone test the patch with simpletest? Or should I requeue the auto test again?
Perhaps, I may be wrong. I tested them with both admin UI and the following command:
Is something wrong?
Comment #30
klausiI think list() in foreach does not work in older PHP versions.
Comment #31
hgoto CreditAttribution: hgoto as a volunteer commented@klausi, thank you very much. You are right. I didn't notice the point... I've fixed that point and will try again!
Comment #33
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThe patch looks good, but we normally don't use
$var
- also that makes the variable public, but there's no need for a public variable here (protected
would be better).And in this case it's probably better just to define the variable locally inside the test method (if another method is ever added later, it wouldn't be likely to need access to this particular variable too).
I fixed that in the attached and also cleaned up the variable names a bit. I'm going to mark this RTBC pending the tests passing/failing as expected (though I will let someone else do a final review and commit it) since my changes are minor and it would be really nice to get this in and the regression fixed in the upcoming release.
Comment #34
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedComment #37
stefan.r CreditAttribution: stefan.r commentedLooks OK to me
Comment #38
hgoto CreditAttribution: hgoto as a volunteer commentedThanks, @David_Rothstein. I see! I totally agree with you.
Comment #40
Fabianx CreditAttribution: Fabianx as a volunteer and at Tag1 Consulting commentedCommitted and pushed to 7.x! Thanks!