Many use cases for hook_f_a_X() implementations will operate on a single given entity type, with a if ($entity_type == 'some_entity') { wrapping the function inner code.

After #765860: drupal_alter() fails to order modules correctly in some cases, a hook_f_a_X_[entity_type]() variant would result in less no-op function calls.

No time to work on a patch for the next couple days, just creating the issue.

Comments

sun’s picture

sun’s picture

I guess you primarily mean _field_invoke() ?

Issue with that is that it's not using drupal_alter(). But I agree that this would be helpful for performance and code flow. We'd need to introduce a similar technique for module_invoke(), I guess.

That said, I always wondered why drupal_alter() is much more advanced than our module_invoke*() functions...

effulgentsia’s picture

Subscribing. Push the code in drupal_alter() that supports $type as an array into module_implements(), letting it support $hook as an array? Is there sufficient buy-in to get that into D7?

sun’s picture

How could that work out? Usually the code flow is like this:

  foreach (module_implements(array('info', 'super_info')) as $module) {
    $function = $module . '_' . ???
    $result = $function();
  }

or

  $result = module_invoke($module, array('info', 'super_info'), $foo, $bar);

The only location where it would make more sense to me is:

  $results = module_invoke_all(array('info', 'super_info'), $foo, $bar);

However, http://api.drupal.org/api/function/_field_invoke/7 is really far more than a simple module_invoke()...

If there was a module API function that would look and work like the following, then it would start to make sense:

  module_implements_invoke(array('hook1', 'hook2'), function ($module, $hook, $function) {
    // $function == $module . '_' . $hook;
    $results[$module] = $function($foo, $bar);
  });

LOL ;)

sun’s picture

Version: 7.x-dev » 8.x-dev

Looks like we want to tackle module_implements() in the same way as drupal_alter() as early as possible in D8 :)

fago’s picture

subscribe

jhedstrom’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)

I think this has been reworked entirely. See https://www.drupal.org/node/2193813.