function _update_7000_field_create_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()
comment_update_7005 in modules/comment/comment.install
Create the comment_body field.
node_update_7006 in modules/node/node.install
Convert body and teaser from node properties to fields, and migrate status/comment/promote and sticky columns to the {node_revision} table.
system_update_7060 in modules/system/system.install
Create fields in preparation for migrating upload.module to file.module.
taxonomy_update_7004 in modules/taxonomy/taxonomy.install
Move taxonomy vocabulary associations for nodes to fields and field instances.

File

modules/field/field.install, line 364

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();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.