You are here

function _content_field_instance_write in Content Construction Kit (CCK) 6.3

Same name and namespace in other branches
  1. 6 includes/content.crud.inc \_content_field_instance_write()
  2. 6.2 includes/content.crud.inc \_content_field_instance_write()

Write a field instance record.

Parameters

$field: The field array to process.

2 calls to _content_field_instance_write()
content_field_instance_create in includes/content.crud.inc
Create a new field instance.
content_field_instance_update in includes/content.crud.inc
Update an existing field instance.

File

includes/content.crud.inc, line 431
Create/Read/Update/Delete functions for CCK-defined object types.

Code

function _content_field_instance_write($field, $op = 'update') {

  // Collapse the field => widget format, so that the values to be saved by
  // drupal_write_record are on top-level.
  $field = content_field_instance_collapse($field);

  // Rearrange the data to create the widget_settings array.
  $setting_names = (array) module_invoke($field['widget_module'], 'widget_settings', 'save', $field);
  drupal_alter('widget_settings', $setting_names, 'save', $field);
  foreach ($setting_names as $setting) {

    // In some cases (when the updated $field was originally read from
    // the db, as opposed to gathered from the values of a form), the values
    // are already in the right place, we take care to not wipe them.
    if (isset($field[$setting])) {
      $field['widget_settings'][$setting] = $field[$setting];
      unset($field[$setting]);
    }
  }
  switch ($op) {
    case 'create':
      drupal_write_record(content_instance_tablename(), $field);
      break;
    case 'update':
      drupal_write_record(content_instance_tablename(), $field, array(
        'field_name',
        'type_name',
      ));
      break;
  }
  return $field;
}