function field_sql_storage_field_attach_rename_bundle

Implements hook_field_attach_rename_bundle().

File

modules/field/modules/field_sql_storage/field_sql_storage.module, line 876

Code

function field_sql_storage_field_attach_rename_bundle($entity_type, $bundle_old, $bundle_new) {
    // We need to account for deleted or inactive fields and instances.
    $instances = field_read_instances(array(
        'entity_type' => $entity_type,
        'bundle' => $bundle_new,
    ), array(
        'include_deleted' => TRUE,
        'include_inactive' => TRUE,
    ));
    foreach ($instances as $instance) {
        $field = field_info_field_by_id($instance['field_id']);
        if ($field['storage']['type'] == 'field_sql_storage') {
            $table_name = _field_sql_storage_tablename($field);
            $revision_name = _field_sql_storage_revision_tablename($field);
            db_update($table_name)->fields(array(
                'bundle' => $bundle_new,
            ))
                ->condition('entity_type', $entity_type)
                ->condition('bundle', $bundle_old)
                ->execute();
            db_update($revision_name)->fields(array(
                'bundle' => $bundle_new,
            ))
                ->condition('entity_type', $entity_type)
                ->condition('bundle', $bundle_old)
                ->execute();
        }
    }
}

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