I'm trying to unset hook_field_storage_load() and hook_field_storage_write() in hook_module_implements_alter() without success. Is there any other way to turn off those hooks?

  • Are you sure the hook is firing? That one is weird. – mpdonadio May 28 '13 at 16:33
  • Thank's MDP, I'm sure, I'm trying to unset mongodb_field_storage_field_storage_load(), I'm sure its firing. When I put in hook_module_implements_alter() 'dpm($hook);' I see all hooks after clear cache: field_storage_details_alter, field_storage_pre_load, field_storage_info, field_storage_info_alter, but not field_storage_load? – malcolm May 28 '13 at 16:54

TL;DR hook_module_implements_alter() is not invoked when mongodb_field_storage_field_storage_load() is needed. You cannot achieve what you are trying.

The function that invokes hook_field_storage_load() is field_attach_load(), which contains the following code.

// Invoke hook_field_storage_load() on the relevant storage backends.
foreach ($storages as $storage => $fields) {
  $storage_info = field_info_storage_types($storage);
  module_invoke($storage_info['module'], 'field_storage_load', $entity_type, $queried_entities, $age, $fields, $options);

module_invoke() calls module_hook(), which contains the following code.

  $function = $module . '_' . $hook;
  if (function_exists($function)) {
    return TRUE;
  // A
  // If the hook implementation does not exist, check whether it may live in an
  // optional include file registered via hook_hook_info().
  $hook_info = module_hook_info();
  if (isset($hook_info[$hook]['group'])) {
    module_load_include('inc', $module, $module . '.' . $hook_info[$hook]['group']);
    if (function_exists($function)) {
      return TRUE;

Since mongodb_field_storage_field_storage_load() is contained in mongodb_field_storage.module, your implementation of hook_module_implements_alter() will not be called. In fact function_exists($function) returns TRUE when $function is equal to 'mongodb_field_storage_field_storage_load', and the part of the code after the line marked with // A will not be executed.

|improve this answer|||||
  • Thanks for the detailed explanation. So what to do to not hack modules? My goal is the implementation of the custom entity controllers to avoid mysql query. Everything works great, except that mongodb_field_storage_field_storage_load() contain unnecessary a second time query, because we have already loaded the full node object with fields from mongodb... – malcolm May 28 '13 at 21:38
  • In my understanding, field_attach_load() is called from DrupalDefaultEntityController::attachLoad(), so should be fine if I'll put in my CustomNodeController a attachLoad() function with mymodule_field_attach_load(), which will be a copy of the original function, with the exception of only module_invoke($storage_info['module'], 'field_storage_load', ...), which will be replaced with my copy of mongodb_field_storage_field_storage_load()? – malcolm May 28 '13 at 21:38
  • Sorry for my poor English, I hope I wrote clearly :) – malcolm May 28 '13 at 21:39
  • As far as I can see, there 6 functions/methods that call field_attach_load(). If you are just concerned about the hook being called from the entity controller, you can implement a new entity controller. Remember that in a module you cannot define a function/hook with the same name of a function/hook implemented by another module. In other words, in my module I cannot define node_load() because PHP would throw an error about a redefined function. – kiamlaluno May 29 '13 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.