If a user attempts to add a taxonomy term with a large name (> 255 characters), taxonomy manager generates an exception and crashes.
taxonomy_manager.admin.inc :: taxonomy_manager_form_add_submit(...) ->
taxonomy_manager.admin.inc :: taxonomy_manager_mass_add_terms(...) ->
taxonomy.module :: taxonomy_term_save($term) ->
drupal_write_record('taxonomy_term_data', $term) ->
generates a PDOException, message: "SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1"
The resulting display to the user is an unthemed display of "ERROR The website encountered an unexpected error. Please try again later. "
Instead, the user the should receive an error message that doesn't break the page, maintains the form data they've submitted, and notifies them of which term(s) need to be fixed.
Alternatively, it would be nice to have an option to simply truncate the term and accept it (maybe with warning). For my use case, most of these long term names are being copied & pasted from another document. I'm okay with them being truncated, and I'd rather have the system automatically truncate them for me, rather than having to figure out exactly how many characters I need to remove from each long term name.
Comment | File | Size | Author |
---|---|---|---|
#2 | taxonomy_manager_config.PNG | 18.52 KB | randyhook |
#2 | taxonomy_manager_notification.PNG | 6.78 KB | randyhook |
#2 | taxonomy_manager-large-term-names-1841986.patch | 3.34 KB | randyhook |
Comments
Comment #1
chirhotec CreditAttribution: chirhotec commentedFor what its worth, here's the code to simply truncate the term on submission, with a warning to the user.
Comment #2
randyhook CreditAttribution: randyhook commentedHere is a patch to address this issue. I started with chirhotec's truncate code. The configuration form at admin/config/user-interface/taxonomy-manager-settings now includes a textfield for the user to enter the max number of characters they would like their terms truncated to.
Adding taxonomy terms at admin/structure/taxonomy_manager/voc/vocab now automatically truncates the terms based on the value entered in the config. If no value is entered, the default 255 characters is used.
Note: Taxonomy Manager uses the Drupal core Taxonomy module to save the terms. The core module does not truncate terms. Rather, it sets it's term textfield to a max length of 255, prohibiting the user from entering a longer term. Therefore, we cannot send a string that is too long to the core module and expect some kind of exception handling. Thus I have set up the patch to truncate terms automatically.
Upon adding the terms, the user is notified which terms, if any, were truncated.
Note: I would like to eliminate the use of the hardcoded "255" characters if possible.
Comment #3
mh86 CreditAttribution: mh86 commentedCommitted a different version to fix this problem, see http://drupalcode.org/project/taxonomy_manager.git/blobdiff/5a238943c396...
@randyhook: at the moment I don't see a use case to not have it hardcoded to 255 characters, as this value directly corresponds to the database schema. But feel free to convince me and re-open this (or create a new) issue (feature request) :-)
Thanks for the report and patches!
Comment #4.0
(not verified) CreditAttribution: commentedtypo