From 2afba19644fe40faa4fb0d841e666e19c2d372eb Mon Sep 17 00:00:00 2001 From: Bob Vincent Date: Thu, 22 Sep 2011 21:38:59 -0400 Subject: [PATCH] Warn if a module implements two or more different kinds of field hooks. --- modules/field/field.install | 46 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/modules/field/field.install b/modules/field/field.install index 16b09e1c9251e9c520a9dddb61f541093bc6a34e..7ce50c8ca99a006f7d68a8aba4af307238d77491 100644 --- a/modules/field/field.install +++ b/modules/field/field.install @@ -375,3 +375,49 @@ function _update_7000_field_create_instance($field, &$instance) { ->fields($record) ->execute(); } + +/** + * Implements hook_requirements(). + * + * Warns if any module implements more than one of the following: + * - hook_field_storage_info() or hook_field_storage_info_alter() + * - hook_field_info() or hook_field_info_alter() + * - hook_entity_info() or hook_entity_info_alter() + */ +function field_requirements($phase) { + if ($phase !== 'runtime') { + return array(); + } + $requirements = array(); + // Gather the storage hook modules. + $storages = array_merge(module_implements('field_storage_info'), module_implements('field_storage_info_alter')); + $storages = array_combine($storages, $storages); + // Gather the field hook modules. + $fields = array_merge(module_implements('field_info'), module_implements('field_info_alter')); + $fields = array_combine($fields, $fields); + // Gather the entity hook modules. + $entities = array_merge(module_implements('entity_info'), module_implements('entity_info_alter')); + $entities = array_combine($entities, $entities); + // Look for modules that implement both storage and field hooks. + foreach (array_intersect_key($storages, $fields) as $module) { + $requirements[] = array( + 'title' => t('Module %module should not define both a storage_info and a field_info hook.', array('%module' => $module)), + 'severity' => REQUIREMENT_WARNING, + ); + } + // Look for modules that implement both field and entity hooks. + foreach (array_intersect_key($fields, $entities) as $module) { + $requirements[] = array( + 'title' => t('Module %module should not define both a field_info and an entity_info hook.', array('%module' => $module)), + 'severity' => REQUIREMENT_WARNING, + ); + } + // Look for modules that implement both entity and storage hooks. + foreach (array_intersect_key($entities, $storages) as $module) { + $requirements[] = array( + 'title' => t('Module %module should not define both an entity_info and a storage_info hook.', array('%module' => $module)), + 'severity' => REQUIREMENT_WARNING, + ); + } + return $requirements; +} -- 1.7.5.4