summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngie Byron2009-09-10 22:31:58 (GMT)
committerAngie Byron2009-09-10 22:31:58 (GMT)
commitb47e68011f520ccadc2924e8240dc461f0c64fe7 (patch)
tree658261afcf0fa507637e468256441b7e488c8ea9
parent0d8adb439d47d2f30fc0d4edee029f40d3145316 (diff)
#569072 by rcross and yched: Clean field_attach_()* namespace by renaming and moving non-crud functions.
-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
-rw-r--r--modules/field_ui/field_ui.admin.inc12
-rw-r--r--modules/file/file.field.inc4
8 files changed, 108 insertions, 107 deletions
diff --git a/modules/field/field.attach.inc b/modules/field/field.attach.inc
index 4cf57c4..5f22293 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 ceecbba..50e71e3 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 b28acd0..16cd30e 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 ef27a06..487ea35 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 752428a..04ceb0a 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 55b7571..ff096df 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)) {
diff --git a/modules/field_ui/field_ui.admin.inc b/modules/field_ui/field_ui.admin.inc
index 759e539..9b9537a 100644
--- a/modules/field_ui/field_ui.admin.inc
+++ b/modules/field_ui/field_ui.admin.inc
@@ -66,7 +66,7 @@ function field_ui_inactive_message($bundle) {
* Allows fields and pseudo-fields to be re-ordered.
*/
function field_ui_field_overview_form(&$form_state, $obj_type, $bundle) {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
field_ui_inactive_message($bundle);
$admin_path = _field_ui_bundle_admin_path($bundle);
@@ -551,7 +551,7 @@ function field_ui_field_overview_form_submit($form, &$form_state) {
* full build modes, and how the field labels should be rendered.
*/
function field_ui_display_overview_form(&$form_state, $obj_type, $bundle, $build_modes_selector = 'basic') {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
field_ui_inactive_message($bundle);
$admin_path = _field_ui_bundle_admin_path($bundle);
@@ -791,7 +791,7 @@ function field_ui_field_has_data($field) {
* Menu callback; presents the field settings edit page.
*/
function field_ui_field_settings_form(&$form_state, $obj_type, $bundle, $instance) {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
$field = field_info_field($instance['field_name']);
// When a field is first created, we have to get data from the db.
@@ -888,7 +888,7 @@ function field_ui_field_settings_form_submit($form, &$form_state) {
* Menu callback; select a widget for the field.
*/
function field_ui_widget_type_form(&$form_state, $obj_type, $bundle, $instance) {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
$field = field_read_field($instance['field_name']);
$field_type = field_info_field_types($field['type']);
@@ -947,7 +947,7 @@ function field_ui_widget_type_form_submit($form, &$form_state) {
* Menu callback; present a form for removing a field from a content type.
*/
function field_ui_field_delete_form(&$form_state, $obj_type, $bundle, $instance) {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
$field = field_info_field($instance['field_name']);
$admin_path = _field_ui_bundle_admin_path($bundle);
@@ -1001,7 +1001,7 @@ function field_ui_field_delete_form_submit($form, &$form_state) {
* Menu callback; presents the field instance edit page.
*/
function field_ui_field_edit_form(&$form_state, $obj_type, $bundle, $instance) {
- $bundle = field_attach_extract_bundle($obj_type, $bundle);
+ $bundle = field_extract_bundle($obj_type, $bundle);
$field = field_info_field($instance['field_name']);
$form['#field'] = $field;
diff --git a/modules/file/file.field.inc b/modules/file/file.field.inc
index 12c1b60..3552229 100644
--- a/modules/file/file.field.inc
+++ b/modules/file/file.field.inc
@@ -292,7 +292,7 @@ function file_field_update($obj_type, $object, $field, $instance, $langcode, &$i
}
// Delete items from original object.
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
$load_function = $obj_type . '_load';
$original = $load_function($id);
@@ -312,7 +312,7 @@ function file_field_update($obj_type, $object, $field, $instance, $langcode, &$i
* Implement hook_field_delete().
*/
function file_field_delete($obj_type, $object, $field, $instance, $langcode, &$items) {
- list($id, $vid, $bundle) = field_attach_extract_ids($obj_type, $object);
+ list($id, $vid, $bundle) = field_extract_ids($obj_type, $object);
foreach ($items as $delta => $item) {
// For hook_file_references(), remember that this is being deleted.
$item['file_field_name'] = $field['field_name'];