API page: https://api.drupal.org/api/drupal/modules!field!field.api.php/function/h...

Enter a descriptive title (above) relating to function hook_field_schema, then describe the problem you have found:

hook_field_schema() is not a true hook, but a magic callback. It is called ONLY for the module that defines a field type, to get the schema for a field of that type.

The flow in field_create_field() is:

- oh you want a new field do you?
- what type is it?
- which module defines the field type?
- call MODULE_field_schema() to get the schema for your new field.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

We have a lot of "hooks" like that. It just needs a sentence stating this.

joachim’s picture

Yup. something like:

This is invoked for a specific module by Field API, in order to obtain the database schema when creating a field.

jhodgdon’s picture

Issue tags: +Novice

"a specific module" is not very specific. :) How about "on the module that defines the field"?

joachim’s picture

"that defines the field type"

Which is a bit messy, as the sentence is referring ahead. But I'm sure some novice will be able to reword it more elegantly; the gist is there :)

ar-jan’s picture

How about This is invoked when a field is created, in order to obtain the database schema from the module that defines the field's type.?

Or maybe something like This is implemented by modules defining a field type, and is invoked when creating a field of that type in order to obtain the database schema.

jhodgdon’s picture

Sure, either one sounds fine to me. They both seem to get the point across clearly.

ar-jan’s picture

I notice the docs say all-caps should only be used for constants. Should 'MUST' in the line below be changed now that we're looking at this?

jhodgdon’s picture

Yeah, that wouldn't hurt.

ar-jan’s picture

Status: Active » Needs review
FileSize
628 bytes

.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

Looks perfect to me.

jhodgdon’s picture

If we're updating this line, would it make better sense to say "in your module.install file" rather than just ".install"?

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs review
joachim’s picture

Doesn't look like there's much consistency for this. In system.api.php alone:

modules/system/system.api.php
2996: * must reside in a module_name.install file, or it will not properly abort
3095: * hook_schema() which must live in your module's .install file.
3273: * .install file. The implementation can rely on the .module file being loaded.
3347: * Implementations of this hook should be placed in a mymodule.install file in
3445: * Implementations of this hook should be placed in a mymodule.install file in
3485: * If you remove some update functions from your mymodule.install file, you
3489: * Implementations of this hook should be placed in a mymodule.install file in
3514: * The uninstall hook must be implemented in the module's .install file. It
3540: * implemented in the module's .install file. The implementation can
3555: * implemented in the module's .install file. The implementation can rely

jhodgdon’s picture

Most of them either say "module's .install file" or "mymodule.install". Saying just " * This hook must be defined in .install " is less clear than either, IMO. Pick one. :)

ar-jan’s picture

Alright, let's go with "the module's .install file".

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! Looks good.

jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again! Committed to 7.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.