Commit 714597a9 authored by Dries's avatar Dries

- Patch #470242 by yched, bjaspan: fixed namespacing for bundle names to avoid...

- Patch #470242 by yched, bjaspan: fixed namespacing for bundle names to avoid users rendering their site unusable.
parent 35e21e54
......@@ -117,7 +117,7 @@ function comment_update_7004() {
*/
function comment_update_7005() {
foreach (node_type_get_types() as $info) {
field_attach_create_bundle('comment_node_' . $info->type);
field_attach_create_bundle('comment', 'comment_node_' . $info->type);
}
}
......
......@@ -233,7 +233,7 @@ function comment_count_unpublished() {
* Implement hook_node_type_insert().
*/
function comment_node_type_insert($info) {
field_attach_create_bundle('comment_node_' . $info->type);
field_attach_create_bundle('comment', 'comment_node_' . $info->type);
}
/**
......@@ -241,7 +241,7 @@ function comment_node_type_insert($info) {
*/
function comment_node_type_update($info) {
if (!empty($info->old_type) && $info->type != $info->old_type) {
field_attach_rename_bundle('comment_node_' . $info->old_type, 'comment_node_' . $info->type);
field_attach_rename_bundle('comment', 'comment_node_' . $info->old_type, 'comment_node_' . $info->type);
}
}
......@@ -249,7 +249,7 @@ function comment_node_type_update($info) {
* Implement hook_node_type_delete().
*/
function comment_node_type_delete($info) {
field_attach_delete_bundle('comment_node_' . $info->type);
field_attach_delete_bundle('comment', 'comment_node_' . $info->type);
$settings = array(
'comment',
'comment_default_mode',
......
......@@ -1061,7 +1061,7 @@ function hook_field_attach_view_alter(&$output, $context) {
*
* See field_attach_create_bundle() for details and arguments.
*/
function hook_field_attach_create_bundle($bundle) {
function hook_field_attach_create_bundle($obj_type, $bundle) {
}
/**
......@@ -1071,7 +1071,7 @@ function hook_field_attach_create_bundle($bundle) {
*
* See field_attach_rename_bundle() for details and arguments.
*/
function hook_field_attach_rename_bundle($bundle_old, $bundle_new) {
function hook_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
}
/**
......@@ -1079,13 +1079,15 @@ function hook_field_attach_rename_bundle($bundle_old, $bundle_new) {
*
* This hook is invoked after the field module has performed the operation.
*
* @param $obj_type
* The type of object; e.g. 'node' or 'user'.
* @param $bundle
* The bundle that was just deleted.
* @param $instances
* An array of all instances that existed for $bundle before it was
* An array of all instances that existed for the bundle before it was
* deleted.
*/
function hook_field_attach_delete_bundle($bundle, $instances) {
function hook_field_attach_delete_bundle($obj_type, $bundle, $instances) {
}
/**
......
......@@ -184,10 +184,10 @@ function _field_invoke($op, $obj_type, $object, &$a = NULL, &$b = NULL, $options
list(, , $bundle) = field_extract_ids($obj_type, $object);
if ($options['deleted']) {
$instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
$instances = field_read_instances(array('object_type' => $obj_type, 'bundle' => $bundle), array('include_deleted' => $options['deleted']));
}
else {
$instances = field_info_instances($bundle);
$instances = field_info_instances($obj_type, $bundle);
}
foreach ($instances as $instance) {
......@@ -304,7 +304,7 @@ function _field_invoke_multiple($op, $obj_type, $objects, &$a = NULL, &$b = NULL
$instances = field_read_field(array('bundle' => $bundle, array('include_deleted' => $options['deleted'])));
}
else {
$instances = field_info_instances($bundle);
$instances = field_info_instances($obj_type, $bundle);
}
foreach ($instances as $instance) {
......@@ -593,10 +593,10 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
foreach ($queried_objects as $obj) {
list($id, $vid, $bundle) = field_extract_ids($obj_type, $obj);
if ($options['deleted']) {
$instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
$instances = field_read_instances(array('object_type' => $obj_type, 'bundle' => $bundle), array('include_deleted' => $options['deleted']));
}
else {
$instances = field_info_instances($bundle);
$instances = field_info_instances($obj_type, $bundle);
}
foreach ($instances as $instance) {
......@@ -637,7 +637,7 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
foreach ($queried_objects as $id => $object) {
$data = array();
list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$instances = field_info_instances($bundle);
$instances = field_info_instances($obj_type, $bundle);
foreach ($instances as $instance) {
$data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
}
......@@ -831,7 +831,7 @@ function field_attach_insert($obj_type, $object) {
// Collect the storage backends used by the remaining fields in the objects.
$storages = array();
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_name = $field['field_name'];
......@@ -877,7 +877,7 @@ function field_attach_update($obj_type, $object) {
// Collect the storage backends used by the remaining fields in the objects.
$storages = array();
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$field_name = $field['field_name'];
......@@ -920,7 +920,7 @@ function field_attach_delete($obj_type, $object) {
// Collect the storage backends used by the fields in the objects.
$storages = array();
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$storages[$field['storage']['type']][$field_id] = $field_id;
......@@ -959,7 +959,7 @@ function field_attach_delete_revision($obj_type, $object) {
// Collect the storage backends used by the fields in the objects.
$storages = array();
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field = field_info_field_by_id($instance['field_id']);
$field_id = $field['id'];
$storages[$field['storage']['type']][$field_id] = $field_id;
......@@ -1225,7 +1225,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode =
function field_attach_preprocess($obj_type, $object, $element, &$variables) {
list(, , $bundle) = field_extract_ids($obj_type, $object);
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
$field_name = $instance['field_name'];
if (isset($element[$field_name]['#language'])) {
$langcode = $element[$field_name]['#language'];
......@@ -1283,33 +1283,38 @@ function field_attach_prepare_translation($node) {
/**
* Notify field.module that a new bundle was created.
*
* The default SQL-based storage doesn't need to do anytrhing about it, but
* The default SQL-based storage doesn't need to do anything about it, but
* others might.
*
* @param $obj_type
* The object type to which the bundle is bound.
* @param $bundle
* The name of the newly created bundle.
*/
function field_attach_create_bundle($bundle) {
function field_attach_create_bundle($obj_type, $bundle) {
// Clear the cache.
field_cache_clear();
foreach (module_implements('field_attach_create_bundle') as $module) {
$function = $module . '_field_attach_create_bundle';
$function($bundle);
$function($obj_type, $bundle);
}
}
/**
* Notify field.module that a bundle was renamed.
*
* @param $obj_type
* The object type to which the bundle is bound.
* @param $bundle_old
* The previous name of the bundle.
* @param $bundle_new
* The new name of the bundle.
*/
function field_attach_rename_bundle($bundle_old, $bundle_new) {
function field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
db_update('field_config_instance')
->fields(array('bundle' => $bundle_new))
->condition('object_type', $obj_type)
->condition('bundle', $bundle_old)
->execute();
......@@ -1318,7 +1323,7 @@ function field_attach_rename_bundle($bundle_old, $bundle_new) {
foreach (module_implements('field_attach_rename_bundle') as $module) {
$function = $module . '_field_attach_rename_bundle';
$function($bundle_old, $bundle_new);
$function($obj_type, $bundle_old, $bundle_new);
}
}
......@@ -1332,12 +1337,14 @@ function field_attach_rename_bundle($bundle_old, $bundle_new) {
* (particularly since for some field types, the deletion is more than just a
* simple DELETE query).
*
* @param $obj_type
* The object type to which the bundle is bound.
* @param $bundle
* The bundle to delete.
*/
function field_attach_delete_bundle($bundle) {
function field_attach_delete_bundle($obj_type, $bundle) {
// First, delete the instances themseves.
$instances = field_info_instances($bundle);
$instances = field_info_instances($obj_type, $bundle);
foreach ($instances as $instance) {
field_delete_instance($instance);
}
......@@ -1348,7 +1355,7 @@ function field_attach_delete_bundle($bundle) {
// Let other modules act on deleting the bundle.
foreach (module_implements('field_attach_delete_bundle') as $module) {
$function = $module . '_field_attach_delete_bundle';
$function($bundle, $instances);
$function($obj_type, $bundle, $instances);
}
}
......
......@@ -15,19 +15,21 @@
* Instance, and the concept of a Bundle. A Field defines a
* particular type of data that can be attached to objects. A Field
* Instance is a Field attached to a single Bundle. A Bundle is a set
* of fields that are treated as a group by the Field Attach API.
* of fields that are treated as a group by the Field Attach API and
* is related to a single fieldable entity type.
*
* For example, suppose a site administrator wants Article nodes to
* have a subtitle and photo. Using the Field API or some UI module,
* have a subtitle and photo. Using the Field API or Field UI module,
* the administrator creates a field named 'subtitle' of type 'text'
* and a field named 'photo' of type 'image'. The administrator
* (again, via a UI) creates two Field Instances, one attaching the
* field 'subtitle' to the bundle 'article' and one attaching the field
* 'photo' to the bundle 'article'. When the node system uses the
* Field Attach API to load all fields for an Article node, it passes
* the node's content type (which is 'article') as the node's bundle.
* field 'subtitle' to the 'node' bundle 'article' and one attaching
* the field 'photo' to the 'node' bundle 'article'. When the node
* system uses the Field Attach API to load all fields for an Article
* node, it passes the node's entity type (which is 'node') and
* content type (which is 'article') as the node's bundle.
* field_attach_load() then loads the 'subtitle' and 'photo' fields
* because they are both attached to the bundle 'article'.
* because they are both attached to the 'node' bundle 'article'.
*
* Field objects are (currently) represented as an array of key/value
* pairs. The object properties are:
......@@ -103,6 +105,8 @@
* It is populated automatically by field_create_instance().
* - field_name (string)
* The name of the field attached to the bundle by this instance.
* - object_type (string)
* The name of the object type the instance is attached to.
* - bundle (string)
* The name of the bundle that the field is attached to.
* - label (string)
......@@ -168,6 +172,8 @@
* - other_build_mode
* - ...
*
* Bundles are represented by two strings, an entity type and a bundle name.
*
* TODO D7 : document max length for field types, widget types,
* formatter names...
*/
......@@ -540,9 +546,11 @@ function field_delete_field($field_name) {
// Delete all non-deleted instances.
$field = field_info_field($field_name);
if (isset($field['bundles'])) {
foreach ($field['bundles'] as $bundle) {
$instance = field_info_instance($field_name, $bundle);
field_delete_instance($instance);
foreach ($field['bundles'] as $obj_type => $bundles) {
foreach ($bundles as $bundle) {
$instance = field_info_instance($obj_type, $field_name, $bundle);
field_delete_instance($instance);
}
}
}
......@@ -565,9 +573,9 @@ function field_delete_field($field_name) {
* Creates an instance of a field, binding it to a bundle.
*
* @param $instance
* A field instance structure. The field_name and bundle properties are
* required.
* Other properties, if omitted, will be given the following default values:
* A field instance structure. The field_name, object_type and
* bundle properties are required. Other properties, if omitted,
* will be given the following default values:
* - label: the field name
* - description: empty string
* - weight: 0
......@@ -592,11 +600,17 @@ function field_delete_field($field_name) {
* FieldException
*/
function field_create_instance($instance) {
// Check that the specified field exists.
$field = field_read_field($instance['field_name']);
if (empty($field)) {
throw new FieldException("Attempt to create an instance of a field that doesn't exist or is currently inactive.");
}
// Check that the required properties exists.
if (empty($instance['object_type'])) {
throw new FieldException(t('Attempt to create an instance of field @field_name without an object type.', array('@field_name' => $instance['field_name'])));
}
if (empty($instance['bundle'])) {
throw new FieldException(t('Attempt to create an instance of field @field_name without a bundle.', array('@field_name' => $instance['field_name'])));
}
// Set the field id.
$instance['field_id'] = $field['id'];
......@@ -614,7 +628,7 @@ function field_create_instance($instance) {
// Ensure the field instance is unique within the bundle.
// We only check for instances of active fields, since adding an instance of
// a disabled field is not supported.
$prior_instance = field_read_instance($instance['field_name'], $instance['bundle']);
$prior_instance = field_read_instance($instance['object_type'], $instance['field_name'], $instance['bundle']);
if (!empty($prior_instance)) {
$message = t('Attempt to create a field instance that already exists.');
throw new FieldException($message);
......@@ -655,7 +669,7 @@ function field_update_instance($instance) {
// Check that the field instance exists (even if it is inactive, since we
// want to be able to replace inactive widgets with new ones).
$prior_instance = field_read_instance($instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
$prior_instance = field_read_instance($instance['object_type'], $instance['field_name'], $instance['bundle'], array('include_inactive' => TRUE));
if (empty($prior_instance)) {
throw new FieldException("Attempt to update a field instance that doesn't exist.");
}
......@@ -736,6 +750,7 @@ function _field_write_instance($instance, $update = FALSE) {
$record = array(
'field_id' => $instance['field_id'],
'field_name' => $instance['field_name'],
'object_type' => $instance['object_type'],
'bundle' => $instance['bundle'],
'data' => $data,
'deleted' => $instance['deleted'],
......@@ -759,6 +774,8 @@ function _field_write_instance($instance, $update = FALSE) {
* This function will not return deleted instances. Use
* field_read_instances() instead for this purpose.
*
* @param $obj_type
* The type of object to which the field is bound.
* @param $field_name
* The field name to read.
* @param $bundle
......@@ -772,8 +789,8 @@ function _field_write_instance($instance, $update = FALSE) {
* @return
* An instance structure, or FALSE.
*/
function field_read_instance($field_name, $bundle, $include_additional = array()) {
$instances = field_read_instances(array('field_name' => $field_name, 'bundle' => $bundle), $include_additional);
function field_read_instance($obj_type, $field_name, $bundle, $include_additional = array()) {
$instances = field_read_instances(array('object_type' => $obj_type, 'field_name' => $field_name, 'bundle' => $bundle), $include_additional);
return $instances ? current($instances) : FALSE;
}
......@@ -820,6 +837,7 @@ function field_read_instances($params = array(), $include_additional = array())
$instance['id'] = $record['id'];
$instance['field_id'] = $record['field_id'];
$instance['field_name'] = $record['field_name'];
$instance['object_type'] = $record['object_type'];
$instance['bundle'] = $record['bundle'];
$instance['deleted'] = $record['deleted'];
......@@ -841,6 +859,7 @@ function field_delete_instance($instance) {
db_update('field_config_instance')
->fields(array('deleted' => 1))
->condition('field_name', $instance['field_name'])
->condition('object_type', $instance['object_type'])
->condition('bundle', $instance['bundle'])
->execute();
......
......@@ -75,9 +75,9 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i
$info = array(
'#field_name' => $field['field_name'],
'#object_type' => $obj_type,
'#bundle' => $bundle,
'#object' => $object,
'#object_type' => $obj_type,
);
$element = $info + array(
......
......@@ -66,6 +66,7 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
'#delta' => $delta,
'#field_name' => $field['field_name'],
'#bundle' => $instance['bundle'],
'#object_type' => $instance['object_type'],
);
$element = array_merge($element, $defaults);
// If we're processing a specific delta value for a field where the
......@@ -168,6 +169,7 @@ function field_multiple_value_form($field, $instance, $langcode, $items, &$form,
'#delta' => $delta,
'#columns' => array_keys($field['columns']),
'#field_name' => $field_name,
'#object_type' => $instance['object_type'],
'#bundle' => $instance['bundle'],
);
......
......@@ -190,8 +190,8 @@ function _field_info_collate_types($reset = FALSE) {
* - fields_id: Array of existing fields, keyed by field id. This entry lists
* both deleted and non-deleted fields. The bundles element is the same as
* for 'fields'.
* - instances: Array of existing instances, keyed by bundle name and field
* name. This entry only lists non-deleted instances.
* - instances: Array of existing instances, keyed by object type, bundle
* name and field name. This entry only lists non-deleted instances.
*/
function _field_info_collate_fields($reset = FALSE) {
static $info;
......@@ -236,18 +236,18 @@ function _field_info_collate_fields($reset = FALSE) {
foreach ($definitions['instances'] as $instance) {
$field = $info['fields'][$instance['field_name']];
$instance = _field_info_prepare_instance($instance, $field);
$info['instances'][$instance['bundle']][$instance['field_name']] = $instance;
$info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']] = $instance;
// Enrich field definitions with the list of bundles where they have
// instances. NOTE: Deleted fields in $info['field_ids'] are not
// enriched because all of their instances are deleted, too, and
// are thus not in $definitions['instances'].
$info['fields'][$instance['field_name']]['bundles'][] = $instance['bundle'];
$info['field_ids'][$instance['field_id']]['bundles'][] = $instance['bundle'];
$info['fields'][$instance['field_name']]['bundles'][$instance['object_type']][] = $instance['bundle'];
$info['field_ids'][$instance['field_id']]['bundles'][$instance['object_type']][] = $instance['bundle'];
// Add storage details.
$details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field, $instance);
drupal_alter('field_storage_details', $details, $field, $instance);
$info['instances'][$instance['bundle']][$instance['field_name']]['storage_details'] = $details;
$info['instances'][$instance['object_type']][$instance['bundle']][$instance['field_name']]['storage_details'] = $details;
}
}
......@@ -313,8 +313,7 @@ function _field_info_prepare_instance($instance, $field) {
}
// Fallback to 'full' display settings for unspecified build modes.
$obj_type = field_info_bundle_entity($instance['bundle']);
foreach (field_build_modes($obj_type) as $build_mode => $label) {
foreach (field_build_modes($instance['object_type']) as $build_mode => $label) {
if (!isset($instance['display'][$build_mode])) {
$instance['display'][$build_mode] = $instance['display']['full'];
}
......@@ -480,33 +479,27 @@ function field_info_fieldable_types($obj_type = NULL) {
}
/**
* Return an array of fieldable bundle names and labels, for an individual
* object type or for all object types.
* Return information about existing bundles.
*
* @param $obj_type
* The type of object; e.g. 'node' or 'user'.
* @return
* An array of bundles for the $obj_type keyed by bundle name,
* or, if no $obj_type was provided, the array of all existing bundles,
* keyed by object type.
*/
function field_info_bundles($obj_type = NULL) {
$info = _field_info_collate_types();
$bundles = array();
foreach ($info['fieldable types'] as $type => $fieldable_info) {
if (empty($obj_type) || $obj_type == $type) {
$bundles += $fieldable_info['bundles'];
}
if ($obj_type) {
return isset($info['fieldable types'][$obj_type]['bundles']) ? $info['fieldable types'][$obj_type]['bundles'] : array();
}
return $bundles;
}
/**
* Identify the type of entity that created a bundle.
* // TODO : might not be needed depending on how we solve
* // the 'namespace bundle names' issue
*/
function field_info_bundle_entity($bundle) {
$info = _field_info_collate_types();
$bundles = array();
foreach ($info['fieldable types'] as $type => $fieldable_info) {
if (isset($fieldable_info['bundles'][$bundle])) {
return $type;
}
$bundles[$type] = $fieldable_info['bundles'];
}
return FALSE;
return $bundles;
}
/**
......@@ -593,30 +586,46 @@ function field_info_field_by_id($field_id) {
}
/**
* Return an array of instance data for a given bundle,
* or for all known bundles, keyed by bundle name and field name.
* Retrieve instances.
*
* @param $obj_type
* The object type for which to return instances.
* @param $bundle_name
* If set, return information on just this bundle.
* The bundle name for which to return instances.
* @return
* If $obj_type is not set, return all instances keyed by object type and
* bundle name. If $obj_type is set, return all instances for that object
* type, keyed by bundle name. If $obj_type and $bundle_name are set, return
* all instances for that bundle.
*/
function field_info_instances($bundle_name = NULL) {
function field_info_instances($obj_type, $bundle_name = NULL) {
$info = _field_info_collate_fields();
if (!isset($bundle_name)) {
if (!isset($obj_type)) {
return $info['instances'];
}
if (isset($info['instances'][$bundle_name])) {
return $info['instances'][$bundle_name];
if (!isset($bundle_name)) {
return $info['instances'][$obj_type];
}
if (isset($info['instances'][$obj_type][$bundle_name])) {
return $info['instances'][$obj_type][$bundle_name];
}
return array();
}
/**
* Return an array of instance data for a specific field and bundle.
*
* @param $obj_type
* The object type for the instance.
* @param $field_name
* The field name for the instance.
* @param $bundle_name
* The bundle name for the instance.
*/
function field_info_instance($field_name, $bundle_name) {
function field_info_instance($obj_type, $field_name, $bundle_name) {
$info = _field_info_collate_fields();
if (isset($info['instances'][$bundle_name][$field_name])) {
return $info['instances'][$bundle_name][$field_name];
if (isset($info['instances'][$obj_type][$bundle_name][$field_name])) {
return $info['instances'][$obj_type][$bundle_name][$field_name];
}
}
......
......@@ -130,6 +130,12 @@ function field_schema() {
'not null' => TRUE,
'default' => ''
),
'object_type' => array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => ''
),
'bundle' => array(
'type' => 'varchar',
'length' => 128,
......@@ -152,7 +158,7 @@ function field_schema() {
'primary key' => array('id'),
'indexes' => array(
// Used by field_delete_instance().
'field_name_bundle' => array('field_name', 'bundle'),
'field_name_bundle' => array('field_name', 'object_type', 'bundle'),
// Used by field_read_instances().
'deleted' => array('deleted'),
),
......
......@@ -507,7 +507,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
// We need $field, $instance, $obj_type, $object to be able to display a value...
list(, , $bundle) = field_extract_ids($obj_type, $object);
$instance = field_info_instance($field['field_name'], $bundle);
$instance = field_info_instance($obj_type, $field['field_name'], $bundle);
$display = array(
'type' => $formatter_type ? $formatter_type : $field_type['default_formatter'],
......@@ -521,6 +521,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$element = array(
'#theme' => $theme,
'#field_name' => $field['field_name'],
'#object_type' => $obj_type,
'#bundle' => $bundle,
'#formatter' => $display['type'],
'#settings' => $display['settings'],
......@@ -741,7 +742,7 @@ function field_create_stub_entity($obj_type, $ids) {
function template_preprocess_field(&$variables) {
$element = $variables['element'];
list(, , $bundle) = field_extract_ids($element['#object_type'], $element['#object']);
$instance = field_info_instance($element['#field_name'], $bundle);
$instance = field_info_instance($element['#object_type'], $element['#field_name'], $bundle);
$field = field_info_field($element['#field_name']);
$field_type_css = strtr($field['type'], '_', '-');
......
This diff is collapsed.
......@@ -436,7 +436,7 @@ function field_sql_storage_field_storage_delete($obj_type, $object, $fields) {
list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$etid = _field_sql_storage_etid($obj_type);
foreach (field_info_instances($bundle) as $instance) {
foreach (field_info_instances($obj_type, $bundle) as $instance) {
if (isset($fields[$instance['field_id']])) {
$field = field_info_field_by_id($instance['field_id']);
field_sql_storage_field_storage_purge($obj_type, $object, $field, $instance);
......@@ -609,15 +609,18 @@ function field_sql_storage_field_storage_delete_revision($obj_type, $object, $fi
* This function simply marks for deletion all data associated with the field.
*/
function field_sql_storage_field_storage_delete_instance($instance) {
$etid = _field_sql_storage_etid($instance['object_type']);
$field = field_info_field($instance['field_name']);
$table_name = _field_sql_storage_tablename($field);
$revision_name = _field_sql_storage_revision_tablename($field);
db_update($table_name)
->fields(array('deleted' => 1))
->condition('etid', $etid)
->condition('bundle', $instance['bundle'])
->execute();
db_update($revision_name)
->fields(array('deleted' => 1))
->