_update_7000_field_create_instance

7 field.install _update_7000_field_create_instance($field, &$instance)
8 field.install _update_7000_field_create_instance($field, &$instance)

Utility function: write a field instance directly to the database.

This function can be used for databases whose schema is at field module version 7000 or higher.

Related topics

4 calls to _update_7000_field_create_instance()

File

modules/field/field.install, line 361
Install, update and uninstall functions for the field module.

Code

function _update_7000_field_create_instance($field, &$instance) {
  // Merge in defaults.
  $instance += array(
    'field_id' => $field['id'], 
    'field_name' => $field['field_name'], 
    'deleted' => 0,
  );

  // The serialized 'data' column contains everything from $instance that does
  // not have its own column and is not automatically populated when the
  // instance is read.
  $data = $instance;
  unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']);

  $record = array(
    'field_id' => $instance['field_id'], 
    'field_name' => $instance['field_name'], 
    'entity_type' => $instance['entity_type'], 
    'bundle' => $instance['bundle'], 
    'data' => serialize($data), 
    'deleted' => (int) $instance['deleted'],
  );
  $instance['id'] = db_insert('field_config_instance')
    ->fields($record)
    ->execute();
}
Login or register to post comments