summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/field.api.php10
-rw-r--r--modules/field/field.attach.inc45
-rw-r--r--modules/field/field.crud.inc55
-rw-r--r--modules/field/field.default.inc2
-rw-r--r--modules/field/field.form.inc2
-rw-r--r--modules/field/field.info.inc85
-rw-r--r--modules/field/field.install8
-rw-r--r--modules/field/field.module5
-rw-r--r--modules/field/field.test122
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.module12
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.test7
-rw-r--r--modules/field/modules/number/number.module11
-rw-r--r--modules/field/modules/options/options.module6
-rw-r--r--modules/field/modules/text/text.module4
-rw-r--r--modules/field/modules/text/text.test3
15 files changed, 227 insertions, 150 deletions
diff --git a/modules/field/field.api.php b/modules/field/field.api.php
index 84a9b07e9..ee80409a8 100644
--- a/modules/field/field.api.php
+++ b/modules/field/field.api.php
@@ -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) {
}
/**
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 4118a60e1..2bf38e457 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -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);
}
}
diff --git a/modules/field/field.crud.inc b/modules/field/field.crud.inc
index 487a44dfa..68bcd06ca 100644
--- a/modules/field/field.crud.inc
+++ b/modules/field/field.crud.inc
@@ -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();
diff --git a/modules/field/field.default.inc b/modules/field/field.default.inc
index 10f3f7bc1..31d5732c4 100644
--- a/modules/field/field.default.inc
+++ b/modules/field/field.default.inc
@@ -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(
diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc
index 581869278..1f4c6a94f 100644
--- a/modules/field/field.form.inc
+++ b/modules/field/field.form.inc
@@ -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'],
);
diff --git a/modules/field/field.info.inc b/modules/field/field.info.inc
index 68291838e..5f929a822 100644
--- a/modules/field/field.info.inc
+++ b/modules/field/field.info.inc
@@ -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];
}
}
diff --git a/modules/field/field.install b/modules/field/field.install
index 2ee9daa12..33d29c065 100644
--- a/modules/field/field.install
+++ b/modules/field/field.install
@@ -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'),
),
diff --git a/modules/field/field.module b/modules/field/field.module
index 0a14e084d..edc20c243 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -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'], '_', '-');
diff --git a/modules/field/field.test b/modules/field/field.test
index 1fd410e78..c425585bb 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -51,6 +51,7 @@ class FieldAttachTestCase extends FieldTestCase {
$this->field_id = $this->field['id'];
$this->instance = array(
'field_name' => $this->field_name,
+ 'object_type' => 'test_entity',
'bundle' => 'test_bundle',
'label' => $this->randomName() . '_label',
'description' => $this->randomName() . '_description',
@@ -179,6 +180,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
foreach ($field_bundles_map[$i] as $bundle) {
$instance = array(
'field_name' => $field_names[$i],
+ 'object_type' => 'test_entity',
'bundle' => $bundles[$bundle],
'settings' => array(
// Configure the instance so that we test hook_field_load()
@@ -194,7 +196,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
foreach ($bundles as $index => $bundle) {
$entities[$index] = field_test_create_stub_entity($index, $index, $bundle);
$entity = clone($entities[$index]);
- $instances = field_info_instances($bundle);
+ $instances = field_info_instances('test_entity', $bundle);
foreach ($instances as $field_name => $instance) {
$values[$index][$field_name] = mt_rand(1, 127);
$entity->$field_name = array($langcode => array(array('value' => $values[$index][$field_name])));
@@ -205,7 +207,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
// Check that a single load correctly loads field values for both entities.
field_attach_load($entity_type, $entities);
foreach ($entities as $index => $entity) {
- $instances = field_info_instances($bundles[$index]);
+ $instances = field_info_instances($entity_type, $bundles[$index]);
foreach ($instances as $field_name => $instance) {
// The field value loaded matches the one inserted.
$this->assertEqual($entity->{$field_name}[$langcode][0]['value'], $values[$index][$field_name], t('Entity %index: expected value was found.', array('%index' => $index)));
@@ -249,6 +251,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
field_create_field($field);
$instance = array(
'field_name' => $field['field_name'],
+ 'object_type' => 'test_entity',
'bundle' => 'test_bundle',
);
field_create_instance($instance);
@@ -289,12 +292,13 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
$field = field_create_field($field);
$instance = array(
'field_name' => $field_name,
+ 'object_type' => 'test_entity',
'bundle' => 'test_bundle',
);
field_create_instance($instance);
$field = field_info_field($instance['field_name']);
- $instance = field_info_instance($instance['field_name'], $instance['bundle']);
+ $instance = field_info_instance($instance['object_type'], $instance['field_name'], $instance['bundle']);
// The storage details are indexed by a storage engine type.
$this->assertTrue(array_key_exists('drupal_variables', $instance['storage_details']), t('The storage type is Drupal variables.'));
@@ -511,7 +515,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
field_test_rename_bundle($this->instance['bundle'], $new_bundle);
// Check that the instance definition has been updated.
- $this->instance = field_info_instance($this->field_name, $new_bundle);
+ $this->instance = field_info_instance($entity_type, $this->field_name, $new_bundle);
$this->assertIdentical($this->instance['bundle'], $new_bundle, "Bundle name has been updated in the instance.");
// Verify the field data is present on load.
@@ -539,6 +543,7 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
field_create_field($field);
$instance = array(
'field_name' => $field_name,
+ 'object_type' => 'test_entity',
'bundle' => $this->instance['bundle'],
'label' => $this->randomName() . '_label',
'description' => $this->randomName() . '_description',
@@ -556,12 +561,11 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity->{$this->field_name}[$langcode] = $values;
$entity->{$field_name}[$langcode] = $this->_generateTestFieldValues(1);
- $entity_type = 'test_entity';
- field_attach_insert($entity_type, $entity);
+ field_attach_insert('test_entity', $entity);
// Verify the fields are present on load
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
- field_attach_load($entity_type, array(0 => $entity));
+ field_attach_load('test_entity', array(0 => $entity));
$this->assertEqual(count($entity->{$this->field_name}[$langcode]), 4, 'First field got loaded');
$this->assertEqual(count($entity->{$field_name}[$langcode]), 1, 'Second field got loaded');
@@ -571,13 +575,13 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
// Verify no data gets loaded
$entity = field_test_create_stub_entity(0, 0, $this->instance['bundle']);
- field_attach_load($entity_type, array(0 => $entity));
+ field_attach_load('test_entity', array(0 => $entity));
$this->assertFalse(isset($entity->{$this->field_name}[$langcode]), 'No data for first field');
$this->assertFalse(isset($entity->{$field_name}[$langcode]), 'No data for second field');
// Verify that the instances are gone
- $this->assertFalse(field_read_instance($this->field_name, $this->instance['bundle']), "First field is deleted");
- $this->assertFalse(field_read_instance($field_name, $instance['bundle']), "Second field is deleted");
+ $this->assertFalse(field_read_instance('test_entity', $this->field_name, $this->instance['bundle']), "First field is deleted");
+ $this->assertFalse(field_read_instance('test_entity', $field_name, $instance['bundle']), "Second field is deleted");
}
/**
@@ -593,6 +597,14 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
$this->instance2['bundle'] = 'test_bundle_1';
field_create_instance($this->instance2);
+ // Create instances of both fields on the second entity type.
+ $instance = $this->instance;
+ $instance['object_type'] = 'test_cacheable_entity';
+ field_create_instance($instance);
+ $instance2 = $this->instance2;
+ $instance2['object_type'] = 'test_cacheable_entity';
+ field_create_instance($instance2);
+
// Create two test objects, using two different types and bundles.
$entity_types = array(1 => 'test_entity', 2 => 'test_cacheable_entity');
$entities = array(1 => field_test_create_stub_entity(1, 1, 'test_bundle'), 2 => field_test_create_stub_entity(2, 2, 'test_bundle_1'));
@@ -876,12 +888,9 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
$langcode = FIELD_LANGUAGE_NONE;
$values = $this->_generateTestFieldValues($this->field['cardinality']);
- $noncached_type = 'test_entity';
- $cached_type = 'test_cacheable_entity';
-
-
// Non-cacheable entity type.
- $cid = "field:$noncached_type:{$entity_init->ftid}";
+ $entity_type = 'test_entity';
+ $cid = "field:$entity_type:{$entity_init->ftid}";
// Check that no initial cache entry is present.
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no initial cache entry'));
@@ -889,17 +898,21 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name}[$langcode] = $values;
- field_attach_insert($noncached_type, $entity);
+ field_attach_insert($entity_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no cache entry on insert'));
// Load, and check that no cache entry is present.
$entity = clone($entity_init);
- field_attach_load($noncached_type, array($entity->ftid => $entity));
+ field_attach_load($entity_type, array($entity->ftid => $entity));
$this->assertFalse(cache_get($cid, 'cache_field'), t('Non-cached: no cache entry on load'));
// Cacheable entity type.
- $cid = "field:$cached_type:{$entity_init->ftid}";
+ $entity_type = 'test_cacheable_entity';
+ $cid = "field:$entity_type:{$entity_init->ftid}";
+ $instance = $this->instance;
+ $instance['object_type'] = $entity_type;
+ field_create_instance($instance);
// Check that no initial cache entry is present.
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no initial cache entry'));
@@ -907,18 +920,18 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
// Save, and check that no cache entry is present.
$entity = clone($entity_init);
$entity->{$this->field_name}[$langcode] = $values;
- field_attach_insert($cached_type, $entity);
+ field_attach_insert($entity_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on insert'));
// Load a single field, and check that no cache entry is present.
$entity = clone($entity_init);
- field_attach_load($cached_type, array($entity->ftid => $entity), FIELD_LOAD_CURRENT, array('field_id' => $this->field_id));
+ field_attach_load($entity_type, array($entity->ftid => $entity), FIELD_LOAD_CURRENT, array('field_id' => $this->field_id));
$cache = cache_get($cid, 'cache_field');
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on loading a single field'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
- field_attach_load($cached_type, array($entity->ftid => $entity));
+ field_attach_load($entity_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name][$langcode], $values, t('Cached: correct cache entry on load'));
@@ -926,12 +939,12 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity = clone($entity_init);
$entity->{$this->field_name}[$langcode] = $values;
- field_attach_update($cached_type, $entity);
+ field_attach_update($entity_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on update'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
- field_attach_load($cached_type, array($entity->ftid => $entity));
+ field_attach_load($entity_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name][$langcode], $values, t('Cached: correct cache entry on load'));
@@ -940,18 +953,18 @@ class FieldAttachOtherTestCase extends FieldAttachTestCase {
$values = $this->_generateTestFieldValues($this->field['cardinality']);
$entity = clone($entity_init);
$entity->{$this->field_name}[$langcode] = $values;
- field_attach_update($cached_type, $entity);
+ field_attach_update($entity_type, $entity);
$cache = cache_get($cid, 'cache_field');
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry on new revision creation'));
// Load, and check that a cache entry is present with the expected values.
$entity = clone($entity_init);
- field_attach_load($cached_type, array($entity->ftid => $entity));
+ field_attach_load($entity_type, array($entity->ftid => $entity));
$cache = cache_get($cid, 'cache_field');
$this->assertEqual($cache->data[$this->field_name][$langcode], $values, t('Cached: correct cache entry on load'));
// Delete, and check that the cache entry is wiped.
- field_attach_delete($cached_type, $entity);
+ field_attach_delete($entity_type, $entity);
$this->assertFalse(cache_get($cid, 'cache_field'), t('Cached: no cache entry after delete'));
}
@@ -1116,7 +1129,7 @@ class FieldInfoTestCase extends FieldTestCase {
// Verify that no unexpected instances exist.
$core_fields = field_info_fields();
- $instances = field_info_instances(FIELD_TEST_BUNDLE);
+ $instances = field_info_instances('test_entity', FIELD_TEST_BUNDLE);
$this->assertTrue(empty($instances), t('With no instances, info bundles is empty.'));
// Create a field, verify it shows up.
@@ -1140,6 +1153,7 @@ class FieldInfoTestCase extends FieldTestCase {
// Create an instance, verify that it shows up
$instance = array(
'field_name' => $field['field_name'],
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
'label' => $this->randomName(),
'description' => $this->randomName(),
@@ -1151,7 +1165,7 @@ class FieldInfoTestCase extends FieldTestCase {
'test_setting' => 999)));
field_create_instance($instance);
- $instances = field_info_instances($instance['bundle']);
+ $instances = field_info_instances('test_entity', $instance['bundle']);
$this->assertEqual(count($instances), 1, t('One instance shows up in info when attached to a bundle.'));
$this->assertTrue($instance < $instances[$instance['field_name']], t('Instance appears in info correctly'));
}
@@ -1198,6 +1212,7 @@ class FieldInfoTestCase extends FieldTestCase {
field_create_field($field_definition);
$instance_definition = array(
'field_name' => $field_definition['field_name'],
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
);
field_create_instance($instance_definition);
@@ -1221,7 +1236,7 @@ class FieldInfoTestCase extends FieldTestCase {
field_cache_clear();
// Read the instance back.
- $instance = field_info_instance($instance_definition['field_name'], $instance_definition['bundle']);
+ $instance = field_info_instance($instance_definition['object_type'], $instance_definition['field_name'], $instance_definition['bundle']);
// Check that all expected instance settings are in place.
$field_type = field_info_field_types($field_definition['type']);
@@ -1282,6 +1297,7 @@ class FieldFormTestCase extends FieldTestCase {
$this->field_unlimited = array('field_name' => drupal_strtolower($this->randomName()), 'type' => 'test_field', 'cardinality' => FIELD_CARDINALITY_UNLIMITED);
$this->instance = array(
+ 'object_type' => 'test_entity',
'bundle' => 'test_bundle',
'label' => $this->randomName() . '_label',
'description' => $this->randomName() . '_description',
@@ -1795,6 +1811,7 @@ class FieldCrudTestCase extends FieldTestCase {
// Create instances for each.
$this->instance_definition = array(
'field_name' => $this->field['field_name'],
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
'widget' => array(
'type' => 'test_field_widget',
@@ -1817,7 +1834,7 @@ class FieldCrudTestCase extends FieldTestCase {
// Make sure that this field's instance is marked as deleted when it is
// specifically loaded.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance['deleted']), t('An instance for a deleted field is marked for deletion.'));
// Try to load the field normally and make sure it does not show up.
@@ -1825,13 +1842,13 @@ class FieldCrudTestCase extends FieldTestCase {
$this->assertTrue(empty($field), t('A deleted field is not loaded by default.'));
// Try to load the instance normally and make sure it does not show up.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(empty($instance), t('An instance for a deleted field is not loaded by default.'));
// Make sure the other field (and its field instance) are not deleted.
$another_field = field_read_field($this->another_field['field_name']);
$this->assertTrue(!empty($another_field) && empty($another_field['deleted']), t('A non-deleted field is not marked for deletion.'));
- $another_instance = field_read_instance($this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
+ $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
$this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), t('An instance of a non-deleted field is not marked for deletion.'));
// Try to create a new field the same name as a deleted field and
@@ -1840,7 +1857,7 @@ class FieldCrudTestCase extends FieldTestCase {
field_create_instance($this->instance_definition);
$field = field_read_field($this->field['field_name']);
$this->assertTrue(!empty($field) && empty($field['deleted']), t('A new field with a previously used name is created.'));
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new instance for a previously used field name is created.'));
// Save an object with data for the field
@@ -1849,7 +1866,7 @@ class FieldCrudTestCase extends FieldTestCase {
$values[0]['value'] = mt_rand(1, 127);
$entity->{$field['field_name']}[$langcode] = $values;
$entity_type = 'test_entity';
- field_attach_insert($entity_type, $entity);
+ field_attach_insert('test_entity', $entity);
// Verify the field is present on load
$entity = field_test_create_stub_entity(0, 0, $this->instance_definition['bundle']);
@@ -1892,7 +1909,7 @@ class FieldCrudTestCase extends FieldTestCase {
// Create a decimal 5.2 field.
$field = array('field_name' => 'decimal53', 'type' => 'number_decimal', 'cardinality' => 3, 'settings' => array('precision' => 5, 'scale' => 2));
$field = field_create_field($field);
- $instance = array('field_name' => 'decimal53', 'bundle' => FIELD_TEST_BUNDLE);
+ $instance = array('field_name' => 'decimal53', 'object_type' => 'test_entity', 'bundle' => FIELD_TEST_BUNDLE);
$instance = field_create_instance($instance);
// Update it to a deciaml 5.3 field.
@@ -2023,6 +2040,8 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
field_create_field($this->field);
$this->instance_definition = array(
'field_name' => $this->field['field_name'],
+ 'object_type' => 'test_entity',
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
);
}
@@ -2044,7 +2063,6 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$record = $result->fetchAssoc();
$record['data'] = unserialize($record['data']);
- //$instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
$field_type = field_info_field_types($this->field['type']);
$widget_type = field_info_widget_types($field_type['default_widget']);
$formatter_type = field_info_formatter_types($field_type['default_formatter']);
@@ -2091,7 +2109,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
field_create_instance($this->instance_definition);
// Read the instance back.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue($this->instance_definition < $instance, t('The field was properly read.'));
}
@@ -2103,7 +2121,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$field_type = field_info_field_types($this->field['type']);
// Check that basic changes are saved.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance['required'] = !$instance['required'];
$instance['label'] = $this->randomName();
$instance['description'] = $this->randomName();
@@ -2114,7 +2132,7 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$instance['display']['full']['weight']++;
field_update_instance($instance);
- $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertEqual($instance['required'], $instance_new['required'], t('"required" change is saved'));
$this->assertEqual($instance['label'], $instance_new['label'], t('"label" change is saved'));
$this->assertEqual($instance['description'], $instance_new['description'], t('"description" change is saved'));
@@ -2124,12 +2142,12 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$this->assertEqual($instance['display']['full']['weight'], $instance_new['display']['full']['weight'], t('Widget weight change is saved'));
// Check that changing widget and formatter types updates the default settings.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance['widget']['type'] = 'test_field_widget_multiple';
$instance['display']['full']['type'] = 'field_test_multiple';
field_update_instance($instance);
- $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertEqual($instance['widget']['type'], $instance_new['widget']['type'] , t('Widget type change is saved.'));
$settings = field_info_widget_settings($instance_new['widget']['type']);
$this->assertIdentical($settings, array_intersect_key($instance_new['widget']['settings'], $settings) , t('Widget type change updates default settings.'));
@@ -2139,11 +2157,11 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$this->assertIdentical($settings, array_intersect_key($instance_new['display']['full']['settings'], $settings) , t('Changing formatter type updates default settings.'));
// Check that adding a new build mode is saved and gets default settings.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$instance['display']['teaser'] = array();
field_update_instance($instance);
- $instance_new = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance_new = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(isset($instance_new['display']['teaser']), t('Display for the new build_mode has been written.'));
$this->assertIdentical($instance_new['display']['teaser']['type'], $field_type['default_formatter'], t('Default formatter for the new build_mode has been written.'));
$info = field_info_formatter_types($instance_new['display']['teaser']['type']);
@@ -2169,21 +2187,21 @@ class FieldInstanceCrudTestCase extends FieldTestCase {
$instance = field_create_instance($this->another_instance_definition);
// Test that the first instance is not deleted, and then delete it.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance) && empty($instance['deleted']), t('A new field instance is not marked for deletion.'));
field_delete_instance($instance);
// Make sure the instance is marked as deleted when the instance is
// specifically loaded.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle'], array('include_deleted' => TRUE));
$this->assertTrue(!empty($instance['deleted']), t('A deleted field instance is marked for deletion.'));
// Try to load the instance normally and make sure it does not show up.
- $instance = field_read_instance($this->instance_definition['field_name'], $this->instance_definition['bundle']);
+ $instance = field_read_instance('test_entity', $this->instance_definition['field_name'], $this->instance_definition['bundle']);
$this->assertTrue(empty($instance), t('A deleted field instance is not loaded by default.'));
// Make sure the other field instance is not deleted.
- $another_instance = field_read_instance($this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
+ $another_instance = field_read_instance('test_entity', $this->another_instance_definition['field_name'], $this->another_instance_definition['bundle']);
$this->assertTrue(!empty($another_instance) && empty($another_instance['deleted']), t('A non-deleted field instance is not marked for deletion.'));
}
}
@@ -2225,6 +2243,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
$instance = array(
'field_name' => $this->field_name,
+ 'object_type' => $this->obj_type,
'bundle' => 'test_bundle',
'label' => $this->randomName() . '_label',
'description' => $this->randomName() . '_description',
@@ -2241,7 +2260,7 @@ class FieldTranslationsTestCase extends FieldTestCase {
),
);
field_create_instance($instance);
- $this->instance = field_read_instance($this->field_name, 'test_bundle');
+ $this->instance = field_read_instance('test_entity', $this->field_name, 'test_bundle');
for ($i = 0; $i < 3; ++$i) {
locale_inc_callback('locale_add_language', 'l' . $i, $this->randomString(), $this->randomString());
@@ -2493,6 +2512,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
foreach ($this->fields as $field) {
$instance = array(
'field_name' => $field['field_name'],
+ 'object_type' => $this->entity_type,
'bundle' => $bundle,
'widget' => array(
'type' => 'test_field_widget',
@@ -2531,7 +2551,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
$this->assertEqual(count($found['test_entity']), 10, 'Correct number of objects found before deleting');
// Delete the instance.
- $instance = field_info_instance($field['field_name'], $bundle);
+ $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle);
field_delete_instance($instance);
// The instance still exists, deleted.
@@ -2564,7 +2584,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
$field = reset($this->fields);
// Delete the instance.
- $instance = field_info_instance($field['field_name'], $bundle);
+ $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle);
field_delete_instance($instance);
// No field hooks were called.
@@ -2620,7 +2640,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
foreach ($this->bundles as $bundle) {
// Delete the instance.
- $instance = field_info_instance($field['field_name'], $bundle);
+ $instance = field_info_instance($this->entity_type, $field['field_name'], $bundle);
field_delete_instance($instance);
// Purge the data.
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.module b/modules/field/modules/field_sql_storage/field_sql_storage.module
index 81318a581..76caa2634 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -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))
+ ->condition('etid', $etid)
->condition('bundle', $instance['bundle'])
->execute();
}
@@ -625,9 +628,10 @@ function field_sql_storage_field_storage_delete_instance($instance) {
/**
* Implement hook_field_attach_rename_bundle().
*/
-function field_sql_storage_field_attach_rename_bundle($bundle_old, $bundle_new) {
+function field_sql_storage_field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
+ $etid = _field_sql_storage_etid($obj_type);
// We need to account for deleted or inactive fields and instances.
- $instances = field_read_instances(array('bundle' => $bundle_new), array('include_deleted' => TRUE, 'include_inactive' => TRUE));
+ $instances = field_read_instances(array('object_type' => $obj_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') {
@@ -635,10 +639,12 @@ function field_sql_storage_field_attach_rename_bundle($bundle_old, $bundle_new)
$revision_name = _field_sql_storage_revision_tablename($field);
db_update($table_name)
->fields(array('bundle' => $bundle_new))
+ ->condition('etid', $etid)
->condition('bundle', $bundle_old)
->execute();
db_update($revision_name)
->fields(array('bundle' => $bundle_new))
+ ->condition('etid', $etid)
->condition('bundle', $bundle_old)
->execute();
}
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.test b/modules/field/modules/field_sql_storage/field_sql_storage.test
index f7dc4bb62..221c2e191 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.test
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.test
@@ -28,6 +28,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$this->field = field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
+ 'object_type' => 'test_entity',
'bundle' => 'test_bundle'
);
$this->instance = field_create_instance($this->instance);
@@ -302,7 +303,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
// Create a decimal 5.2 field and add some data.
$field = array('field_name' => 'decimal52', 'type' => 'number_decimal', 'settings' => array('precision' => 5, 'scale' => 2));
$field = field_create_field($field);
- $instance = array('field_name' => 'decimal52', 'bundle' => FIELD_TEST_BUNDLE);
+ $instance = array('field_name' => 'decimal52', 'object_type' => 'test_entity', 'bundle' => FIELD_TEST_BUNDLE);
$instance = field_create_instance($instance);
$entity = field_test_create_stub_entity(0, 0, $instance['bundle']);
$entity->decimal52[FIELD_LANGUAGE_NONE][0]['value'] = '1.235';
@@ -330,7 +331,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$field_name = 'testfield';
$field = array('field_name' => $field_name, 'type' => 'text');
$field = field_create_field($field);
- $instance = array('field_name' => $field_name, 'bundle' => FIELD_TEST_BUNDLE);
+ $instance = array('field_name' => $field_name, 'object_type' => 'test_entity', 'bundle' => FIELD_TEST_BUNDLE);
$instance = field_create_instance($instance);
$tables = array(_field_sql_storage_tablename($field), _field_sql_storage_revision_tablename($field));
@@ -379,7 +380,7 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
// Retrieve the field and instance with field_info so the storage details are attached.
$field = field_info_field($this->field['field_name']);
- $instance = field_info_instance($this->instance['field_name'], $this->instance['bundle']);
+ $instance = field_info_instance($this->instance['object_type'], $this->instance['field_name'], $this->instance['bundle']);
// The storage details are indexed by a storage engine type.
$this->assertTrue(array_key_exists('sql', $instance['storage_details']), t('The storage type is SQL.'));
diff --git a/modules/field/modules/number/number.module b/modules/field/modules/number/number.module
index 3d3b0c845..54c44fec6 100644
--- a/modules/field/modules/number/number.module
+++ b/modules/field/modules/number/number.module
@@ -253,7 +253,7 @@ function theme_field_formatter_number_unformatted($variables) {
function theme_field_formatter_number($variables) {
$element = $variables['element'];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$value = $element['#item']['value'];
$settings = $element['#settings'];
$formatter_type = $element['#formatter'];
@@ -368,7 +368,7 @@ function number_field_widget_error($element, $error) {
function number_elements_process($element, $form_state, $form) {
$field_name = $element['#field_name'];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$field_key = $element['#columns'][0];
$value = isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : '';
@@ -390,6 +390,7 @@ function number_elements_process($element, $form_state, $form) {
'#description' => $element['#description'],
'#required' => $element['#required'],
'#field_name' => $element['#field_name'],
+ '#object_type' => $element['#object_type'],
'#bundle' => $element['#bundle'],
'#delta' => $element['#delta'],
'#columns' => $element['#columns'],
@@ -428,7 +429,7 @@ function number_elements_process($element, $form_state, $form) {
*/
function number_float_validate($element, &$form_state) {
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$field_key = $element['#columns'][0];
$value = $element['#value'][$field_key];
@@ -450,7 +451,7 @@ function number_float_validate($element, &$form_state) {
*/
function number_integer_validate($element, &$form_state) {
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$field_key = $element['#columns'][0];
$value = $element['#value'][$field_key];
@@ -472,7 +473,7 @@ function number_integer_validate($element, &$form_state) {
*/
function number_decimal_validate($element, &$form_state) {
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$field_key = $element['#columns'][0];
$value = $element['#value'][$field_key];
diff --git a/modules/field/modules/options/options.module b/modules/field/modules/options/options.module
index 53bec62c7..743d92454 100644
--- a/modules/field/modules/options/options.module
+++ b/modules/field/modules/options/options.module
@@ -284,8 +284,8 @@ function options_validate($element, &$form_state) {
function options_data2form($element, $items, $field) {
$field_key = $element['#columns'][0];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
- $options = options_options($field, $instance);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
+ $options = options_options($field, $instance);
$items_transposed = options_transpose_array_rows_cols($items);
$values = (isset($items_transposed[$field_key]) && is_array($items_transposed[$field_key])) ? $items_transposed[$field_key] : array();
@@ -312,7 +312,7 @@ function options_data2form($element, $items, $field) {
function options_form2data($element, $field) {
$field_key = $element['#columns'][0];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
$items = (array) $element[$field_key]['#value'];
$options = options_options($field, $instance);
diff --git a/modules/field/modules/text/text.module b/modules/field/modules/text/text.module
index 0579a8bcf..cf53d27da 100644
--- a/modules/field/modules/text/text.module
+++ b/modules/field/modules/text/text.module
@@ -318,7 +318,7 @@ function theme_field_formatter_text_plain($variables) {
function theme_field_formatter_text_trimmed($variables) {
$element = $variables['element'];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
return text_summary($element['#item']['safe'], $instance['settings']['text_processing'] ? $element['#item']['format'] : NULL);
}
@@ -331,7 +331,7 @@ function theme_field_formatter_text_trimmed($variables) {
function theme_field_formatter_text_summary_or_trimmed($variables) {
$element = $variables['element'];
$field = field_info_field($element['#field_name']);
- $instance = field_info_instance($element['#field_name'], $element['#bundle']);
+ $instance = field_info_instance($element['#object_type'], $element['#field_name'], $element['#bundle']);
if (!empty($element['#item']['safe_summary'])) {
return $element['#item']['safe_summary'];
diff --git a/modules/field/modules/text/text.test b/modules/field/modules/text/text.test
index 5388069bf..b4cc4dfef 100644
--- a/modules/field/modules/text/text.test
+++ b/modules/field/modules/text/text.test
@@ -40,6 +40,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
'widget' => array(
'type' => 'text_textfield',
@@ -85,6 +86,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
'label' => $this->randomName() . '_label',
'settings' => array(
@@ -138,6 +140,7 @@ class TextFieldTestCase extends DrupalWebTestCase {
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field_name,
+ 'object_type' => 'test_entity',
'bundle' => FIELD_TEST_BUNDLE,
'label' => $this->randomName() . '_label',
'settings' => array(