Problem/Motivation
I am running a set of calendar imports and I am running into this issue when trying to import events with a long title/name (more than 50 characters):
The website encountered an unexpected error. Please try again later.
Drupal\Core\Entity\EntityStorageException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1: INSERT INTO "gcs_calendar_event" ("uuid", "langcode", "user_id", "name", "location", "event_id", "calendar", "description__value", "description__format", "start_date", "end_date", "status", "created", "changed", "event_url") 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, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14); Array ( [:db_insert_placeholder_0] => 7005f679-ca7b-4bf9-8e40-ad156730140b [:db_insert_placeholder_1] => en [:db_insert_placeholder_2] => 1 [:db_insert_placeholder_3] => Event title which is longer than fifty characterssss [:db_insert_placeholder_4] => [:db_insert_placeholder_5] => q065a7tphnu09brpab2pam6d9k [:db_insert_placeholder_6] => 1 [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => [:db_insert_placeholder_9] => 1270468800 [:db_insert_placeholder_10] => 1270472400 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1702068684 [:db_insert_placeholder_13] => 1702068684 [:db_insert_placeholder_14] => https://www.google.com/calendar/event?eid=cTA2NWE3dHBobnUwOWJycGFiMnBhbTZkOWsgZGFucm9kQG0 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Steps to reproduce
- Create events in your google calendar with a long Event name/title, then create the calendar on your Drupal site, and try to import all the events in that google calendar, you will encounter that error:
Proposed resolution
- Change the CalendarEvent
entity at src/Entity/CalendarEvent.php
and set the "Event Name" field to have a max length of 100 characters or more:
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Event Name'))
->setDescription(t(
'The name of the event.'
))
->setSettings([
'max_length' => 50,
'text_processing' => 0,
])
If the Event Name in the Google Calendar is longer than 100 characters, apply changes in src/CalendarImport.php
to truncate the Event Name to 100 characters
Remaining tasks
User interface changes
API changes
Data model changes