Field API

Attaches custom data fields to Drupal entities.

The Field API allows custom data fields to be attached to Drupal entities and takes care of storing, loading, editing, and rendering field data. Any entity type (node, user, etc.) can use the Field API to make itself "fieldable" and thus allow fields to be attached to it. Other modules can provide a user interface for managing custom fields via a web browser as well as a wide and flexible variety of data type, form element, and display format capabilities.

The Field API defines two primary data structures, Field and Instance, and the concept of a Bundle. A Field defines a particular type of data that can be attached to entities. A Field Instance is a Field attached to a single Bundle. A Bundle is a set of fields that are treated as a group by the Field Attach API and is related to a single fieldable entity type.

For example, suppose a site administrator wants Article nodes to have a subtitle and photo. Using the Field API or Field UI module, the administrator creates a field named 'subtitle' of type 'text' and a field named 'photo' of type 'image'. The administrator (again, via a UI) creates two Field Instances, one attaching the field 'subtitle' to the 'node' bundle 'article' and one attaching the field 'photo' to the 'node' bundle 'article'. When the node system uses the Field Attach API to load all fields for an Article node, it passes the node's entity type (which is 'node') and content type (which is 'article') as the node's bundle. field_attach_load() then loads the 'subtitle' and 'photo' fields because they are both attached to the 'node' bundle 'article'.

  • Field Types API: Defines field types, widget types, and display formatters. Field modules use this API to provide field types like Text and Node Reference along with the associated form elements and display formatters.
  • Field CRUD API: Create, updates, and deletes fields, bundles (a.k.a. "content types"), and instances. Modules use this API, often in hook_install(), to create custom data structures.
  • Field Attach API: Connects entity types to the Field API. Field Attach API functions load, store, generate Form API structures, display, and perform a variety of other functions for field data connected to individual entities. Fieldable entity types like node and user use this API to make themselves fieldable.
  • Field Info API: Exposes information about all fields, instances, widgets, and related information defined by or with the Field API.
  • Field Storage API: Provides a pluggable back -end storage system for actual field data. The default implementation, field_sql_storage.module, stores field data in the local SQL database.
  • Field API bulk data deletion: Cleans up after bulk deletion operations such as field_delete_field() and field_delete_instance().
  • Field language API: Provides native multilingual support for the Field API.

File

drupal/core/modules/field/field.module, line 23
Attach custom data fields to Drupal entities.

Functions

Namesort descending Location Description
field_access drupal/core/modules/field/field.module Determines whether the user has access to a given field.
field_bundle_settings drupal/core/modules/field/field.module Gets or sets administratively defined bundle settings.
field_cache_clear drupal/core/modules/field/field.module Clears the field info and field data caches.
field_cron drupal/core/modules/field/field.module Implements hook_cron().
field_data_type_info drupal/core/modules/field/field.module Implements hook_data_type_info() to register data types for all field types.
field_entity_create drupal/core/modules/field/field.module Implements hook_entity_create().
field_entity_field_info drupal/core/modules/field/field.module Implements hook_entity_field_info() to define all configured fields.
field_extract_bundle drupal/core/modules/field/field.module Extracts the bundle name from a bundle object.
field_field_widget_info_alter drupal/core/modules/field/field.module Implements hook_field_widget_info_alter().
field_filter_xss drupal/core/modules/field/field.module Filters an HTML string to prevent cross-site-scripting (XSS) vulnerabilities.
field_get_default_value drupal/core/modules/field/field.module Helper function to get the default value for a field on an entity.
field_get_items drupal/core/modules/field/field.module Returns the field items in the language they currently would be displayed.
field_has_data drupal/core/modules/field/field.module Determines whether a field has any data.
field_help drupal/core/modules/field/field.module Implements hook_help().
field_language_fallback drupal/core/modules/field/field.module Applies language fallback rules to the fields attached to the given entity.
field_modules_disabled drupal/core/modules/field/field.module Implements hook_modules_disabled().
field_modules_enabled drupal/core/modules/field/field.module Implements hook_modules_enabled().
field_page_build drupal/core/modules/field/field.module Implements hook_page_build().
field_populate_default_values drupal/core/modules/field/field.module Inserts a default value for each entity field not having one.
field_rebuild drupal/core/modules/field/field.module Implements hook_rebuild().
field_sync_field_status drupal/core/modules/field/field.module Refreshes the 'active' and 'storage[active]' values for fields.
field_system_info_alter drupal/core/modules/field/field.module Implements hook_system_info_alter().
field_theme drupal/core/modules/field/field.module Implements hook_theme().
field_ui_instance_load drupal/core/modules/field_ui/field_ui.module Menu loader callback: Loads a field instance based on field and bundle name.
field_view_field drupal/core/modules/field/field.module Returns a renderable array for the value of a single field in an entity.
field_view_mode_settings drupal/core/modules/field/field.module Returns view mode settings in a given bundle.
field_view_value drupal/core/modules/field/field.module Returns a renderable array for a single field value.
template_preprocess_field drupal/core/modules/field/field.module Prepares variables for field templates.
template_process_field drupal/core/modules/field/field.module Theme process function for theme_field() and field.html.twig.
_field_filter_items drupal/core/modules/field/field.module Filters out empty field values.
_field_filter_xss_allowed_tags drupal/core/modules/field/field.module Returns a list of tags allowed by field_filter_xss().
_field_filter_xss_display_allowed_tags drupal/core/modules/field/field.module Returns a human-readable list of allowed tags for display in help texts.
_field_sort_items drupal/core/modules/field/field.module Sorts items in a field according to user drag-and-drop reordering.
_field_sort_items_helper drupal/core/modules/field/field.module Callback for usort() within _field_sort_items().
_field_sort_items_value_helper drupal/core/modules/field/field.module Callback for usort() within theme_field_multiple_value_form().

Constants

Namesort descending Location Description
FIELD_BEHAVIOR_CUSTOM drupal/core/modules/field/field.module Value for field API indicating a widget can receive several field values.
FIELD_BEHAVIOR_DEFAULT drupal/core/modules/field/field.module Value for field API concerning widget default and multiple value settings.
FIELD_BEHAVIOR_NONE drupal/core/modules/field/field.module Value for field API indicating a widget doesn't accept default values.
FIELD_CARDINALITY_UNLIMITED drupal/core/modules/field/field.module Value for field API indicating a field accepts an unlimited number of values.
FIELD_LOAD_CURRENT drupal/core/modules/field/field.module Load the most recent version of an entity's field data.
FIELD_LOAD_REVISION drupal/core/modules/field/field.module Load the version of an entity's field data specified in the entity.