Max length of 128 preventing saving lots of referenced entities

Created on 25 September 2024, 4 months ago
Updated 29 November 2024, 2 months ago

Problem/Motivation

When trying to save a node with many tags (using SHS), I get an error saying:

"{field name} cannot be longer than 128 characters but is currently {number} characters long."

When I inspect the HTML, I see that it saves the target IDs in a "textfield" form field, that has a maxlength="128" attribute. This is unnecessarily short and preventing me from saving the node.

When I review the module code, I see that in:
/shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.php, in formElement(), line 164 is:
$element['#type'] = 'textfield';
which changes the field type to textfield. However that also uses the default maxlength of 128.

If I add the following line right after it:
$element['#maxlength'] = 500;
Then I'm able to save the node with way more tags.

But 500 is an arbitrary maximum length, so I'm not sure how to determine the ideal length.

πŸ› Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

πŸ‡ΏπŸ‡¦South Africa droces

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

Comments & Activities

  • Issue created by @droces
  • First commit to issue fork.
  • πŸ‡«πŸ‡·France rubberg

    Hi @droces,

    I reproduced the error you described above (see caption with suffix "before").

    I made a patch to remove maxlength limitation on the text field once it is built and not during its construction (after Drupal applied the 128 chars limitation), and was able to exceed the field length limitation and saved a 134 chars string with no errors (46 taxonomy terms saved : see 3 captions with suffix "after").

    Tested on Drupal 10.3.10 with SHS module version 2.0.0.

Production build 0.71.5 2024