PDOException Error upon saving node with computed field

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="https://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.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

PDOException Error upon saving node with computed field

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.