0

I am working on a D6 site and I have created some fields programatically, and it looked like it worked fine (code below). The fields show up in the database and on the UI screen. However, I found that after adding these field types, when I tried editing data in that content type, it wouldn't save. Looking at the error logs, I saw this:

include_once(./includes/unicode.entities.inc): failed to open stream: No such file or directory in /srv/www/usni.utdev.com/htdocs/includes/unicode.inc on line 339.

and

include_once(): Failed opening './includes/unicode.entities.inc' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /srv/www/usni.utdev.com/htdocs/includes/unicode.inc on line 339.

and I can't figure out why I could be causing these errors.


function createCckFields($csv) {
  foreach ($csv as $key => $value) {
    list($category, $label, $fieldName, $sampleValue, $fieldType, $cardinality) = $value;
    if ($fieldType == 'text' || $fieldType == 'number_integer' || $fieldType == 'number_float' || $fieldType == 'date') {
      createField($category, $label, $fieldName, $sampleValue, $fieldType, $cardinality);
    }
  }
  return;
}

function createField($category, $label, $fieldName, $sampleValue, $fieldType, $cardinality) {
  if ($fieldType == 'text') {
    $module = 'text';
    $widget_type = 'text_textfield';
    $widget_module = 'text';
    $field_name = 'field_' . $fieldName;
  }
  elseif ($fieldType == 'number_integer' || $fieldType == 'number_float') {
    $module = 'number';
    $widget_type = 'number';
    $widget_module = 'number';
    $field_name = 'field_' . $fieldName;
  }
  elseif ($fieldType == 'date') {
    $module = 'date';
    $widget_type = 'date_popup'; //options: date_popup, date_text
    $widget_module = 'date';
    $field_name = 'field_' . $fieldName;
  }
  elseif ($fieldType == 'N/A' && $fieldName == 'RelatedProducts') { //@TODO TAKE OUT HARDCODED FIELDNAME, NEED TO DEAL WITH REVIEW QUOTES TOO
    //this is for fields which have a cardinality of  $field_name,
    'type_name' => 'product',
    'display_settings' => array(
      'label' => array(
        'format' => 'hidden',
        'exclude' => 0,
      ),
      'teaser' => array(
        'format' => 'hidden',
        'exclude' => 1,
      ),
      'full' => array(
        'format' => 'default',
        'exclude' => 0,
      ),
    ),
    'widget_active' => 1,
    'type' => $fieldType, //options: text, number_integer, date
    'required' => 0,
    'multiple' => $cardinality,
    'db_storage' => 1,  //not sure what this does
    'module' => $module, //options: text, number, date
    'active' => 1,
    'locked' => 0,
    'widget' => array(
      'label' => $label,
      /*'default_value' => array(
        0 => array(
          'value' => $sampleValue,
          '_error_element' => 'default_value_widget][' . $field_name . '][0][value',
        ),
      ),*/
      'weight' => 2,
      'description' => 'ie: ' . $sampleValue,
      'type' => $widget_type, //options: text_textfield, optionwidgets_onoff
      'module' => $widget_module, //options: text, optionwidgets
    ),
  );

  if ($fieldType == 'date') {
    $field['granularity'] = array(
      'year' => 'year',
      'month' => 'month',
      'day' => 'day',
    );
    $field['timezone_db'] = '';
    $field['tz_handling'] = 'none'; //this is set to none, since we are not tracking hour and minute in the granularity
    $field['todate'] = '';
    $field['repeat'] = 0;
    $field['repeat_collapsed'] = '';
    $field['default_format'] = 'medium';
    $field['widget']['default_value_code'] = "";
    $field['widget']['default_value2'] = 'blank';
    $field['widget']['default_value_code2'] = '';
    $field['widget']['input_format'] = 'Y-m-d:i:s';
    $field['widget']['input_format_custom'] = 'Ymd'; //the format set for the date fields in onix is YYYYMMDD
    $field['widget']['increment'] = 1;
    $field['widget']['text_parts'] = array();
    $field['widget']['year_range'] = '-3:+3';
    $field['widget']['label_position'] = 'above';
  }
  elseif ($fieldType == 'nodereference') {
    $node_types = node_get_types('names');
    foreach($node_types as $type=>$value) {
      $node_types[$type] = 0;
    }
    $node_types['product'] = 'product';
    $field['referenceable_types'] = $node_types;
    $field['advanced_view'] = '--';
    $field['advanced_view_args'] = '';
    $field['widget']['autocomplete_match'] = 'contains';
    //$field['widget']['size'] = 60;
    //field['widget']['default_value'] = null;
  }
  module_load_include('inc', 'content', 'includes/content.crud');
  if (content_fields($field, 'product')) {
    //content_field_instance_update($field);
    drupal_set_message('Did not create field_' . $fieldName . ' of type ' . $fieldType);
  }
  else {
    content_field_instance_create($field);
    drupal_set_message('Created  field_' . $fieldName . ' of type ' . $fieldType);
  }
  return;
}
0

I'm not sure what is causing those errors, but that was not the issue. I found out that the issue was that I had been creating fields with field names longer than 32 characters, which Drupal doesn't like. I added a 32 character limit to the names, and everything worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.