The EntityAutocomplete form element handles the entity autocompletion fields and is being used by Entity Reference or other modules.
This module basically sets the standard for the format of the value that is being provided by autocomplete text fields representing entities. This element provides a static method for retrieving the entity id from the value and that is the extractEntityIdFromAutocompleteInput method.
Now the issue here is that if a developer wants to use this method in his form element so he can preserve this naming standard he can since it is a static method therefore the developer will most likely want to use it but there is an issue that in case the entity does not exist or uses null storage, etc.. the developer needs to write his own method for extracting just the label of such entity if he needs to work with it, otherwise he would end up with incorrect label if he would just replace the entity id returned by the aforementioned method in the submitted value.(ie "Some label (123)" -> "Some Label ()".
So he is forced to write his own method for extracting the label from the value and use the same regex used by this form element which seems like he shouldn't have to since then he could just write his own pattern and not use this form element in the first place.
Yes, in case he is providing his own autocomplete path he will structure the returned results according to what the form element expects but that does not mean he should also have to create method for extracting labels.
Therefore I think this form element should have additional method for extracting only the label.
| Comment | File | Size | Author |
|---|---|---|---|
| #17 | 2558705-17.patch | 2.95 KB | smustgrave |
| #17 | interdiff-3-17.txt | 5.03 KB | smustgrave |
Comments
Comment #1
Anonymous (not verified) commentedivanjaros created an issue. See original summary.
Comment #2
cilefen commentedComment #3
cilefen commentedI added some test coverage to this and to the ID function. I am ignorant a bit of the autocomplete details. Is there always an ID set in parenthesis?
Comment #4
Anonymous (not verified) commentedYes, although I'm not sure since which Drupal version.
Comment #16
smustgrave commentedAlso if we can get a test-only patch to see the red/green.
Comment #17
smustgrave commentedComment #19
smustgrave commentedRandom ckeditor5 failure.
Comment #20
smustgrave commentedSelf review
This needs an issue summary update/cleanup.
New function should be typehinted.