Problem/Motivation
If someone tries to insert a long term via autocomplete on a page, then it will result in an exception because no validation is fired that the term isn't too long.
This is also an issue on D7, which is where I originally uncovered the situation. I had expected it to be fixed in D8 with typed data, but that isn't the case.
Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1: INSERT INTO {taxonomy_term_field_data} (tid, vid, langcode, name, description__value, description__format, weight, changed, default_langcode) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8); Array ( [:db_insert_placeholder_0] => 2 [:db_insert_placeholder_1] => tags [:db_insert_placeholder_2] => en [:db_insert_placeholder_3] => Donec mi odio; faucibus at; scelerisque quis; convallis in; nisi; Proin sapien ipsum;porta a; auctor quis; euismod ut; mi; Sed libero; Praesent vestibulum dapibus nibh; Pellentesque auctor neque nec urna; Aliquam lorem ante; dapibus in; viverra quis; feugiat a; tellus; Vivamus aliquet elit ac nisl; Donec vitae orci sed dolor rutrum auctor; Donec pede justo; fringilla vel; aliquet nec; vulputate eget; arcu; Donec venenatis vulputate lorem [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => 0 [:db_insert_placeholder_7] => 1444326833 [:db_insert_placeholder_8] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 757 of /home/dfv2i/www/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Proposed resolution
Remaining tasks
Fix it. I think a good starting point would be EntityAutocomplete->validateEntityAutocomplete().
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | drupal-taxonomy_autocomplete-2584225-1.patch | 1.21 KB | puneetsharma |
| #14 | drupal-taxonomy_autocomplete-2584225-14.patch | 1.13 KB | klausi |
Comments
Comment #2
heddnTemporarily switching this to D7 to see how it fairs. It still needs some tests though.
Comment #3
heddnComment #4
heddnPatch in #3 is against D7.
Comment #5
azinck commentedRefined the error message in the D7 patch a bit to make it less technical ("strings" is probably less understandable than "terms"). Other than that, this looks great.
Comment #7
imre.horjanThis patch is not for D8, so I've changed version.
Comment #8
heddnEven though the patches are for D7, this needs to be fixed in D8 first, because of the backport policy. Switching back to D8.
Comment #9
imre.horjanYeah, I forget to mention there's an other issue for D8, which's a general fix for all kind of entity references, not only taxonomy terms:
https://www.drupal.org/node/2438017
So, I still think this is a D7-only issue.
Comment #10
imre.horjanCheck this, this is closed as duplicate for D8:
https://www.drupal.org/node/2569549
Comment #11
heddnPostponing on #2438017: Entity reference does not validate auto-created entities then.
Comment #12
sepgil commentedFixed the path from #2584225-5: [PP-1] Taxonomy autocomplete does not validate for term name length to use drupal_strlen instead strlen, so that unicode characters are supported.
Comment #13
klausiThis should use form_error() on $element instead. And the message should be 255, not 256.
In my testing with other taxonomy autocomplete module $element['#title'] was not even set. So I have this workaround:
Because the textfield property is there for me.
Comment #14
klausiPatch. This still needs tests, so leaving at "needs work".
Comment #15
puneetsharma commentedPatch with replacing
!emptywithisset.