Commit 0b71c0ca authored by webchick's avatar webchick

#622534 by yched: Cleanup hook_field_attach_*() and hook_field_storage_*() space.

parent a6e707cd
This diff is collapsed.
...@@ -494,6 +494,7 @@ function field_attach_form($obj_type, $object, &$form, &$form_state, $langcode = ...@@ -494,6 +494,7 @@ function field_attach_form($obj_type, $object, &$form, &$form_state, $langcode =
$form['#extra_fields'] = field_extra_fields($bundle); $form['#extra_fields'] = field_extra_fields($bundle);
// Let other modules make changes to the form. // Let other modules make changes to the form.
// Avoid module_invoke_all() to let parameters be taken by reference.
foreach (module_implements('field_attach_form') as $module) { foreach (module_implements('field_attach_form') as $module) {
$function = $module . '_field_attach_form'; $function = $module . '_field_attach_form';
$function($obj_type, $object, $form, $form_state, $langcode); $function($obj_type, $object, $form, $form_state, $langcode);
...@@ -575,16 +576,16 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti ...@@ -575,16 +576,16 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
// Fetch other objects from their storage location. // Fetch other objects from their storage location.
if ($queried_objects) { if ($queried_objects) {
// The invoke order is: // The invoke order is:
// - hook_field_attach_pre_load() // - hook_field_storage_pre_load()
// - storage backend's hook_field_storage_load() // - storage backend's hook_field_storage_load()
// - field-type module's hook_field_load() // - field-type module's hook_field_load()
// - hook_field_attach_load() // - hook_field_attach_load()
// Invoke hook_field_attach_pre_load(): let any module load field // Invoke hook_field_storage_pre_load(): let any module load field
// data before the storage engine, accumulating along the way. // data before the storage engine, accumulating along the way.
$skip_fields = array(); $skip_fields = array();
foreach (module_implements('field_attach_pre_load') as $module) { foreach (module_implements('field_storage_pre_load') as $module) {
$function = $module . '_field_attach_pre_load'; $function = $module . '_field_storage_pre_load';
$function($obj_type, $queried_objects, $age, $skip_fields, $options); $function($obj_type, $queried_objects, $age, $skip_fields, $options);
} }
...@@ -627,10 +628,7 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti ...@@ -627,10 +628,7 @@ function field_attach_load($obj_type, $objects, $age = FIELD_LOAD_CURRENT, $opti
// Invoke hook_field_attach_load(): let other modules act on loading the // Invoke hook_field_attach_load(): let other modules act on loading the
// object. // object.
foreach (module_implements('field_attach_load') as $module) { module_invoke_all('field_attach_load', $obj_type, $queried_objects, $age, $options);
$function = $module . '_field_attach_load';
$function($obj_type, $queried_objects, $age, $options);
}
// Build cache data. // Build cache data.
if ($cache_write) { if ($cache_write) {
...@@ -695,6 +693,7 @@ function field_attach_validate($obj_type, $object) { ...@@ -695,6 +693,7 @@ function field_attach_validate($obj_type, $object) {
_field_invoke('validate', $obj_type, $object, $errors); _field_invoke('validate', $obj_type, $object, $errors);
// Let other modules validate the object. // Let other modules validate the object.
// Avoid module_invoke_all() to let $errors be taken by reference.
foreach (module_implements('field_attach_validate') as $module) { foreach (module_implements('field_attach_validate') as $module) {
$function = $module . '_field_attach_validate'; $function = $module . '_field_attach_validate';
$function($obj_type, $object, $errors); $function($obj_type, $object, $errors);
...@@ -772,6 +771,7 @@ function field_attach_submit($obj_type, $object, $form, &$form_state) { ...@@ -772,6 +771,7 @@ function field_attach_submit($obj_type, $object, $form, &$form_state) {
_field_invoke_default('submit', $obj_type, $object, $form, $form_state); _field_invoke_default('submit', $obj_type, $object, $form, $form_state);
// Let other modules act on submitting the object. // Let other modules act on submitting the object.
// Avoid module_invoke_all() to let $form_state be taken by reference.
foreach (module_implements('field_attach_submit') as $module) { foreach (module_implements('field_attach_submit') as $module) {
$function = $module . '_field_attach_submit'; $function = $module . '_field_attach_submit';
$function($obj_type, $object, $form, $form_state); $function($obj_type, $object, $form, $form_state);
...@@ -793,10 +793,7 @@ function field_attach_presave($obj_type, $object) { ...@@ -793,10 +793,7 @@ function field_attach_presave($obj_type, $object) {
_field_invoke('presave', $obj_type, $object); _field_invoke('presave', $obj_type, $object);
// Let other modules act on presaving the object. // Let other modules act on presaving the object.
foreach (module_implements('field_attach_presave') as $module) { module_invoke_all('field_attach_presave', $obj_type, $object);
$function = $module . '_field_attach_presave';
$function($obj_type, $object);
}
} }
/** /**
...@@ -821,11 +818,11 @@ function field_attach_insert($obj_type, $object) { ...@@ -821,11 +818,11 @@ function field_attach_insert($obj_type, $object) {
list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object); list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object);
// Let other modules act on inserting the object, accumulating saved // Let any module insert field data before the storage engine, accumulating
// fields along the way. // saved fields along the way.
$skip_fields = array(); $skip_fields = array();
foreach (module_implements('field_attach_pre_insert') as $module) { foreach (module_implements('field_storage_pre_insert') as $module) {
$function = $module . '_field_attach_pre_insert'; $function = $module . '_field_storage_pre_insert';
$function($obj_type, $object, $skip_fields); $function($obj_type, $object, $skip_fields);
} }
...@@ -849,6 +846,9 @@ function field_attach_insert($obj_type, $object) { ...@@ -849,6 +846,9 @@ function field_attach_insert($obj_type, $object) {
module_invoke($storage_info['module'], 'field_storage_write', $obj_type, $object, FIELD_STORAGE_INSERT, $fields); module_invoke($storage_info['module'], 'field_storage_write', $obj_type, $object, FIELD_STORAGE_INSERT, $fields);
} }
// Let other modules act on inserting the object.
module_invoke_all('field_attach_insert', $obj_type, $object);
if ($cacheable) { if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field'); cache_clear_all("field:$obj_type:$id", 'cache_field');
} }
...@@ -867,11 +867,11 @@ function field_attach_update($obj_type, $object) { ...@@ -867,11 +867,11 @@ function field_attach_update($obj_type, $object) {
list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object); list($id, $vid, $bundle, $cacheable) = entity_extract_ids($obj_type, $object);
// Let other modules act on updating the object, accumulating saved // Let any module update field data before the storage engine, accumulating
// fields along the way. // saved fields along the way.
$skip_fields = array(); $skip_fields = array();
foreach (module_implements('field_attach_pre_update') as $module) { foreach (module_implements('field_storage_pre_update') as $module) {
$function = $module . '_field_attach_pre_update'; $function = $module . '_field_storage_pre_update';
$function($obj_type, $object, $skip_fields); $function($obj_type, $object, $skip_fields);
} }
...@@ -899,6 +899,9 @@ function field_attach_update($obj_type, $object) { ...@@ -899,6 +899,9 @@ function field_attach_update($obj_type, $object) {
module_invoke($storage_info['module'], 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $fields); module_invoke($storage_info['module'], 'field_storage_write', $obj_type, $object, FIELD_STORAGE_UPDATE, $fields);
} }
// Let other modules act on updating the object.
module_invoke_all('field_attach_update', $obj_type, $object);
if ($cacheable) { if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field'); cache_clear_all("field:$obj_type:$id", 'cache_field');
} }
...@@ -933,10 +936,7 @@ function field_attach_delete($obj_type, $object) { ...@@ -933,10 +936,7 @@ function field_attach_delete($obj_type, $object) {
} }
// Let other modules act on deleting the object. // Let other modules act on deleting the object.
foreach (module_implements('field_attach_delete') as $module) { module_invoke_all('field_attach_delete', $obj_type, $object);
$function = $module . '_field_attach_delete';
$function($obj_type, $object);
}
if ($cacheable) { if ($cacheable) {
cache_clear_all("field:$obj_type:$id", 'cache_field'); cache_clear_all("field:$obj_type:$id", 'cache_field');
...@@ -972,10 +972,7 @@ function field_attach_delete_revision($obj_type, $object) { ...@@ -972,10 +972,7 @@ function field_attach_delete_revision($obj_type, $object) {
} }
// Let other modules act on deleting the revision. // Let other modules act on deleting the revision.
foreach (module_implements('field_attach_delete_revision') as $module) { module_invoke_all('field_attach_delete_revision', $obj_type, $object);
$function = $module . '_field_attach_delete_revision';
$function($obj_type, $object);
}
} }
/** /**
...@@ -1071,8 +1068,8 @@ function field_attach_query($field_id, $conditions, $options = array()) { ...@@ -1071,8 +1068,8 @@ function field_attach_query($field_id, $conditions, $options = array()) {
// Give a chance to 3rd party modules that bypass the storage engine to // Give a chance to 3rd party modules that bypass the storage engine to
// handle the query. // handle the query.
$skip_field = FALSE; $skip_field = FALSE;
foreach (module_implements('field_attach_pre_query') as $module) { foreach (module_implements('field_storage_pre_query') as $module) {
$function = $module . '_field_attach_pre_query'; $function = $module . '_field_storage_pre_query';
$results = $function($field_id, $conditions, $options, $skip_field); $results = $function($field_id, $conditions, $options, $skip_field);
// Stop as soon as a module claims it handled the query. // Stop as soon as a module claims it handled the query.
if ($skip_field) { if ($skip_field) {
...@@ -1301,10 +1298,8 @@ function field_attach_create_bundle($obj_type, $bundle) { ...@@ -1301,10 +1298,8 @@ function field_attach_create_bundle($obj_type, $bundle) {
// Clear the cache. // Clear the cache.
field_cache_clear(); field_cache_clear();
foreach (module_implements('field_attach_create_bundle') as $module) { // Let other modules act on creating the bundle.
$function = $module . '_field_attach_create_bundle'; module_invoke_all('field_attach_create_bundle', $obj_type, $bundle);
$function($obj_type, $bundle);
}
} }
/** /**
...@@ -1327,10 +1322,8 @@ function field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) { ...@@ -1327,10 +1322,8 @@ function field_attach_rename_bundle($obj_type, $bundle_old, $bundle_new) {
// Clear the cache. // Clear the cache.
field_cache_clear(); field_cache_clear();
foreach (module_implements('field_attach_rename_bundle') as $module) { // Let other modules act on renaming the bundle.
$function = $module . '_field_attach_rename_bundle'; module_invoke_all('field_attach_rename_bundle', $obj_type, $bundle_old, $bundle_new);
$function($obj_type, $bundle_old, $bundle_new);
}
} }
/** /**
...@@ -1359,10 +1352,7 @@ function field_attach_delete_bundle($obj_type, $bundle) { ...@@ -1359,10 +1352,7 @@ function field_attach_delete_bundle($obj_type, $bundle) {
field_cache_clear(); field_cache_clear();
// Let other modules act on deleting the bundle. // Let other modules act on deleting the bundle.
foreach (module_implements('field_attach_delete_bundle') as $module) { module_invoke_all('field_attach_delete_bundle', $obj_type, $bundle, $instances);
$function = $module . '_field_attach_delete_bundle';
$function($obj_type, $bundle, $instances);
}
} }
......
...@@ -420,9 +420,9 @@ function forum_comment_delete($comment) { ...@@ -420,9 +420,9 @@ function forum_comment_delete($comment) {
} }
/** /**
* Implement hook_field_attach_pre_insert(). * Implement hook_field_storage_pre_insert().
*/ */
function forum_field_attach_pre_insert($obj_type, $object, $skip_fields) { function forum_field_storage_pre_insert($obj_type, $object, &$skip_fields) {
if ($obj_type == 'node' && $object->status && _forum_node_check_node_type($object)) { if ($obj_type == 'node' && $object->status && _forum_node_check_node_type($object)) {
$query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp')); $query = db_insert('forum_index')->fields(array('nid', 'title', 'tid', 'sticky', 'created', 'comment_count', 'last_comment_timestamp'));
foreach ($object->taxonomy_forums as $language) { foreach ($object->taxonomy_forums as $language) {
...@@ -443,9 +443,9 @@ function forum_field_attach_pre_insert($obj_type, $object, $skip_fields) { ...@@ -443,9 +443,9 @@ function forum_field_attach_pre_insert($obj_type, $object, $skip_fields) {
} }
/** /**
* Implement hook_field_attach_pre_update(). * Implement hook_field_storage_pre_update().
*/ */
function forum_field_attach_pre_update($obj_type, $object, $skip_fields) { function forum_field_storage_pre_update($obj_type, $object, &$skip_fields) {
$first_call = &drupal_static(__FUNCTION__, array()); $first_call = &drupal_static(__FUNCTION__, array());
if ($obj_type == 'node' && $object->status && _forum_node_check_node_type($object)) { if ($obj_type == 'node' && $object->status && _forum_node_check_node_type($object)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment