Custom Drupal field widget causing check_plain() error I'm working on a custom field widget for Drupal 7. Everything appears to be working correct, but now I'm getting this error:


  Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1565 includes\bootstrap.inc)


My .module hooks:

&lt;?php
/**
 * Implements hook_field_widget_info().
 */
function MYMODULE_field_hook_info() {
  return array(
    'CUSTOM_field' =&gt; array(
      'label' =&gt; t('Custom Text Area'),
      'field_types' =&gt; array('text_long'),
      'behaviors' =&gt; array(
        'multiple values' =&gt; FIELD_BEHAVIOR_DEFAULT,
        'default value' =&gt; FIELD_BEHAVIOR_DEFAULT,
      ),
    ),
  );
}

/**
 * Implements hook_field_widget_form().
 */
function MYMODULE_field_widget_form(&amp;$form, &amp;$form_state, $field, $instance, $langcode, $items, $delta, $element) {
  switch($instance['widget']['type']) {
    case 'CUSTOM_field':
      $element['text_long'] = array(
        '#type' =&gt; 'textarea',
        '#attributes' =&gt; array('id' =&gt; 'MYFIELD', 'rows' =&gt; '5', 'cols' =&gt; '3'),
        '#default_value' =&gt; isset($items[$delta]['value']) ? $items[$delta]['value'] : '',
      );
      break;
  }
  return array('value' =&gt; $element);
}


My guess is that it's something in the way Drupal is attempting to validate my value with check_plain(), but I can't figure out what's wrong.
According to the hook description, $items is an "Array of default values for this field."  You are trying to look in an array of arrays in your default value.

You need to change this line:

    '#default_value' =&gt; isset($items[$delta]['value']) ? $items[$delta]['value'] : '',


to look in the $items array, rather than the $items[$delta] array (which doesn't exist) by removing ['value'], like this:

    '#default_value' =&gt; isset($items[$delta]) ? $items[$delta] : '',