I have a node with three fields that I need to concatenate into a single computed field: title, icon, and track. Track is a term reference to a taxonomy term, and icon is a field attached to the taxonomy.
In my computed code, I'm using this:
$tmp = field_get_items('node', $entity, 'field_track_term');
$track_tax = taxonomy_term_load($tmp[0]['tid']);
$field_items = field_get_items('taxonomy_term', $track_tax, 'field_track_icon');
// Get the first item (fields can have multiple items so field_get_items always returns an array)
$first_item = array_shift($field_items);
// Get the URI
$uri = $first_item['uri'];
$icon_vars = array(
'path' => file_create_url($uri),
'attributes' => array(
'class' => array('session_list_track_logo')
)
);
$icon_img = theme_image($icon_vars);
$sess_num_tmp = field_get_items('node', $entity, 'field_session_number');
$sess_num = $sess_num_tmp[0]['safe_value'];
$sess_title = $entity->title;
$entity_field[0]['value'] = $icon_img . " " . $sess_num . " | " . $sess_title;
I've set it to save to the database, field type text, no size limit. What I'm trying to save to the database is a string that looks like this:
<img class="session_list_track_logo" src="http://example.com/sites/default/files/track_icon/shopper_marketing_best_practices.png"
/> A22 | In-Home Insights that Drive In-Store Purchase Decisions
When I try to save a node, I get the following error:
Notice: Undefined index: safe_value in eval() (line 18 of /home/www/expo/sites/all/modules/contrib/computed_field/computed_field.module(466) : eval()'d code).
PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'field_computed_label_value' at row 1: INSERT INTO {field_revision_field_computed_label} (entity_type, entity_id, revision_id, bundle, delta, language, field_computed_label_value) 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); Array ( [:db_insert_placeholder_0] => node [:db_insert_placeholder_1] => 163 [:db_insert_placeholder_2] => 163 [:db_insert_placeholder_3] => session [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => | The Path to Purchase Begins At-Home: In-Home Insights that Drive In-Store Purchase Decisions ) in field_sql_storage_field_storage_write() (line 449 of /home/www/expo/modules/field/modules/field_sql_storage/field_sql_storage.module). The website encountered an unexpected error. Please try again later.
(Note that the image string is included in the query shown after the db_insert_placeholder_6 line; I just can't get SO to format it correctly inside a blockquote.)
I'm not too worried about the first part of the error; I'm obviously just not getting at the session number correctly. What I'm unsure of is what's causing the PDOException error. It says the data is too long for the column. I've double-checked in the database, and the column is definitely set to text with no size limit.
So why would the simple string that shows up later in the error be too long to save?
Just out of curiosity, I set the computed code to do nothing but this:
$entity_field[0]['value'] = $entity->title;
I got the same error.