It appears hook_field_schema() has moved its implementation to .install files since I last used it -- see http://api.drupal.org/api/drupal/modules--field--field.api.php/function/...

As far as I can tell, now this can't be invoked with module_invoke(), since the .install files won't be loaded.

I reckon this can be fixed by field module implementing hook_hook_info() -- however I'm not sure this will work with 'install' as a group since install files are a special case.

Comments

joachim’s picture

Status: Active » Needs review
StatusFileSize
new645 bytes

Seems to work.

If this is the right approach, then presumably other hooks that live in .install files should get similar treatment?

damien tournoud’s picture

Status: Needs review » Active

You just have to load the install file of the corresponding module first.

  module_load_install($field['module']);
  $schema = (array) module_invoke($field['module'], 'field_schema', $field);
joachim’s picture

> You just have to load the install file of the corresponding module first.

Yes, you do.

But isn't the whole point of hook_hook_info() that you don't need to think about that?

sun’s picture

Status: Active » Closed (works as designed)

hook_hook_info() transforms the 'group' into $module.GROUP.inc, which is not what you want. $module.install is incompatible with the pattern.

joachim’s picture

Title: hook_field_schema() can't be invoked -- needs hook_hook_info() » let hook_hook_info() handle hooks in .install files
Version: 7.x-dev » 8.x-dev
Category: bug » feature
Status: Closed (works as designed) » Active

Ok then let's punt this to D8, because:

> But isn't the whole point of hook_hook_info() that you don't need to think about that?

xano’s picture

Title: let hook_hook_info() handle hooks in .install files » Let hook_hook_info() handle hooks in .install files (aka "rename MODULE.install to MODULE.install.inc")

What about we rename MODULE.install to MODULE.install.inc for consistency? We can do this by setting the group for install file related hooks and slowly migrate .install files to .install.inc files. The only potential problem I see so far are hook_update_N() implementations.

joachim’s picture

Nobody should be calling hook_update_N() implementations apart from the update system itself, so we can probably ignore those hooks.

As an alternative to a big renaming exercise, we could let the system that consumes hook_hook_info() information know that 'install' is a special case.

xano’s picture

Nobody should be calling hook_update_N() implementations apart from the update system itself, so we can probably ignore those hooks.

Probably (never say never), but they're still hooks. In addition to that, hooks like hook_form_FORM_ID_alter() or hook_ENTITY_TYPE_ACTION() cause the same issue. I can live with hook_update_N() files living in MODULE.install.inc and letting the update system include the file just it does for MODULE.install. That would already be an improvement over the current approach. Ideally (perhaps after this issue gets in), we figure out a way to make hook_hook_info() work for dynamic hooks. Perhaps it should function like hook_forms()?

As an alternative to a big renaming exercise, we could let the system that consumes hook_hook_info() information know that 'install' is a special case.

Then we would replace the current special case with a new one, which defeats this issue's purpose of creating unity and consistency. Also, renaming files isn't that big of a deal. History is kept, and with changes to a few functions that are hardcoded to work with .install files, we can make it work.

xano’s picture

Now the upgrade system will be completely overthrown in D8, and hook_update_n() may cease to exist, we may be able to make *.install files work with the existing hook system.

joachim’s picture

Issue tags: -API change

> Then we would replace the current special case with a new one, which defeats this issue's purpose of creating unity and consistency.

Yes and no.

It replaces the special case with a new one, but crucially, it *moves* the special case somewhere else.

Consider who currently needs to know about this special case? Any developer who wants to invoke a hook needs to know the rule:

- use module_invoke_all() for any hook; the file is loaded automatically for you
- EXCEPT if it's a hook in MODULE.install, where you need to load the file yourself

If we make hook_hook_info() aware of hooks in .install files, then the rule for developers who want to invoke a hook becomes the much simpler:

- use module_invoke_all() for any hook; the file is loaded automatically for you
- there are no exceptions

Who now needs to know about this special case?

- anyone working with the internals of hook_hook_info() and module_implements() (which IIRC is where the file inclusion happens)
- anyone wanting to *invent* a new hook that belongs in MODULE.install

That's far fewer people. In fact, I'd say that's probably just core, as I've never seen a contrib module that invents hooks that go in .install.

So while we only move the inconsistency to a new place instead of cleaning it up, we drastically reduce the number of people who are affected by it.

xano’s picture

Issue tags: +API change

Tagging.

xano’s picture

I'm not sure this API change will be accepted at this point. On the other hand, #1972304: Add a HookEvent will allow us to implement hooks as methods on any class registered as an event listener.

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should 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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

andypost’s picture

Issue summary: View changes
Status: Active » Closed (duplicate)