Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array

Created on 26 May 2025, about 1 month ago

Problem/Motivation

I get the following error when I try to add default values to a multi-value formatted text field:

Error: Cannot use object of type Drupal\Core\StringTranslation\TranslatableMarkup as array in Drupal\text\Plugin\Field\FieldType\TextFieldItemList->defaultValuesFormValidate() (line 24 of /app/web/core/modules/text/src/Plugin/Field/FieldType/TextFieldItemList.php).

The "add_more" button is handled as a submitted value and that is causing an error in the allowed_formats check.

Steps to reproduce

  1. Add a formatted text field to a node type
  2. Select "Text (formatted)" as the field type
  3. Make sure at least one format is selected in the "Allowed formats" list
  4. Click the "Add item" button to add another default value

Proposed resolution

Check if the value "add_more" is set and remove it if so.

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

field system

Created by

🇳🇱Netherlands Ewout Goosmann

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Ewout Goosmann
  • 🇳🇱Netherlands Ewout Goosmann

    Also as patch, next to the MR.

  • 🇺🇸United States smustgrave

    Thanks for reporting

    Changes will need to be in an MR against 11.x

    Also will need a test case showing the bug.

  • 🇮🇳India libbna New Delhi, India

    I will create a MR for #3 patch.

  • 🇮🇳India libbna New Delhi, India

    I already can see the changes in the in the branch.

  • First commit to issue fork.
  • Merge request !12390Issue #3526541: add test scenario → (Open) created by julio_retkwa
  • Pipeline finished with Failed
    11 days ago
    Total: 180s
    #523956
  • 🇧🇷Brazil julio_retkwa Balneário Camboriú

    Hey all
    I've added a test scenario let me know if that makes sense
    any reviews are welcome :D https://git.drupalcode.org/project/drupal/-/merge_requests/12390

  • 🇧🇷Brazil julio_retkwa Balneário Camboriú
  • Pipeline finished with Failed
    11 days ago
    Total: 182s
    #523957
  • 🇺🇸United States smustgrave

    Appears to have a pipeline issue

  • Pipeline finished with Failed
    10 days ago
    Total: 1395s
    #524737
  • Pipeline finished with Failed
    10 days ago
    Total: 851s
    #524749
  • Pipeline finished with Failed
    10 days ago
    Total: 3106s
    #524757
  • Pipeline finished with Failed
    10 days ago
    Total: 1017s
    #524800
  • Pipeline finished with Failed
    10 days ago
    Total: 969s
    #524833
  • Pipeline finished with Failed
    10 days ago
    #524850
  • Pipeline finished with Failed
    10 days ago
    Total: 652s
    #524858
  • Pipeline finished with Failed
    10 days ago
    Total: 516s
    #524866
  • Pipeline finished with Failed
    10 days ago
    Total: 684s
    #524872
  • Pipeline finished with Failed
    8 days ago
    Total: 617s
    #526516
  • Pipeline finished with Failed
    8 days ago
    Total: 500s
    #526727
  • Pipeline finished with Failed
    7 days ago
    Total: 124s
    #526979
  • Pipeline finished with Failed
    7 days ago
    Total: 427s
    #527079
  • Pipeline finished with Failed
    7 days ago
    Total: 5542s
    #527015
  • Pipeline finished with Failed
    5 days ago
    #528523
  • 🇧🇷Brazil julio_retkwa Balneário Camboriú

    I'm sorry but I'll need to give up this one, I'm out of ideas on how to solve the test problems that I'm facing

  • 🇮🇳India JatinGupta40

    Hello
    I am assigning it to myself for trying to resolve the test problems thanks

  • 🇮🇳India JatinGupta40

    Hello @julio_rekwa,
    It seems the branch you're using might not be aligned with the expected naming convention. Ideally, it should be something like:
    git checkout 3526541-error-cannot-use However, your MR branch appears to be: issue/drupal-3526541:11.x

    When I check out this branch (issue/drupal-3526541:11.x), I do see all the changes from the MR, but Git shows the state as:
    HEAD detached at drupal-3526541/11.x

    This typically indicates that the branch is tracking a remote ref directly without creating a local branch. Let me know if this is intentional or if we should align on a consistent branch naming and checkout approach.

    Also, attaching a patch file, please check if it is resolving the pipeline issue.
    2025-06-24/3526541-error-cannot-use.patch
    Thanks.

  • Merge request !12468Issue #3526541: Error: Cannot use object of type... → (Open) created by oily
  • 🇬🇧United Kingdom oily Greater London

    oily changed the visibility of the branch 11.x to hidden.

  • 🇬🇧United Kingdom oily Greater London

    @julioretkwa I am trying to get the pipeline to show green with a minor PHPSTAN fix. Your test coverage in your new branch can be ported over to the active branch, then. Then can make sure the test works correctly in the pipeline, too.

  • 🇬🇧United Kingdom oily Greater London

    RE: #14 Trying a merge request to see if the active fork/ MR is syncing with the 11.x dev branch. It is currently about 90 commits behind it.

  • 🇬🇧United Kingdom oily Greater London

    @julio_retkwa If you want to have another go at the test coverage, good if you can start by merging your test into the active branch. Can then run manually the 'test-only' test which will fail if test coverage is working well.

Production build 0.71.5 2024