Field Attach API

Operates on Field API data attached to Drupal entities.

Field Attach API functions load, store, display, generate Field API structures, and perform a variety of other functions for field data attached to individual entities.

Field Attach API functions generally take $entity_type and $entity arguments along with additional function-specific arguments. $entity_type is the type of the fieldable entity, such as 'node' or 'user', and $entity is the entity itself.

An entity plugin's annotation is how entity types define if and how Field API should operate on their entity objects. Notably, the 'fieldable' property needs to be set to TRUE.

The Field Attach API uses the concept of bundles: the set of fields for a given entity is defined on a per-bundle basis. The collection of bundles for an entity type is added to the entity definition with hook_entity_info_alter(). For instance, node_entity_info_alter() exposes each node type as its own bundle. This means that the set of fields of a node is determined by the node type.

The Field API reads the bundle name for a given entity from a particular property of the entity object, and hook_entity_info_alter() defines which property to use. For instance, node_entity_info_alter() specifies:

$info['entity_keys']['bundle'] = 'type';

This indicates that for a particular node object, the bundle name can be found in $node->type. This property can be omitted if the entity type only exposes a single bundle (all entities of this type have the same collection of fields). This is the case for the 'user' entity type.

Most Field Attach API functions define a corresponding hook function that allows any module to act on Field Attach operations for any entity after the operation is complete, and access or modify all the field, form, or display data for that entity and operation. For example, field_attach_view() invokes hook_field_attach_view_alter(). These all-module hooks are distinct from those of the Field Types API, such as hook_field_load(), that are only invoked for the module that defines a specific field type.

field_attach_load(), field_attach_insert(), and field_attach_update() also define pre-operation hooks, e.g. hook_field_attach_pre_load(). These hooks run before the corresponding Field Storage API and Field Type API operations. They allow modules to define additional storage locations (e.g. denormalizing, mirroring) for field data on a per-field basis. They also allow modules to take over field storage completely by instructing other implementations of the same hook and the Field Storage API itself not to operate on specified fields.

The pre-operation hooks do not make the Field Storage API irrelevant. The Field Storage API is essentially the "fallback mechanism" for any fields that aren't being intercepted explicitly by pre-operation hooks.

Field language API provides information about the structure of field objects.

See Field API for information about the other parts of the Field API.


drupal/core/modules/field/, line 49
Field attach API, allowing entities (nodes, users, ...) to be 'fieldable'.


Namesort descending Location Description
field_attach_create_bundle drupal/core/modules/field/ Notifies field.module that a new bundle was created.
field_attach_delete drupal/core/modules/field/ Deletes field data for an existing entity. This deletes all revisions of field data for the entity.
field_attach_delete_bundle drupal/core/modules/field/ Notifies field.module the a bundle was deleted.
field_attach_delete_revision drupal/core/modules/field/ Delete field data for a single revision of an existing entity. The passed entity must have a revision ID attribute.
field_attach_form drupal/core/modules/field/ Adds form elements for all fields for an entity to a form structure.
field_attach_form_validate drupal/core/modules/field/ Performs field validation against form-submitted field values.
field_attach_insert drupal/core/modules/field/ Save field data for a new entity.
field_attach_load drupal/core/modules/field/ Loads fields for the current revisions of a group of entities.
field_attach_load_revision drupal/core/modules/field/ Loads all fields for previous versions of a group of entities.
field_attach_prepare_translation drupal/core/modules/field/ Prepares an entity for translation.
field_attach_prepare_view drupal/core/modules/field/ Prepares field data prior to display.
field_attach_preprocess drupal/core/modules/field/ Populates the template variables with the available field values.
field_attach_presave drupal/core/modules/field/ Performs necessary operations just before fields data get saved.
field_attach_rename_bundle drupal/core/modules/field/ Notifies field.module that a bundle was renamed.
field_attach_submit drupal/core/modules/field/ Performs necessary operations on field data submitted by a form.
field_attach_update drupal/core/modules/field/ Saves field data for an existing entity.
field_attach_validate drupal/core/modules/field/ Performs field validation against the field data in an entity.
field_attach_view drupal/core/modules/field/ Returns a renderable array for the fields on an entity.
field_invoke_method drupal/core/modules/field/ Invokes a method on all the fields of a given entity.
field_invoke_method_multiple drupal/core/modules/field/ Invokes a method across fields on multiple entities.
hook_field_attach_create_bundle drupal/core/modules/field/field.api.php Act on field_attach_create_bundle().
hook_field_attach_delete drupal/core/modules/field/field.api.php Act on field_attach_delete().
hook_field_attach_delete_bundle drupal/core/modules/field/field.api.php Act on field_attach_delete_bundle.
hook_field_attach_delete_revision drupal/core/modules/field/field.api.php Act on field_attach_delete_revision().
hook_field_attach_form drupal/core/modules/field/field.api.php Act on field_attach_form().
hook_field_attach_insert drupal/core/modules/field/field.api.php Act on field_attach_insert().
hook_field_attach_load drupal/core/modules/field/field.api.php Act on field_attach_load().
hook_field_attach_prepare_translation_alter drupal/core/modules/field/field.api.php Perform alterations on field_attach_prepare_translation().
hook_field_attach_preprocess_alter drupal/core/modules/field/field.api.php Alter field_attach_preprocess() variables.
hook_field_attach_presave drupal/core/modules/field/field.api.php Act on field_attach_presave().
hook_field_attach_purge drupal/core/modules/field/field.api.php Act on field_purge_data().
hook_field_attach_rename_bundle drupal/core/modules/field/field.api.php Act on field_attach_rename_bundle().
hook_field_attach_submit drupal/core/modules/field/field.api.php Act on field_attach_submit().
hook_field_attach_update drupal/core/modules/field/field.api.php Act on field_attach_update().
hook_field_attach_validate drupal/core/modules/field/field.api.php Act on field_attach_validate().
hook_field_attach_view_alter drupal/core/modules/field/field.api.php Perform alterations on field_attach_view() or field_view_field().
hook_field_available_languages_alter drupal/core/modules/field/field.api.php Alter field_available_languages() values.
hook_field_language_alter drupal/core/modules/field/field.api.php Perform alterations on field_language() values.
_field_invoke drupal/core/modules/field/ Invoke a field hook.
_field_invoke_default drupal/core/modules/field/ Invoke field.module's version of a field hook.
_field_invoke_formatter_target drupal/core/modules/field/ Defines a 'target function' for field_invoke_method().
_field_invoke_get_instances drupal/core/modules/field/ Retrieves a list of instances to operate on.
_field_invoke_multiple drupal/core/modules/field/ Invokes a field hook across fields on multiple entities.
_field_invoke_multiple_default drupal/core/modules/field/ Invoke field.module's version of a field hook on multiple entities.
_field_invoke_widget_target drupal/core/modules/field/ Defines a 'target function' for field_invoke_method().