confusing error & behavior when creating a new referenced entity containing parentheses

Created on 19 November 2017, about 7 years ago
Updated 19 September 2024, 3 months ago

Problem/Motivation

A confusing error occurs if a content creator includes parentheses when creating an entity via an entity reference field. Some actions generate no error. The lack of message with some actions, the error message that appears on node save, and the general behavior, cause confusion for content creators who understand they can add new nodes using entity reference fields.

In some cases, e.g. adding parentheses when creating an entity via a multi-value entity reference field then clicking "add another item", the field turns red but provides no explanation.

In other cases, e.g. clicking "save" when creating an entity via an entity reference field, the error message does not explain that the parentheses are the cause of the failure.

Proposed resolution

System can try finding a reference with that ID, but when match is not found, it should create it even if name/value has parentheses.

Ideally parentheses should be allowed while creating new entities via the entity reference field. Alternatively the error message should provide instructions appropriate to the intended (non-technical) audience.

To reproduce the issue

On a clean, standard install of Drupal:

  1. create an Article
  2. in the default Tags field, add a taxonomy term containing parentheses
  3. click save
  4. note the error message
  5. visit the list of Tags and note that only terms without parentheses are present

To see the alternatives that work as intended

  1. follow the steps above but remove the parentheses and click save
  2. try other special characters (e.g. curly brackets), then click save
  3. visit the list of Tags and note that only terms without parentheses are present
  4. click 'Add term' while on the taxonomy list page and add a term with parentheses

Original issue report

Content type with an Entity Reference field allowed to create new entities to the taxonomy term will not accept values with parentheses.

Fields' REFERENCE TYPE has a Reference method: Default
and checkbox "Create referenced entities if they don't already exist" is checked.

It works and new term is created if I enter the field value:
Test

It does not work when I insert
Test (some other text)

Last one gives an error:
The referenced entity (taxonomy_term: some other text) does not exist.

It probably tries to find the term with an ID 'some other text' and when match is not found, it does not try to create it but blindly believes that entered is ID and it needs to find a match.

But how can one enter a value which has parentheses without making system to think that it's the ID what user entered between parentheses?

Proposed resolution

System can try finding a reference with that ID, but when match is not found, it should create it even if name/value has parentheses.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated about 17 hours ago

Created by

πŸ‡ͺπŸ‡ͺEstonia adroid

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡¦Ukraine vasyok

    Drupal 9.5.
    [For me] Today pathces are not needed for use with Autocomplite (Tags style) widget. Even if linked entites contain brackets.
    But with popular_tags module (mb with some others) patch #18 is necessary.

  • πŸ‡ΈπŸ‡°Slovakia lubwn

    Sadly this does not work in Drupal 9.5.9 at all. Putting any text in parentheses triggers an error so entities containing text in parentheses can not be referenced at all (nor created). Applying patch from #18 does not solve the issue.

  • πŸ‡ΈπŸ‡°Slovakia lubwn

    Sadly this is an error which seems to be too deep to be fixed in short term so I developed custom solution.

    I have basicly only added new custom fields with same names as taxonomy fields I already had but with formatter "Text (plain)". Then I used hook_entity_presave() to match text inputted by user into those custom fields and check whether taxonomies exists by name or not, setting them to previously created taxonomy reference fields as target_id. In this custom solution you also have full control over what you want to use as a delimited between each taxonomy entity (for example ";" instead of "," or so)

    I guess proper "Drupal" way would be either somehow fix the error or create custom taxonomy field formatter with the logic needed for that but to be fair that would take so much more time and effort as everything with Drupal that those custom hacks works better and are faster to implement.

  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    Patch for 10.3, continuation of #34.

    I added a check on the matched entity ID in parenthesis to verify that it is an integer.

    Now we can create new referenced entities with parenthesis.

    For example: Natural Language Processing (NLP)

    Referencing an existing entity that has a number in parenthesis is working.

    Example: Collection (403)

    Works with both typing in by name and using the autocomplete.

    What does NOT work is verifying that the parenthesis value is a valid ID or otherwise creating a new entity.

Production build 0.71.5 2024