Problem

info hooks have one major design gap: if provided info changes, how to invalidate cached dependent data?
(in dataflow speak: we have only a pull and no push mechanism.)

examples:
* if hook_menu() info changes you do a menu_rebuild() (and pray that no other modules caches hook_menu() info)
* commerce_custom_line_items.module implements hook_commerce_line_items() and hardcodes a cache clear mechanism on behalf of commerce_line_items.module

Clarification

some hooks like hook_menu() are not explicitly named hook_foo_info(), but for this issue we call them info hooks too. this might change with #1751240: Fix naming pattern of info hooks.

Proposed solution

Invoking hook_foo_info_change() notifies all modules that
* hook_foo_info() data changed
* all caches need to be cleared
* and maybe other actions taken

in contrast to today's solution to e.g. calling menu_rebuild() any module can listen to this ntification.

Example

if dynamic_foo_provider.module implementing hook_foo_info() changes their info
then it calls

  // invoke hook_foo_info_change() and clear dependent caches
  module_invoke_all('foo_info_change', 'dynamic_foo_provider');

and any foo_info_consumer.module can invalidate its cache like this

/**
 * Implements hook_foo_info_change()
 *
 * clears the cache when provided info changes 
 * @see:http://drupal.org/node/1446808 
 *
 * TODO: for now we clear our whole cache if some module announces an info change
 * we might use $module and make this more granular later
 */
function foo_info_consumer_foo_info_change($module) {
  foo_info_consumer_clear_foo_cache();
}

About $module

The $module parameter can help to partially clear cache.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Damien Tournoud’s picture

We have a bigger problem with the pull mechanism, which is that we cannot manage dependencies between objects defined by two info hooks, as described in #1416558: hook_entity_info(), hook_schema(), and the field system are strongly bound to each other.

We should just move completely to a push mechanism, with an event that just says "please have fun pushing new objects now".

geek-merlin’s picture

Issue summary: View changes

added backref

geek-merlin’s picture

Issue summary: View changes

workaround for d.o filter

geek-merlin’s picture

thanks for sharing damien. i'll keep going for this one, keeping an eye on the issue you mentioned!

geek-merlin’s picture

Issue summary: View changes

better doc

geek-merlin’s picture

Issue summary: View changes

improved

geek-merlin’s picture

Title: Let info hook prividers announce changes (hook_foo_info_push()) » Implement hook family hook_foo_info_push()
Status: Needs review » Active
FileSize
791 bytes

Atteched an example, think we need (guessed) about 50 implementations like this.
And the api docs.

Kindly asking for architectural review.

EDIT: note that push() became change() in #6 which this patch does not yet reflect.

geek-merlin’s picture

Title: new hook family hook_foo_info_push() » Implement hook family hook_foo_info_push()
Status: Active » Needs review
Issue tags: +Needs architectural review
geek-merlin’s picture

Title: Implement hook family hook_foo_info_push() » Let info hook prividers announce changes (hook_foo_info_push())
geek-merlin’s picture

Issue summary: View changes

improved

geek-merlin’s picture

Title: Implement hook family hook_foo_info_push() » Let info hook prividers announce changes (info_change hooks)
Status: Active » Needs review

Changed terminology from "push" to "change" - far more intuitive.

donquixote’s picture

I want to kindly mention that with our poor hook naming scheme, every hook can make name clashes (or for D8, we should rather say, it increases the chance for unintended hook invocations in future contrib).
We generally ignore this problem, but we should be careful introducing a ton of hooks all at once.
Should we not rather introduce just one hook? Or would that have performance implications?

geek-merlin’s picture

Answered this on GDO to keep this issue focused.

donquixote’s picture

More thoughts over there, http://groups.drupal.org/node/267163#comment-850378
Esp, a suggested alternative system with a "dependency matrix"

donquixote’s picture

Issue summary: View changes

push => change

xjm’s picture

Title: Let info hook prividers announce changes (info_change hooks) » Let plugin managers announce changed definitions
Version: 8.0.x-dev » 8.1.x-dev
Component: other » plugin system
Status: Needs review » Active
Issue tags: -Needs architectural review

So, at this point, this issue is no longer relevant for Drupal 8, since most info hooks are done away with and replaced by plugin managers, which have their own mechanisms for updating plugin definitions. There's a possibility of rescoping this issue to be about having some sort of generic mechanism for this for plugins, I guess? I retitled along those lines. That or it's wontfix.

In any case setting to active, since the previous approach in the issue is no longer applicable, and bumping to 8.1.x since we're unlikely to get below thresholds to add features in 8.0.x. We can move it back later if we do get under thresholds.

dawehner’s picture

After talking with chx this morning he wanted to open up a follow up for block, given that with derivatives you
cannot have a huge number of custom blocks. On a more abstract level the menu links introduces a system where you
can add new plugins and actually store them: #2312383: Provide a plugin manager interface which allows to add new definitions/update some/remove some

On top of that there is #2031859: Invoke an event[s] when a plugin ID disappears which ensures that things are actually announced.

geek-merlin’s picture

@xjm #10: i totally agree.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.