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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

klausi’s picture

Issue summary: View changes
Status: Active » Needs review
FileSize
596 bytes

Patch attached.

klausi’s picture

Title: Drupal 7.35 regression: hidden field textarea #default_value is ignored » Drupal 7.36 regression: hidden field textarea #default_value is ignored

Drupal 7.36 actually.

Rajab Natshah’s picture

Testing too :)
Not sure. If we are going to have this in 7.38 .
we had this from #2380053

ckng’s picture

Patch #1 is working for bugs seen in Invite module, where the Invite type entity body field is missing when it is hidden.

cilefen’s picture

@ckng Can you please review it so it can be committed?

ckng’s picture

Status: Needs review » Reviewed & tested by the community

Patch #1 is reviewed and working as described.

klausi’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Cool, so the next steps is to write tests for this.

pwolanin’s picture

I'm not sure I understand the bug - the problem is that NULL input is cast to empty string which is set?

ckng’s picture

The 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.

n_vashenko’s picture

Hi, i'm getting the same bug. Solution in #2 works well

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Needs work » Needs review
FileSize
687 bytes

Let'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.

Status: Needs review » Needs work

The last submitted patch, 11: 2502263-D8-revert-11.patch, failed testing.

The last submitted patch, 11: 2502263-D8-revert-11.patch, failed testing.

David_Rothstein’s picture

Version: 8.0.x-dev » 7.x-dev

OK, 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.

deanflory’s picture

Patch "form-textarea-value-2502263-1.patch" (#1) when applied to D7.42 deletes includes/form.inc entirely.

maximpodorov’s picture

Status: Needs work » Needs review

@deanflory, the patch is correct. You make something wrong.

deanflory’s picture

Thanks 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.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

The patch from #1 works for me with the latest Drupal. RTBC.

klausi’s picture

Status: Reviewed & tested by the community » Needs work

Tests are missing.

hgoto’s picture

Following 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.

The last submitted patch, 20: form-textarea-value-2502263-20.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 20: form-textarea-value-only_test-2502263-20.patch, failed testing.

David_Rothstein’s picture

Status: Needs work » Needs review

I queued these for retesting; the testbot seems to be having a bad day.

The last submitted patch, 20: form-textarea-value-2502263-20.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 20: form-textarea-value-only_test-2502263-20.patch, failed testing.

The last submitted patch, 20: form-textarea-value-2502263-20.patch, failed testing.

The last submitted patch, 20: form-textarea-value-only_test-2502263-20.patch, failed testing.

David_Rothstein’s picture

Oh 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:

17:06:33 PHP Parse error:  syntax error, unexpected T_LIST in /var/www/html/modules/simpletest/tests/form.test on line 2133
17:06:33 PHP Stack trace:
17:06:33 PHP   1. {main}() /var/www/html/scripts/run-tests.sh:0
17:06:33 PHP   2. simpletest_test_get_all() /var/www/html/scripts/run-tests.sh:50
17:06:33 PHP   3. class_exists() /var/www/html/modules/simpletest/simpletest.module:371
17:06:33 PHP   4. drupal_autoload_class() /var/www/html/modules/simpletest/simpletest.module:371
17:06:33 PHP   5. _registry_check_code() /var/www/html/includes/bootstrap.inc:3120
17:06:34 HTTP/1.1 200 OK
hgoto’s picture

Status: Needs work » Needs review

@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:

php ./scripts/run-tests.sh --class FormTextareaTestCase

Is something wrong?

klausi’s picture

Status: Needs review » Needs work

I think list() in foreach does not work in older PHP versions.

hgoto’s picture

@klausi, thank you very much. You are right. I didn't notice the point... I've fixed that point and will try again!

Status: Needs review » Needs work

The last submitted patch, 31: form-textarea-value-only_test-2502263-31.patch, failed testing.

David_Rothstein’s picture

The 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.

David_Rothstein’s picture

Issue tags: -7.50 target +Drupal 7.50 target

The last submitted patch, 33: form-textarea-value-2502263-33-tests-only.patch, failed testing.

The last submitted patch, 33: form-textarea-value-2502263-33-tests-only.patch, failed testing.

stefan.r’s picture

Issue tags: -Needs tests +Pending Drupal 7 commit

Looks OK to me

hgoto’s picture

Thanks, @David_Rothstein. I see! I totally agree with you.

  • Fabianx committed b042085 on 7.x
    Issue #2502263 by hgoto, David_Rothstein, klausi, ckng, rhclayto: Drupal...
Fabianx’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Committed and pushed to 7.x! Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.