text_textarea field widget fails config validation by default

Created on 29 July 2024, 4 months ago
Updated 3 August 2024, 4 months ago

Problem/Motivation

If I add a field of type text_long using hook_entity_base_field_info(), and I use the text_textarea field widget, then the value of rows is set to the string '5' by default. The resulting config object core.entity_form_display... fails validation since text.schema.yml declares that rows should be an integer.

Adding a field through the UI does not have this problem. I have not tracked down why.

Steps to reproduce

Implement hook_entity_base_field_info() in a custom module and define a field as in the previous section.

Proposed resolution

In the parent class Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextareaWidget, change the default value for rows from the string '5' to the integer 5.

Remaining tasks

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

N/A

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component
Text 

Last updated 27 days ago

Created by

🇺🇸United States benjifisher Boston area

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @benjifisher
  • 🇺🇸United States benjifisher Boston area

    We could also fix the problem in the text module: either change text.schema.yml or override defaultSettings() in the child class Drupal\text\Plugin\Field\FieldWidget\TextareaWidget.

  • Issue was unassigned.
  • Status changed to Needs work 4 months ago
  • 🇺🇸United States benjifisher Boston area

    The MR has the proposed resolution. This is my entry in the contest for this year's smallest change.

    I will set the status to NW, not NR, because this bug fix still needs a test.

  • Pipeline finished with Success
    4 months ago
    Total: 2169s
    #237831
  • 🇮🇳India prashant.c Dharamshala

    @benjifisher

    I found an existing test for this field type here: StringFieldTest.
    https://api.drupal.org/api/drupal/core%21modules%21field%21tests%21src%2...

    Do you think this test will suffice as is, or do we need to modify it or create an entirely new one? Please advise.

  • 🇺🇸United States benjifisher Boston area

    @Prashant.c:

    Thanks for taking a look at this issue!

    That test class is in the field module, and it does not enable the text module, so I do not think that is the right place for it.

    Also, we need a test that fails without the change I made in the MR. All current tests are passing, so we need to add a new test, once we decide on where to add it.

    I think Drupal\Tests\text\Functional\TextFieldTest is the right place.

    Before doing too much work, check what I said just above "Steps to reproduce": if you add the field from the UI, then you do not run into this problem. If I was right, then you will need to write a test module that implements hook_entity_base_field_info(). I can help with that if you want.

    I am not sure how to test for config validation. But I think we should do that, and not just check the configuration. That is why I think this should be a functional test.

  • Status changed to Postponed: needs info 4 months ago
  • 🇺🇸United States benjifisher Boston area

    I tried to reproduce this issue starting with a fresh install of Drupal core, and I could not.

    There must be something else on my site that is causing this odd behavior.

    I am postponing this issue now. I hope I will have time next week to look into it some more.

Production build 0.71.5 2024