diff options
author | Dries Buytaert <dries@buytaert.net> | 2009-10-15 12:44:36 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2009-10-15 12:44:36 +0000 |
commit | 714597a9cdb42c3ca0df843f7f6a7351c6e06e39 (patch) | |
tree | 4e42239768111673ec7e8ae3181e7fa7339937c4 | |
parent | 35e21e54e1122f98bede28f89d80f2fb13b3fd97 (diff) | |
download | brdo-714597a9cdb42c3ca0df843f7f6a7351c6e06e39.tar.gz brdo-714597a9cdb42c3ca0df843f7f6a7351c6e06e39.tar.bz2 |
- Patch #470242 by yched, bjaspan: fixed namespacing for bundle names to avoid users rendering their site unusable.
31 files changed, 350 insertions, 240 deletions
diff --git a/modules/comment/comment.install b/modules/comment/comment.install index c5d78e1b3..454d6e16a 100644 --- a/modules/comment/comment.install +++ b/modules/comment/comment.install @@ -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); } } diff --git a/modules/comment/comment.module b/modules/comment/comment.module index c18e4ed44..431a9daaf 100644 --- a/modules/comment/comment.module +++ b/modules/comment/comment.module @@ -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', 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( diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc index f48e03db5..4b68e1428 100644 --- a/modules/field_ui/field_ui.admin.inc +++ b/modules/field_ui/field_ui.admin.inc @@ -15,14 +15,16 @@ function field_ui_fields_list() { $bundles = field_info_bundles(); $header = array(t('Field name'), t('Field type'), t('Used in')); $rows = array(); - foreach ($instances as $bundle => $info) { - foreach ($info as $field_name => $instance) { - $field = field_info_field($field_name); - $admin_path = _field_ui_bundle_admin_path($bundle); - $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; - $rows[$field_name]['data'][1] = t($field_types[$field['type']]['label']); - $rows[$field_name]['data'][2][] = l($bundles[$bundle]['label'], $admin_path . '/fields'); - $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array(''); + foreach ($instances as $obj_type => $bundles) { + foreach ($bundles as $bundle => $info) { + foreach ($info as $field_name => $instance) { + $field = field_info_field($field_name); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); + $rows[$field_name]['data'][0] = $field['locked'] ? t('@field_name (Locked)', array('@field_name' => $field_name)) : $field_name; + $rows[$field_name]['data'][1] = t($field_types[$field['type']]['label']); + $rows[$field_name]['data'][2][] = l($bundles[$bundle]['label'], $admin_path . '/fields'); + $rows[$field_name]['class'] = $field['locked'] ? array('menu-disabled') : array(''); + } } } foreach ($rows as $field_name => $cell) { @@ -42,8 +44,8 @@ function field_ui_fields_list() { /** * Helper function to display a message about inactive fields. */ -function field_ui_inactive_message($bundle) { - $inactive_instances = field_ui_inactive_instances($bundle); +function field_ui_inactive_message($obj_type, $bundle) { + $inactive_instances = field_ui_inactive_instances($obj_type, $bundle); if (!empty($inactive_instances)) { $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); @@ -68,8 +70,8 @@ function field_ui_inactive_message($bundle) { function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) { $bundle = field_extract_bundle($obj_type, $bundle); - field_ui_inactive_message($bundle); - $admin_path = _field_ui_bundle_admin_path($bundle); + field_ui_inactive_message($obj_type, $bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); // When displaying the form, make sure the list of fields is up-to-date. if (empty($form_state['post'])) { @@ -77,7 +79,7 @@ function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) { } // Gather bundle information. - $instances = field_info_instances($bundle); + $instances = field_info_instances($obj_type, $bundle); $field_types = field_info_field_types(); $widget_types = field_info_widget_types(); @@ -88,6 +90,7 @@ function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) { $form += array( '#tree' => TRUE, + '#object_type' => $obj_type, '#bundle' => $bundle, '#fields' => array_keys($instances), '#extra' => array_keys($extra), @@ -223,7 +226,7 @@ function field_ui_field_overview_form($form, &$form_state, $obj_type, $bundle) { } // Additional row: add existing field. - $existing_field_options = field_ui_existing_field_options($bundle); + $existing_field_options = field_ui_existing_field_options($obj_type, $bundle); if ($existing_field_options && $widget_type_options) { $weight++; array_unshift($existing_field_options, t('- Select an existing field -')); @@ -274,9 +277,9 @@ function template_preprocess_field_ui_field_overview_form(&$vars) { drupal_add_js(drupal_get_path('module', 'field_ui') . '/field_ui.js'); // Add settings for the update selects behavior. $js_fields = array(); - foreach (field_ui_existing_field_options($form['#bundle']) as $field_name => $fields) { + foreach (field_ui_existing_field_options($form['#object_type'], $form['#bundle']) as $field_name => $fields) { $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $form['#bundle']); + $instance = field_info_instance($form['#object_type'], $field_name, $form['#bundle']); $js_fields[$field_name] = array('label' => $instance['label'], 'type' => $field['type'], 'widget' => $instance['widget']['type']); } drupal_add_js(array('fieldWidgetTypes' => field_ui_widget_type_options(), 'fields' => $js_fields), 'setting'); @@ -444,14 +447,15 @@ function _field_ui_field_overview_form_validate_add_existing($form, &$form_state */ function field_ui_field_overview_form_submit($form, &$form_state) { $form_values = $form_state['values']; + $obj_type = $form['#object_type']; $bundle = $form['#bundle']; - $admin_path = _field_ui_bundle_admin_path($bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); // Update field weights. $extra = array(); foreach ($form_values as $key => $values) { if (in_array($key, $form['#fields'])) { - $instance = field_read_instance($key, $bundle); + $instance = field_read_instance($obj_type, $key, $bundle); $instance['widget']['weight'] = $values['weight']; foreach($instance['display'] as $build_mode => $display) { $instance['display'][$build_mode]['weight'] = $values['weight']; @@ -484,6 +488,7 @@ function field_ui_field_overview_form_submit($form, &$form_state) { ); $instance = array( 'field_name' => $field['field_name'], + 'object_type' => $obj_type, 'bundle' => $bundle, 'label' => $values['label'], 'widget' => array( @@ -555,17 +560,17 @@ function field_ui_field_overview_form_submit($form, &$form_state) { function field_ui_display_overview_form($form, &$form_state, $obj_type, $bundle, $build_modes_selector = 'basic') { $bundle = field_extract_bundle($obj_type, $bundle); - field_ui_inactive_message($bundle); - $admin_path = _field_ui_bundle_admin_path($bundle); + field_ui_inactive_message($obj_type, $bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); // Gather type information. - $entity = field_info_bundle_entity($bundle); - $instances = field_info_instances($bundle); + $instances = field_info_instances($obj_type, $bundle); $field_types = field_info_field_types(); - $build_modes = field_ui_build_modes_tabs($entity, $build_modes_selector); + $build_modes = field_ui_build_modes_tabs($obj_type, $build_modes_selector); $form += array( '#tree' => TRUE, + '#object_type' => $obj_type, '#bundle' => $bundle, '#fields' => array_keys($instances), '#contexts' => $build_modes_selector, @@ -621,7 +626,7 @@ function template_preprocess_field_ui_display_overview_form(&$vars) { $form = &$vars['form']; $contexts_selector = $form['#contexts']; - $vars['contexts'] = field_ui_build_modes_tabs(field_info_bundle_entity($form['#bundle']), $contexts_selector); + $vars['contexts'] = field_ui_build_modes_tabs($form['#object_type'], $contexts_selector); $order = _field_ui_overview_order($form, $form['#fields']); if (empty($order)) { @@ -657,7 +662,7 @@ function field_ui_display_overview_form_submit($form, &$form_state) { $form_values = $form_state['values']; foreach ($form_values as $key => $values) { if (in_array($key, $form['#fields'])) { - $instance = field_info_instance($key, $form['#bundle']); + $instance = field_info_instance($form['#object_type'], $key, $form['#bundle']); foreach ($instance['display'] as $build_mode => $display) { if (isset($values[$build_mode])) { $instance['display'][$build_mode] = array_merge($instance['display'][$build_mode], $values[$build_mode]); @@ -757,16 +762,16 @@ function field_ui_formatter_options($field_type = NULL) { /** * Return an array of existing field to be added to a bundle. */ -function field_ui_existing_field_options($bundle) { +function field_ui_existing_field_options($obj_type, $bundle) { $options = array(); $field_types = field_info_field_types(); - foreach (field_info_instances() as $bundle_name => $instances) { + foreach (field_info_instances($obj_type) as $bundle_name => $instances) { // No need to look in the current bundle. if ($bundle_name != $bundle) { foreach ($instances as $instance) { $field = field_info_field($instance['field_name']); // Don't show locked fields or fields already in the current bundle. - if (empty($field['locked']) && !field_info_instance($field['field_name'], $bundle)) { + if (empty($field['locked']) && !field_info_instance($obj_type, $field['field_name'], $bundle)) { $text = t('@type: @field (@label)', array( '@type' => $field_types[$field['type']]['label'], '@label' => t($instance['label']), '@field' => $instance['field_name'], @@ -847,6 +852,7 @@ function field_ui_field_settings_form($form, &$form_state, $obj_type, $bundle, $ '#markup' => t('%field has no field settings.', array('%field' => $instance['label'])), ); } + $form['#object_type'] = $obj_type; $form['#bundle'] = $bundle; $form['submit'] = array('#type' => 'submit', '#value' => t('Save field settings')); @@ -863,8 +869,9 @@ function field_ui_field_settings_form_submit($form, &$form_state) { // Merge incoming form values into the existing field. $field = field_info_field($field_values['field_name']); + $obj_type = $form['#object_type']; $bundle = $form['#bundle']; - $instance = field_info_instance($field['field_name'], $bundle); + $instance = field_info_instance($obj_type, $field['field_name'], $bundle); // Update the field. $field = array_merge($field, $field_values); @@ -872,12 +879,12 @@ function field_ui_field_settings_form_submit($form, &$form_state) { try { field_update_field($field); drupal_set_message(t('Updated field %label field settings.', array('%label' => $instance['label']))); - $form_state['redirect'] = field_ui_next_destination($bundle); + $form_state['redirect'] = field_ui_next_destination($obj_type, $bundle); } catch (FieldException $e) { drupal_set_message(t('Attempt to update field %label failed: %message.', array('%label' => $instance['label'], '%message' => $e->getMessage())), 'error'); // TODO: Where do we go from here? - $form_state['redirect'] = field_ui_next_destination($bundle); + $form_state['redirect'] = field_ui_next_destination($obj_type, $bundle); } } @@ -922,6 +929,7 @@ function field_ui_widget_type_form_submit($form, &$form_state) { $form_values = $form_state['values']; $instance = $form['#instance']; $bundle = $instance['bundle']; + $obj_type = $instance['object_type']; // Set the right module information. $widget_type = field_info_widget_types($form_values['widget_type']); @@ -937,7 +945,7 @@ function field_ui_widget_type_form_submit($form, &$form_state) { drupal_set_message(t('There was a problem changing the widget for field %label.', array('%label' => $instance['label']))); } - $form_state['redirect'] = field_ui_next_destination($bundle); + $form_state['redirect'] = field_ui_next_destination($obj_type, $bundle); } /** @@ -946,8 +954,9 @@ function field_ui_widget_type_form_submit($form, &$form_state) { function field_ui_field_delete_form($form, &$form_state, $obj_type, $bundle, $instance) { $bundle = field_extract_bundle($obj_type, $bundle); $field = field_info_field($instance['field_name']); - $admin_path = _field_ui_bundle_admin_path($bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); + $form['object_type'] = array('#type' => 'value', '#value' => $obj_type); $form['bundle'] = array('#type' => 'value', '#value' => $bundle); $form['field_name'] = array('#type' => 'value', '#value' => $field['field_name']); @@ -972,11 +981,13 @@ function field_ui_field_delete_form($form, &$form_state, $obj_type, $bundle, $in */ function field_ui_field_delete_form_submit($form, &$form_state) { $form_values = $form_state['values']; + $field_name = $form_values['field_name']; + $bundle = $form_values['bundle']; + $obj_type = $form_values['object_type']; $field = field_info_field($form_values['field_name']); - $instance = field_info_instance($form_values['field_name'], $form_values['bundle']); + $instance = field_info_instance($obj_type, $field_name, $bundle); $bundles = field_info_bundles(); - $bundle = $form_values['bundle']; - $bundle_label = $bundles[$bundle]['label']; + $bundle_label = $bundles[$obj_type][$bundle]['label']; if (!empty($bundle) && $field && !$field['locked'] && $form_values['confirm']) { field_delete_instance($instance); @@ -990,7 +1001,7 @@ function field_ui_field_delete_form_submit($form, &$form_state) { drupal_set_message(t('There was a problem removing the %field from the %type content type.', array('%field' => $instance['label'], '%type' => $bundle_label))); } - $admin_path = _field_ui_bundle_admin_path($bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); $form_state['redirect'] = field_ui_get_destinations(array($admin_path . '/fields')); } @@ -1021,8 +1032,8 @@ function field_ui_field_edit_form($form, &$form_state, $obj_type, $bundle, $inst $form['instance'] = array( '#tree' => TRUE, '#type' => 'fieldset', - '#title' => t('%type settings', array('%type' => $bundles[$bundle]['label'])), - '#description' => t('These settings apply only to the %field field when used in the %type type.', array('%field' => $instance['label'], '%type' => $bundles[$bundle]['label'])), + '#title' => t('%type settings', array('%type' => $bundles[$obj_type][$bundle]['label'])), + '#description' => t('These settings apply only to the %field field when used in the %type type.', array('%field' => $instance['label'], '%type' => $bundles[$obj_type][$bundle]['label'])), '#pre_render' => array('field_ui_field_edit_instance_pre_render'), ); @@ -1031,6 +1042,10 @@ function field_ui_field_edit_form($form, &$form_state, $obj_type, $bundle, $inst '#type' => 'value', '#value' => $instance['field_name'], ); + $form['instance']['object_type'] = array( + '#type' => 'value', + '#value' => $obj_type, + ); $form['instance']['bundle'] = array( '#type' => 'value', '#value' => $bundle, @@ -1293,13 +1308,13 @@ function field_ui_field_edit_form_submit($form, &$form_state) { } // Update the instance settings. - $instance = field_info_instance($instance_values['field_name'], $instance_values['bundle']); + $instance = field_info_instance($instance_values['object_type'], $instance_values['field_name'], $instance_values['bundle']); $instance = array_merge($instance, $instance_values); field_update_instance($instance); drupal_set_message(t('Saved %label configuration.', array('%label' => $instance['label']))); - $form_state['redirect'] = field_ui_next_destination($instance['bundle']); + $form_state['redirect'] = field_ui_next_destination($instance['object_type'], $instance['bundle']); } /** @@ -1317,13 +1332,13 @@ function field_ui_get_destinations($destinations) { /** * Return the next redirect path in a multipage sequence. */ -function field_ui_next_destination($bundle) { +function field_ui_next_destination($obj_type, $bundle) { $destinations = !empty($_REQUEST['destinations']) ? $_REQUEST['destinations'] : array(); if (!empty($destinations)) { unset($_REQUEST['destinations']); return field_ui_get_destinations($destinations); } - $admin_path = _field_ui_bundle_admin_path($bundle); + $admin_path = _field_ui_bundle_admin_path($obj_type, $bundle); return $admin_path . '/fields'; } diff --git a/modules/field_ui/field_ui.module b/modules/field_ui/field_ui.module index 7fa03fcad..99dd8c057 100644 --- a/modules/field_ui/field_ui.module +++ b/modules/field_ui/field_ui.module @@ -67,7 +67,7 @@ function field_ui_menu() { $items["$path/fields/%field_ui_menu"] = array( 'title callback' => 'field_ui_menu_label', 'title arguments' => array($instance_position), - 'load arguments' => array($bundle_arg), + 'load arguments' => array($obj_type, $bundle_arg), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $instance_position), 'type' => MENU_LOCAL_TASK, @@ -75,7 +75,7 @@ function field_ui_menu() { ) + $access; $items["$path/fields/%field_ui_menu/edit"] = array( 'title' => 'Edit instance settings', - 'load arguments' => array($bundle_arg), + 'load arguments' => array($obj_type, $bundle_arg), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_edit_form', $obj_type, $bundle_arg, $instance_position), 'type' => MENU_DEFAULT_LOCAL_TASK, @@ -83,7 +83,7 @@ function field_ui_menu() { ) + $access; $items["$path/fields/%field_ui_menu/field-settings"] = array( 'title' => 'Edit field settings', - 'load arguments' => array($bundle_arg), + 'load arguments' => array($obj_type, $bundle_arg), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_settings_form', $obj_type, $bundle_arg, $instance_position), 'type' => MENU_LOCAL_TASK, @@ -91,7 +91,7 @@ function field_ui_menu() { ) + $access; $items["$path/fields/%field_ui_menu/widget-type"] = array( 'title' => 'Change widget type', - 'load arguments' => array($bundle_arg), + 'load arguments' => array($obj_type, $bundle_arg), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_widget_type_form', $obj_type, $bundle_arg, $instance_position), 'type' => MENU_LOCAL_TASK, @@ -99,7 +99,7 @@ function field_ui_menu() { ) + $access; $items["$path/fields/%field_ui_menu/delete"] = array( 'title' => 'Delete instance', - 'load arguments' => array($bundle_arg), + 'load arguments' => array($obj_type, $bundle_arg), 'page callback' => 'drupal_get_form', 'page arguments' => array('field_ui_field_delete_form', $obj_type, $bundle_arg, $instance_position), 'type' => MENU_LOCAL_TASK, @@ -134,8 +134,8 @@ function field_ui_menu() { /** * Menu loader; Load a field instance based on its name. */ -function field_ui_menu_load($field_name, $bundle_name) { - if ($instance = field_info_instance($field_name, $bundle_name)) { +function field_ui_menu_load($field_name, $obj_type, $bundle_name) { + if ($instance = field_info_instance($obj_type, $field_name, $bundle_name)) { return $instance; } return FALSE; @@ -270,8 +270,8 @@ function field_ui_field_attach_delete_bundle($bundle) { /** * Helper function to create the right administration path for a bundle. */ -function _field_ui_bundle_admin_path($bundle_name) { - $bundles = field_info_bundles(); +function _field_ui_bundle_admin_path($obj_type, $bundle_name) { + $bundles = field_info_bundles($obj_type); $bundle_info = $bundles[$bundle_name]; return isset($bundle_info['admin']['real path']) ? $bundle_info['admin']['real path'] : $bundle_info['admin']['path']; } @@ -279,7 +279,7 @@ function _field_ui_bundle_admin_path($bundle_name) { /** * Helper function to identify inactive fields within a bundle. */ -function field_ui_inactive_instances($bundle_name = NULL) { +function field_ui_inactive_instances($obj_type, $bundle_name = NULL) { if (!empty($bundle_name)) { $inactive = array($bundle_name => array()); $params = array('bundle' => $bundle_name); @@ -288,7 +288,9 @@ function field_ui_inactive_instances($bundle_name = NULL) { $inactive = array(); $params = array(); } - $active_instances = field_info_instances(); + $params['object_type'] = $obj_type; + + $active_instances = field_info_instances($obj_type); $all_instances = field_read_instances($params, array('include_inactive' => TRUE)); foreach ($all_instances as $instance) { if (!isset($active_instances[$instance['bundle']][$instance['field_name']])) { diff --git a/modules/file/file.field.inc b/modules/file/file.field.inc index d08135817..6375c0174 100644 --- a/modules/file/file.field.inc +++ b/modules/file/file.field.inc @@ -474,6 +474,7 @@ function file_field_widget(&$form, &$form_state, $field, $instance, $langcode, $ // Add extra Field properties. '#field_name' => $field['field_name'], '#bundle' => $instance['bundle'], + '#object_type' => $instance['object_type'], ); if ($field['cardinality'] == 1) { @@ -605,7 +606,7 @@ function file_field_widget_process($element, &$form_state, $form) { $item['fid'] = $element['fid']['#value']; $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']); $settings = $instance['widget']['settings']; $element['#theme'] = 'file_widget'; @@ -717,7 +718,7 @@ function theme_file_widget_multiple($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']); // Get our list of widgets in order. $widgets = array(); diff --git a/modules/file/tests/file.test b/modules/file/tests/file.test index ed89fc5d5..8c4a75b0a 100644 --- a/modules/file/tests/file.test +++ b/modules/file/tests/file.test @@ -57,6 +57,7 @@ class FileFieldTestCase extends DrupalWebTestCase { $instance = array( 'field_name' => $field['field_name'], + 'object_type' => 'node', 'label' => $name, 'bundle' => $type_name, 'required' => !empty($instance_settings['required']), @@ -76,7 +77,7 @@ class FileFieldTestCase extends DrupalWebTestCase { */ function updateFileField($name, $type_name, $instance_settings = array(), $widget_settings = array()) { $field = field_info_field($name); - $instance = field_info_instance($name, $type_name); + $instance = field_info_instance('node', $name, $type_name); $instance['settings'] = array_merge($instance['settings'], $instance_settings); $instance['widget']['settings'] = array_merge($instance['widget']['settings'], $widget_settings); @@ -201,7 +202,7 @@ class FileFieldRevisionTestCase extends FileFieldTestCase { $field_name = 'field_' . strtolower($this->randomName()); $this->createFileField($field_name, $type_name); $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); @@ -294,7 +295,7 @@ class FileFieldDisplayTestCase extends FileFieldTestCase { $widget_settings = array(); $this->createFileField($field_name, $type_name, $field_settings, $instance_settings, $widget_settings); $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); @@ -340,7 +341,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { $field_name = 'field_' . strtolower($this->randomName()); $this->createFileField($field_name, $type_name, array(), array('required' => '1')); $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); $test_file = $this->getTestFile('text'); @@ -386,7 +387,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { $field_name = 'field_' . strtolower($this->randomName()); $this->createFileField($field_name, $type_name, array(), array('required' => '1')); $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); $small_file = $this->getTestFile('text', 131072); // 128KB. $large_file = $this->getTestFile('text', 1310720); // 1.2MB @@ -401,7 +402,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { foreach ($sizes as $max_filesize => $file_limit) { // Set the max file upload size. $this->updateFileField($field_name, $type_name, array('max_filesize' => $max_filesize)); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); @@ -438,7 +439,7 @@ class FileFieldValidateTestCase extends FileFieldTestCase { $field_name = 'field_' . strtolower($this->randomName()); $this->createFileField($field_name, $type_name); $field = field_info_field($field_name); - $instance = field_info_instance($field_name, $type_name); + $instance = field_info_instance('node', $field_name, $type_name); // Get the test file (a GIF image). $test_file = $this->getTestFile('image'); diff --git a/modules/forum/forum.install b/modules/forum/forum.install index a21244947..1f4c72ba2 100644 --- a/modules/forum/forum.install +++ b/modules/forum/forum.install @@ -43,6 +43,7 @@ function forum_enable() { $instance = array( 'field_name' => 'taxonomy_' . $vocabulary->machine_name, + 'object_type' => 'node', 'label' => $vocabulary->name, 'bundle' => 'forum', 'widget' => array( diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 6a62bdfe8..da83c86f6 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -159,7 +159,7 @@ function forum_init() { */ function _forum_node_check_node_type($node) { // Fetch information about the forum field. - $field = field_info_instance('taxonomy_forums', $node->type); + $field = field_info_instance('node', 'taxonomy_forums', $node->type); return is_array($field); } @@ -850,7 +850,7 @@ function template_preprocess_forums(&$variables) { // Loop through all bundles for forum taxonomy vocabulary field. $field = field_info_field('taxonomy_' . $vocabulary->machine_name); - foreach ($field['bundles'] as $type) { + foreach ($field['bundles']['node'] as $type) { // Check if the current user has the 'create' permission for this node type. if (node_access('create', $type)) { // Fetch the "General" name of the content type; diff --git a/modules/node/node.module b/modules/node/node.module index b4869de54..db50ea97a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -491,7 +491,7 @@ function node_type_save($info) { ->execute(); if (!empty($type->old_type) && $type->old_type != $type->type) { - field_attach_rename_bundle($type->old_type, $type->type); + field_attach_rename_bundle('node', $type->old_type, $type->type); } node_configure_fields($type); module_invoke_all('node_type_update', $type); @@ -503,7 +503,7 @@ function node_type_save($info) { ->fields($fields) ->execute(); - field_attach_create_bundle($type->type); + field_attach_create_bundle('node', $type->type); node_configure_fields($type); module_invoke_all('node_type_insert', $type); $status = SAVED_NEW; @@ -528,7 +528,7 @@ function node_type_save($info) { function node_configure_fields($type) { // Add or remove the body field, as needed. $field = field_info_field('body'); - $instance = field_info_instance('body', $type->type); + $instance = field_info_instance('node', 'body', $type->type); if ($type->has_body) { if (empty($field)) { $field = array( @@ -540,6 +540,7 @@ function node_configure_fields($type) { if (empty($instance)) { $instance = array( 'field_name' => 'body', + 'object_type' => 'node', 'bundle' => $type->type, 'label' => $type->body_label, 'widget_type' => 'text_textarea_with_summary', @@ -572,7 +573,7 @@ function node_configure_fields($type) { if ($type->has_title) { // Add the title field if not present. $field = field_info_field('title'); - $instance = field_info_instance('title', $type->type); + $instance = field_info_instance('node', 'title', $type->type); if (empty($field)) { $field = array( @@ -585,6 +586,7 @@ function node_configure_fields($type) { $weight = -5; $instance = array( 'field_name' => 'title', + 'object_type' => 'node', 'bundle' => $type->type, 'label' => $type->title_label, 'widget_type' => 'text', diff --git a/modules/node/node.test b/modules/node/node.test index a4f5f90e1..56cd251c0 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -871,7 +871,7 @@ class NodeTypeTestCase extends DrupalWebTestCase { $web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types')); $this->drupalLogin($web_user); - $instance = field_info_instance('body', 'page'); + $instance = field_info_instance('node', 'body', 'page'); $this->assertEqual($instance['label'], 'Body', t('Body field was found.')); // Verify that title and body fields are displayed. @@ -887,7 +887,7 @@ class NodeTypeTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); field_info_cache_clear(); - $this->assertFalse(field_info_instance('body', 'page'), t('Body field was removed.')); + $this->assertFalse(field_info_instance('node', 'body', 'page'), t('Body field was removed.')); $this->drupalGet('node/add/page'); $this->assertRaw('Foo', t('New title label was displayed.')); $this->assertNoRaw('Title', t('Old title label was not displayed.')); @@ -903,7 +903,7 @@ class NodeTypeTestCase extends DrupalWebTestCase { $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); field_info_cache_clear(); - $instance = field_info_instance('body', 'bar'); + $instance = field_info_instance('node', 'body', 'bar'); $this->assertEqual($instance['label'], 'Baz', t('Body field was added.')); $this->drupalGet('node/add'); $this->assertRaw('Bar', t('New name was displayed.')); diff --git a/modules/simpletest/tests/field_test.module b/modules/simpletest/tests/field_test.module index cbd1bc07e..d5c35d06b 100644 --- a/modules/simpletest/tests/field_test.module +++ b/modules/simpletest/tests/field_test.module @@ -101,18 +101,21 @@ function field_test_entity_info_alter(&$entity_info) { /** * Create a new bundle for test_entity objects. * - * @param $bundle_name + * @param $bundle * The machine-readable name of the bundle. * @param $text * The human-readable name of the bundle. If none is provided, the machine * name will be used. */ -function field_test_create_bundle($bundle_name, $text = NULL) { +function field_test_create_bundle($bundle, $text = NULL) { $bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle'))); - $bundles += array($bundle_name => array('label' => $text ? $text : $bundle_name)); + $bundles += array($bundle => array('label' => $text ? $text : $bundle)); variable_set('field_test_bundles', $bundles); - field_attach_create_bundle($bundle_name); + $info = field_test_entity_info(); + foreach ($info as $type => $type_info) { + field_attach_create_bundle($type, $bundle); + } } /** @@ -129,21 +132,27 @@ function field_test_rename_bundle($bundle_old, $bundle_new) { unset($bundles[$bundle_old]); variable_set('field_test_bundles', $bundles); - field_attach_rename_bundle($bundle_old, $bundle_new); + $info = field_test_entity_info(); + foreach ($info as $type => $type_info) { + field_attach_rename_bundle($type, $bundle_old, $bundle_new); + } } /** * Delete a bundle for test_entity objects. * - * @param $bundle_name + * @param $bundle * The machine-readable name of the bundle to delete. */ -function field_test_delete_bundle($bundle_name) { +function field_test_delete_bundle($bundle) { $bundles = variable_get('field_test_bundles', array('test_bundle' => array('label' => 'Test Bundle'))); - unset($bundles[$bundle_name]); + unset($bundles[$bundle]); variable_set('field_test_bundles', $bundles); - field_attach_delete_bundle($bundle_name); + $info = field_test_entity_info(); + foreach ($info as $type => $type_info) { + field_attach_delete_bundle($type, $bundle); + } } /** diff --git a/modules/taxonomy/taxonomy.admin.inc b/modules/taxonomy/taxonomy.admin.inc index 110d43d5b..c7dafe7d6 100644 --- a/modules/taxonomy/taxonomy.admin.inc +++ b/modules/taxonomy/taxonomy.admin.inc @@ -207,7 +207,7 @@ function taxonomy_form_vocabulary_submit($form, &$form_state) { } $vocabulary = (object) $form_state['values']; if ($vocabulary->machine_name != $old_vocabulary->machine_name) { - field_attach_rename_bundle($old_vocabulary->machine_name, $vocabulary->machine_name); + field_attach_rename_bundle('taxonomy_term', $old_vocabulary->machine_name, $vocabulary->machine_name); } switch (taxonomy_vocabulary_save($vocabulary)) { case SAVED_NEW: diff --git a/modules/taxonomy/taxonomy.install b/modules/taxonomy/taxonomy.install index 5fd904cf4..17749dc5a 100644 --- a/modules/taxonomy/taxonomy.install +++ b/modules/taxonomy/taxonomy.install @@ -256,7 +256,7 @@ function taxonomy_update_7002() { ->fields(array('machine_name' => 'vocabulary_' . $vid)) ->condition('vid', $vid) ->execute(); - field_attach_create_bundle($machine_name); + field_attach_create_bundle('taxonomy_term', $machine_name); } } diff --git a/modules/taxonomy/taxonomy.module b/modules/taxonomy/taxonomy.module index b7423f124..e22554107 100644 --- a/modules/taxonomy/taxonomy.module +++ b/modules/taxonomy/taxonomy.module @@ -314,7 +314,7 @@ function taxonomy_vocabulary_save($vocabulary) { } elseif (empty($vocabulary->vid)) { $status = drupal_write_record('taxonomy_vocabulary', $vocabulary); - field_attach_create_bundle($vocabulary->machine_name); + field_attach_create_bundle('taxonomy_term', $vocabulary->machine_name); taxonomy_vocabulary_create_field($vocabulary); module_invoke_all('taxonomy_vocabulary_insert', $vocabulary); } @@ -344,7 +344,7 @@ function taxonomy_vocabulary_delete($vid) { taxonomy_term_delete($tid); } - field_attach_delete_bundle($vocabulary['machine_name']); + field_attach_delete_bundle('taxonomy_term', $vocabulary['machine_name']); module_invoke_all('taxonomy', 'delete', 'vocabulary', $vocabulary); cache_clear_all(); diff --git a/modules/taxonomy/taxonomy.test b/modules/taxonomy/taxonomy.test index 6fd16dd18..b4e351371 100644 --- a/modules/taxonomy/taxonomy.test +++ b/modules/taxonomy/taxonomy.test @@ -665,7 +665,6 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase { $web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer taxonomy')); $this->drupalLogin($web_user); - $this->vocabulary = $this->createVocabulary(); } @@ -691,6 +690,7 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase { field_create_field($this->field); $this->instance = array( 'field_name' => $this->field_name, + 'object_type' => 'test_entity', 'bundle' => FIELD_TEST_BUNDLE, 'widget' => array( 'type' => 'options_select', @@ -749,6 +749,7 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase { 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', 'widget' => array( diff --git a/profiles/default/default.install b/profiles/default/default.install index 2ca6f19e5..2b07a9c1b 100644 --- a/profiles/default/default.install +++ b/profiles/default/default.install @@ -202,6 +202,7 @@ function default_install() { taxonomy_vocabulary_save($vocabulary); $instance = array( 'field_name' => 'taxonomy_' . $vocabulary->machine_name, + 'object_type' => 'taxonomy_term', 'label' => $vocabulary->name, 'bundle' => 'article', 'description' => $vocabulary->help, |