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:
- create an Article
- in the default Tags field, add a taxonomy term containing parentheses
- click save
- note the error message
- visit the list of Tags and note that only terms without parentheses are present
To see the alternatives that work as intended
- follow the steps above but remove the parentheses and click save
- try other special characters (e.g. curly brackets), then click save
- visit the list of Tags and note that only terms without parentheses are present
- 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.
Comment | File | Size | Author |
---|---|---|---|
#34 | interdiff_30-34.txt | 907 bytes | Spokje |
#34 | 2924783-34.patch | 2.7 KB | Spokje |
#30 | 2924783_test_only_should_fail.patch | 1.79 KB | Spokje |
Screen Shot 2017-11-19 at 21.35.18.png | 23.97 KB | adroid |
Comments
Comment #2
adroid CreditAttribution: adroid commentedTested if these kinds of terms can be added directly from the Add new term form - it is. Tested by adding:
Test (some other text)
So seems to be more of a widget case.
Comment #3
dorficus CreditAttribution: dorficus as a volunteer commented@adroid I am having the same issue. Did you find a workaround or patch?
Comment #4
dorficus CreditAttribution: dorficus as a volunteer commentedhttps://www.drupal.org/node/2520416 is possibly a related issue. It's referenced in EntityAutocomplete.php
Comment #5
kay_v CreditAttribution: kay_v as a volunteer commentedComment #6
kay_v CreditAttribution: kay_v as a volunteer commentedComment #8
MrPaulDriver CreditAttribution: MrPaulDriver commentedIt would be good to see this annoying bug fixed.
Comment #12
schnydszch CreditAttribution: schnydszch commentedThis just came up when trying out in my Drupal install. I hope this bug will be solved soon. Thanks!
Comment #13
Skymen CreditAttribution: Skymen at EPAM Systems commentedI wrote a patch which fix this issue for me. Please, review.
Comment #15
Skymen CreditAttribution: Skymen at EPAM Systems commentedUpdated patch. Fixed cases for anonymous users.
Comment #17
Skymen CreditAttribution: Skymen at EPAM Systems commentedAnother fix after tests fail.
Comment #18
Skymen CreditAttribution: Skymen at EPAM Systems commentedImproved version.
Comment #20
Skymen CreditAttribution: Skymen commentedComment #21
Skymen CreditAttribution: Skymen at EPAM Systems commentedComment #22
Skymen CreditAttribution: Skymen at EPAM Systems commentedComment #24
daveiano#18 solves this issue for me.
Comment #25
Skymen CreditAttribution: Skymen at EPAM Systems commentedComment #26
quietone CreditAttribution: quietone as a volunteer commentedCorrect me if I am wrong but a test is needed.
Comment #27
Leo Pitt CreditAttribution: Leo Pitt commentedThis latest patch does not work for me.
After adding the patch and then trying to create a term "taxonomy_term (yo)" I receive the following message:
The referenced entity (taxonomy_term: yo) does not exist.
Comment #29
Proteo CreditAttribution: Proteo commentedPatch from #18 worked like a charm, thanks!
Comment #30
SpokjeComment #31
SpokjeComment #34
SpokjeComment #35
SpokjeI think the fail_test patch shows that the current patch doesn't solve _all_ cases of parentheses being used in the title of the referenced entity. (@Leo Pitt in Leo Pitt #27 already found out that text in parentheses didn't work).
Comment #36
mkindred CreditAttribution: mkindred commentedThus far, #18 is working for me in 9.2.9.
Comment #37
gambryHave you thought about the implications?
Currently - without the patch - using the scenario Article+Tags in the IS, if you type "Foo (2)", and a term with ID 2 exists, that term will be used.
It doesn't matter what label you put before the "(2)", the label of term with ID 2 will be used.
The work on this issue, and its patch, only adds to this confusion since the behavior of the widget will be different depending what is within the parentheses, and according to the entities already existing in the database.
Talking about the widget... this is how the entity autocomplete form element is meant to work, with expected input being "Label (ID)". Allowing a different pattern is changing the way entity autocomplete works.
My suggestion: close this issue with "work as designed". Then we can open a different feature request issue proposing a widget extending entity autocomplete but allowing parentheses. This can also be a contrib module initially, to speed up adoption.
RE the misleading error, we can create another issue providing meaningful errors when parenthesis are used within the entity autocomplete element.
Comment #39
ainsofs CreditAttribution: ainsofs commented# edit - pls ignore or delete this message if you are admin. thnx
--
#18 not working on 9.4.5
Comment #41
szato CreditAttribution: szato at Brainsum commentedUsing Drupal core 9.4.8 + term reference with views reference display.
Patch #18 fixed my issue.
Comment #42
VasyOK CreditAttribution: VasyOK commentedDrupal 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.
Comment #43
lubwn CreditAttribution: lubwn commentedSadly 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.
Comment #44
lubwn CreditAttribution: lubwn commentedSadly 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.