#645926 by Damien Tournoud and yched: hook_field_storage_details() should be per-field, not per-instance. Allows Views/Field integration to get unblocked.

merge-requests/26/head
Angie Byron 2010-01-13 04:37:03 +00:00
parent ac581679b0
commit 52f99dc071
6 changed files with 14 additions and 21 deletions

View File

@ -1134,8 +1134,6 @@ function hook_field_storage_info_alter(&$info) {
*
* @param $field
* A field structure.
* @param $instance
* A field instance structure.
* @return
* An array of details.
* - The first dimension is a store type (sql, solr, etc).
@ -1143,24 +1141,19 @@ function hook_field_storage_info_alter(&$info) {
* FIELD_LOAD_CURRENT or FIELD_LOAD_REVISION.
* - Other dimensions are specific to the field storage module.
*/
function hook_field_storage_details($field, $instance) {
function hook_field_storage_details($field) {
}
/**
* Perform alterations on Field API storage details.
*
* The storage details are appended to the field instance structure after this
* hook is invoked. Read and alter the $details only.
*
* @param $details
* An array of storage details for fields as exposed by
* hook_field_storage_details() implementations.
* @param $field
* A field structure.
* @param $instance
* A field instance structure.
*/
function hook_field_storage_details_alter(&$details, $field, $instance) {
function hook_field_storage_details_alter(&$details, $field) {
}
/**

View File

@ -223,11 +223,6 @@ function _field_info_collate_fields($reset = FALSE) {
// are thus not in $definitions['instances'].
$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['object_type']][$instance['bundle']][$instance['field_name']]['storage_details'] = $details;
}
}
@ -248,6 +243,11 @@ function _field_info_prepare_field($field) {
$field['settings'] += field_info_field_settings($field['type']);
$field['storage']['settings'] += field_info_storage_settings($field['storage']['type']);
// Add storage details.
$details = (array) module_invoke($field['storage']['module'], 'field_storage_details', $field);
drupal_alter('field_storage_details', $details, $field, $instance);
$field['storage']['details'] = $details;
return $field;
}

View File

@ -678,7 +678,7 @@ function field_sql_storage_field_storage_purge_field($field) {
/**
* Implements hook_field_storage_details().
*/
function field_sql_storage_field_storage_details($field, $instance) {
function field_sql_storage_field_storage_details($field) {
$details = array();
// Add field columns.

View File

@ -383,10 +383,10 @@ class FieldSqlStorageTestCase extends DrupalWebTestCase {
$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.'));
$this->assertTrue(array_key_exists('sql', $field['storage']['details']), t('The storage type is SQL.'));
// The SQL details are indexed by table name.
$details = $instance['storage_details']['sql'];
$details = $field['storage']['details']['sql'];
$this->assertTrue(array_key_exists($current, $details[FIELD_LOAD_CURRENT]), t('Table name is available in the instance array.'));
$this->assertTrue(array_key_exists($revision, $details[FIELD_LOAD_REVISION]), t('Revision table name is available in the instance array.'));

View File

@ -328,9 +328,9 @@ class FieldAttachStorageTestCase extends FieldAttachTestCase {
$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.'));
$this->assertTrue(array_key_exists('drupal_variables', $field['storage']['details']), t('The storage type is Drupal variables.'));
$details = $instance['storage_details']['drupal_variables'];
$details = $field['storage']['details']['drupal_variables'];
// The field_test storage details are indexed by variable name. The details
// are altered, so moon and mars are correct for this test.

View File

@ -26,7 +26,7 @@ function field_test_field_storage_info() {
/**
* Implements hook_field_storage_details().
*/
function field_test_field_storage_details($field, $instance) {
function field_test_field_storage_details($field) {
$details = array();
// Add field columns.
@ -47,7 +47,7 @@ function field_test_field_storage_details($field, $instance) {
*
* @see FieldAttachStorageTestCase::testFieldStorageDetailsAlter()
*/
function field_test_field_storage_details_alter(&$details, $field, $instance) {
function field_test_field_storage_details_alter(&$details, $field) {
// For testing, storage details are changed only because of the field name.
if ($field['field_name'] == 'field_test_change_my_details') {