summaryrefslogtreecommitdiff
path: root/modules/field
diff options
context:
space:
mode:
Diffstat (limited to 'modules/field')
-rw-r--r--modules/field/field.attach.inc97
-rw-r--r--modules/field/field.default.inc2
-rw-r--r--modules/field/field.form.inc2
-rw-r--r--modules/field/field.module84
-rw-r--r--modules/field/field.test2
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.module12
6 files changed, 100 insertions, 99 deletions
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 4cf57c483..5f2229376 100644
--- a/modules/field/field.attach.inc
+++ b/modules/field/field.attach.inc
@@ -182,7 +182,7 @@ function _field_invoke($op, $obj_type, $object, &$a = NULL, &$b = NULL, $options
// Iterate through the object's field instances.
$return = array();
- list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
+ list(, , $bundle) = field_extract_ids($obj_type, $object);
if ($options['deleted']) {
$instances = field_read_instances(array('bundle' => $bundle), array('include_deleted' => $options['deleted']));
@@ -299,7 +299,7 @@ function _field_invoke_multiple($op, $obj_type, $objects, &$a = NULL, &$b = NULL
// is deleted, so we reference field data via the
// $object->$field_name property.
foreach ($objects as $object) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
if ($options['deleted']) {
$instances = field_read_field(array('bundle' => $bundle, array('include_deleted' => $options['deleted'])));
@@ -489,7 +489,7 @@ function field_attach_form($obj_type, $object, &$form, &$form_state, $langcode =
$form += (array) _field_invoke_default('form', $obj_type, $object, $form, $form_state, $options);
// Add custom weight handling.
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$form['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
$form['#pre_render'][] = '_field_extra_weights_pre_render';
$form['#extra_fields'] = field_extra_fields($bundle);
@@ -608,7 +608,7 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
if ($cache_write) {
foreach ($queried_objects as $id => $object) {
$data = array();
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$instances = field_info_instances($bundle);
foreach ($instances as $instance) {
$data[$instance['field_name']] = $queried_objects[$id]->{$instance['field_name']};
@@ -802,7 +802,7 @@ function field_attach_insert($obj_type, $object) {
// Field storage module saves any remaining unsaved fields.
module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_INSERT, $skip_fields);
- list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field');
}
@@ -830,7 +830,7 @@ function field_attach_update($obj_type, $object) {
// Field storage module saves any remaining unsaved fields.
module_invoke(variable_get('field_storage_module', 'field_sql_storage'), 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $skip_fields);
- list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field');
}
@@ -855,7 +855,7 @@ function field_attach_delete($obj_type, $object) {
$function($obj_type, $object);
}
- list($id, $vid, $bundle, $cacheable) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle, $cacheable) = field_extract_ids($obj_type, $object);
if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field');
}
@@ -1089,7 +1089,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode =
$output = _field_invoke_default('view', $obj_type, $object, $build_mode, $null, $options);
// Add custom weight handling.
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$output['#attached']['css'][] = drupal_get_path('module', 'field') . '/theme/field.css';
$output['#pre_render'][] = '_field_extra_weights_pre_render';
$output['#extra_fields'] = field_extra_fields($bundle);
@@ -1119,7 +1119,7 @@ function field_attach_view($obj_type, $object, $build_mode = 'full', $langcode =
* values.
*/
function field_attach_preprocess($obj_type, $object, $element, &$variables) {
- list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
+ list(, , $bundle) = field_extract_ids($obj_type, $object);
foreach (field_info_instances($bundle) as $instance) {
$field_name = $instance['field_name'];
@@ -1243,85 +1243,6 @@ function field_attach_delete_bundle($bundle) {
}
}
-/**
- * Helper function to extract id, vid, and bundle name from an object.
- *
- * @param $obj_type
- * The type of $object; e.g. 'node' or 'user'.
- * @param $object
- * The object from which to extract values.
- * @return
- * A numerically indexed array (not a hash table) containing these
- * elements:
- *
- * 0: primary id of the object
- * 1: revision id of the object, or NULL if $obj_type is not versioned
- * 2: bundle name of the object
- * 3: whether $obj_type's fields should be cached (TRUE/FALSE)
- */
-function field_attach_extract_ids($obj_type, $object) {
- // TODO D7 : prevent against broken 3rd party $node without 'type'.
- $info = field_info_fieldable_types($obj_type);
- // Objects being created might not have id/vid yet.
- $id = isset($object->{$info['object keys']['id']}) ? $object->{$info['object keys']['id']} : NULL;
- $vid = ($info['object keys']['revision'] && isset($object->{$info['object keys']['revision']})) ? $object->{$info['object keys']['revision']} : NULL;
- // If no bundle key provided, then we assume a single bundle, named after the
- // type of the object.
- $bundle = $info['object keys']['bundle'] ? $object->{$info['object keys']['bundle']} : $obj_type;
- $cacheable = $info['cacheable'];
- return array($id, $vid, $bundle, $cacheable);
-}
-
-/**
- * Helper function to extract id, vid, and bundle name from an object.
- *
- * @param $obj_type
- * The type of $object; e.g. 'node' or 'user'.
- * @param $bundle
- * The bundle object (or string if bundles for this object type do not exist
- * as standalone objects).
- * @return
- * The bundle name.
- */
-function field_attach_extract_bundle($obj_type, $bundle) {
- if (is_string($bundle)) {
- return $bundle;
- }
-
- $info = field_info_fieldable_types($obj_type);
- if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {
- return $bundle->{$info['bundle keys']['bundle']};
- }
-}
-
-/**
- * Helper function to assemble an object structure with initial ids.
- *
- * This function can be seen as reciprocal to field_attach_extract_ids().
- *
- * @param $obj_type
- * The type of $object; e.g. 'node' or 'user'.
- * @param $ids
- * A numerically indexed array, as returned by field_attach_extract_ids(),
- * containing these elements:
- * 0: primary id of the object
- * 1: revision id of the object, or NULL if $obj_type is not versioned
- * 2: bundle name of the object
- * @return
- * An $object structure, initialized with the ids provided.
- */
-function field_attach_create_stub_object($obj_type, $ids) {
- $object = new stdClass();
- $info = field_info_fieldable_types($obj_type);
- $object->{$info['object keys']['id']} = $ids[0];
- if (isset($info['object keys']['revision']) && !is_null($ids[1])) {
- $object->{$info['object keys']['revision']} = $ids[1];
- }
- if ($info['object keys']['bundle']) {
- $object->{$info['object keys']['bundle']} = $ids[2];
- }
- return $object;
-}
/**
* @} End of "defgroup field_attach"
diff --git a/modules/field/field.default.inc b/modules/field/field.default.inc
index ceecbba3a..50e71e30e 100644
--- a/modules/field/field.default.inc
+++ b/modules/field/field.default.inc
@@ -59,7 +59,7 @@ function field_default_insert($obj_type, $object, $field, $instance, $langcode,
* @see field_attach_view()
*/
function field_default_view($obj_type, $object, $field, $instance, $langcode, $items, $build_mode) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$addition = array();
$display = $instance['display'][$build_mode];
diff --git a/modules/field/field.form.inc b/modules/field/field.form.inc
index b28acd07b..16cd30ed9 100644
--- a/modules/field/field.form.inc
+++ b/modules/field/field.form.inc
@@ -13,7 +13,7 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
// This could be called with no object, as when a UI module creates a
// dummy form to set default values.
if ($object) {
- list($id, , ) = field_attach_extract_ids($obj_type, $object);
+ list($id, , ) = field_extract_ids($obj_type, $object);
}
$addition = array();
diff --git a/modules/field/field.module b/modules/field/field.module
index ef27a0618..487ea3595 100644
--- a/modules/field/field.module
+++ b/modules/field/field.module
@@ -500,7 +500,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$field_type = field_info_field_types($field['type']);
// We need $field, $instance, $obj_type, $object to be able to display a value...
- list(, , $bundle) = field_attach_extract_ids($obj_type, $object);
+ list(, , $bundle) = field_extract_ids($obj_type, $object);
$instance = field_info_instance($field['field_name'], $bundle);
$display = array(
@@ -631,13 +631,93 @@ function field_access($op, $field, $account = NULL) {
}
/**
+ * Helper function to extract id, vid, and bundle name from an object.
+ *
+ * @param $obj_type
+ * The type of $object; e.g. 'node' or 'user'.
+ * @param $object
+ * The object from which to extract values.
+ * @return
+ * A numerically indexed array (not a hash table) containing these
+ * elements:
+ *
+ * 0: primary id of the object
+ * 1: revision id of the object, or NULL if $obj_type is not versioned
+ * 2: bundle name of the object
+ * 3: whether $obj_type's fields should be cached (TRUE/FALSE)
+ */
+function field_extract_ids($obj_type, $object) {
+ // TODO D7 : prevent against broken 3rd party $node without 'type'.
+ $info = field_info_fieldable_types($obj_type);
+ // Objects being created might not have id/vid yet.
+ $id = isset($object->{$info['object keys']['id']}) ? $object->{$info['object keys']['id']} : NULL;
+ $vid = ($info['object keys']['revision'] && isset($object->{$info['object keys']['revision']})) ? $object->{$info['object keys']['revision']} : NULL;
+ // If no bundle key provided, then we assume a single bundle, named after the
+ // type of the object.
+ $bundle = $info['object keys']['bundle'] ? $object->{$info['object keys']['bundle']} : $obj_type;
+ $cacheable = $info['cacheable'];
+ return array($id, $vid, $bundle, $cacheable);
+}
+
+/**
+ * Helper function to extract id, vid, and bundle name from an object.
+ *
+ * @param $obj_type
+ * The type of $object; e.g. 'node' or 'user'.
+ * @param $bundle
+ * The bundle object (or string if bundles for this object type do not exist
+ * as standalone objects).
+ * @return
+ * The bundle name.
+ */
+function field_extract_bundle($obj_type, $bundle) {
+ if (is_string($bundle)) {
+ return $bundle;
+ }
+
+ $info = field_info_fieldable_types($obj_type);
+ if (is_object($bundle) && isset($info['bundle keys']['bundle']) && isset($bundle->{$info['bundle keys']['bundle']})) {
+ return $bundle->{$info['bundle keys']['bundle']};
+ }
+}
+
+/**
+ * Helper function to assemble an object structure with initial ids.
+ *
+ * This function can be seen as reciprocal to field_extract_ids().
+ *
+ * @param $obj_type
+ * The type of $object; e.g. 'node' or 'user'.
+ * @param $ids
+ * A numerically indexed array, as returned by field_extract_ids(),
+ * containing these elements:
+ * 0: primary id of the object
+ * 1: revision id of the object, or NULL if $obj_type is not versioned
+ * 2: bundle name of the object
+ * @return
+ * An $object structure, initialized with the ids provided.
+ */
+function field_create_stub_entity($obj_type, $ids) {
+ $object = new stdClass();
+ $info = field_info_fieldable_types($obj_type);
+ $object->{$info['object keys']['id']} = $ids[0];
+ if (isset($info['object keys']['revision']) && !is_null($ids[1])) {
+ $object->{$info['object keys']['revision']} = $ids[1];
+ }
+ if ($info['object keys']['bundle']) {
+ $object->{$info['object keys']['bundle']} = $ids[2];
+ }
+ return $object;
+}
+
+/**
* Theme preprocess function for field.tpl.php.
*
* @see field.tpl.php
*/
function template_preprocess_field(&$variables) {
$element = $variables['element'];
- list(, , $bundle) = field_attach_extract_ids($element['#object_type'], $element['#object']);
+ list(, , $bundle) = field_extract_ids($element['#object_type'], $element['#object']);
$instance = field_info_instance($element['#field_name'], $bundle);
$field = field_info_field($element['#field_name']);
diff --git a/modules/field/field.test b/modules/field/field.test
index 752428acb..04ceb0ab2 100644
--- a/modules/field/field.test
+++ b/modules/field/field.test
@@ -2135,7 +2135,7 @@ class FieldBulkDeleteTestCase extends FieldTestCase {
function _generateStubObjects($obj_type, $objects, $field_name = NULL) {
$stubs = array();
foreach ($objects as $obj) {
- $stub = field_attach_create_stub_object($obj_type, field_attach_extract_ids($obj_type, $obj));
+ $stub = field_create_stub_entity($obj_type, field_extract_ids($obj_type, $obj));
if (isset($field_name)) {
$stub->{$field_name} = $obj->{$field_name};
}
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 55b75715f..ff096dfe6 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -238,7 +238,7 @@ function field_sql_storage_field_storage_load($obj_type, $objects, $age, $skip_f
$field_ids = array();
$delta_count = array();
foreach ($objects as $obj) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $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']));
@@ -301,7 +301,7 @@ function field_sql_storage_field_storage_load($obj_type, $objects, $age, $skip_f
* Implement hook_field_storage_write().
*/
function field_sql_storage_field_storage_write($obj_type, $object, $op, $skip_fields) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$etid = _field_sql_storage_etid($obj_type);
$instances = field_info_instances($bundle);
@@ -399,7 +399,7 @@ function field_sql_storage_field_storage_write($obj_type, $object, $op, $skip_fi
* This function deletes data for all fields for an object from the database.
*/
function field_sql_storage_field_storage_delete($obj_type, $object) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$etid = _field_sql_storage_etid($obj_type);
$instances = field_info_instances($bundle);
@@ -416,7 +416,7 @@ function field_sql_storage_field_storage_delete($obj_type, $object) {
* an object.
*/
function field_sql_storage_field_storage_purge($obj_type, $object, $field, $instance) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$etid = _field_sql_storage_etid($obj_type);
$field = field_info_field_by_id($field['id']);
@@ -532,7 +532,7 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $count, &
$id = ($load_current || empty($entity_type['object keys']['revision'])) ? $row->entity_id : $row->revision_id;
if (!isset($return[$row->type][$id])) {
- $return[$row->type][$id] = field_attach_create_stub_object($row->type, array($row->entity_id, $row->revision_id, $row->bundle));
+ $return[$row->type][$id] = field_create_stub_entity($row->type, array($row->entity_id, $row->revision_id, $row->bundle));
$obj_count++;
}
}
@@ -553,7 +553,7 @@ function field_sql_storage_field_storage_query($field_id, $conditions, $count, &
* This function actually deletes the data from the database.
*/
function field_sql_storage_field_storage_delete_revision($obj_type, $object) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$etid = _field_sql_storage_etid($obj_type);
if (isset($vid)) {