Field API data structures
Represent Field API fields and instances.
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 objects. 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 objects are (currently) represented as an array of key/value pairs. The object properties are:
@param array $field:
- id (integer, read-only) The primary identifier of the field. It is assigned automatically by field_create_field().
- field_name (string) The name of the field. Each field name is unique within Field API. When a field is attached to an object, the field's data is stored in $object->$field_name.
- type (string) The type of the field, such as 'text' or 'image'. Field types are defined by modules that implement hook_field_info().
- cardinality (integer) The number of values the field can hold. Legal values are any positive integer or FIELD_CARDINALITY_UNLIMITED.
- translatable (integer) Whether the field is translatable.
- locked (integer) TODO: undefined.
- module (string, read-only) The name of the module that implements the field type.
- active (integer, read-only) TRUE if the module that implements the field type is currently enabled, FALSE otherwise.
- deleted (integer, read-only) TRUE if this field has been deleted, FALSE otherwise. Deleted fields are ignored by the Field Attach API. This property exists because fields can be marked for deletion but only actually destroyed by a separate garbage-collection process.
- columns (array, read-only). An array of the Field API columns used to store each value of this field. The column list may depend on field settings; it is not constant per field type. Field API column specifications are exactly like Schema API column specifications but, depending on the field storage module in use, the name of the column may not represent an actual column in an SQL database.
- indexes (array). An array of indexes on data columns, using the same definition format as Schema API index specifications. Only columns that appear in the 'columns' setting are allowed. Note that field types can specify default indexes, which can be modified or added to when creating a field.
- settings (array) A sub-array of key/value pairs of field-type-specific settings. Each field type module defines and documents its own field settings.
- storage (array)
A sub-array of key/value pairs identifying the storage backend to use for
the for the field.
- type (string) The storage backend used by the field. Storage backends are defined by modules that implement hook_field_storage_info().
- module (string, read-only) The name of the module that implements the storage backend.
- active (integer, read-only) TRUE if the module that implements the storage backend is currently enabled, FALSE otherwise.
- settings (array) A sub-array of key/value pairs of settings. Each storage backend defines and documents its own settings.
Field Instance objects are (currently) represented as an array of key/value pairs. The object properties are:
@param array $instance:
- id (integer, read-only) The primary identifier of this field instance. It is assigned automatically by field_create_instance().
- field_id (integer, read-only) The foreign key of the field attached to the bundle by this instance. It is populated automatically by field_create_instance().
- field_name (string) The name of the field attached to the bundle by this instance.
- object_type (string) The name of the object type the instance is attached to.
- bundle (string) The name of the bundle that the field is attached to.
- label (string) A human-readable label for the field when used with this bundle. For example, the label will be the title of Form API elements for this instance.
- description (string) A human-readable description for the field when used with this bundle. For example, the description will be the help text of Form API elements for this instance.
- required (integer) TRUE if a value for this field is required when used with this bundle, FALSE otherwise. Currently, required-ness is only enforced during Form API operations, not by field_attach_load(), field_attach_insert(), or field_attach_update().
- default_value_function (string) The name of the function, if any, that will provide a default value.
- deleted (integer, read-only) TRUE if this instance has been deleted, FALSE otherwise. Deleted instances are ignored by the Field Attach API. This property exists because instances can be marked for deletion but only actually destroyed by a separate garbage-collection process.
- settings (array) A sub-array of key/value pairs of field-type-specific instance settings. Each field type module defines and documents its own instance settings.
- widget (array)
A sub-array of key/value pairs identifying the Form API input widget
for the field when used by this bundle.
- type (string) The type of the widget, such as text_textfield. Widget types are defined by modules that implement hook_field_widget_info().
- settings (array) A sub-array of key/value pairs of widget-type-specific settings. Each field widget type module defines and documents its own widget settings.
- weight (float) The weight of the widget relative to the other elements in object edit forms.
- module (string, read-only) The name of the module that implements the widget type.
- display (array)
A sub-array of key/value pairs identifying build modes and the way the
field values should be displayed in each build mode.
- full (array)
A sub-array of key/value pairs of the display options to be used
when the field is being displayed in the "full" build mode.
- label (string) Position of the label. 'inline', 'above' and 'hidden' are the values recognized by the default 'field' theme implementation.
- type (string) The type of the display formatter, or 'hidden' for no display.
- settings (array) A sub-array of key/value pairs of display options specific to the formatter.
- weight (float)
The weight of the field relative to the other object components
displayed in this build mode.
- module (string, read-only) The name of the module which implements the display formatter.
- teaser
- ...
- other_build_mode
- ...
- full (array)
A sub-array of key/value pairs of the display options to be used
when the field is being displayed in the "full" build mode.
Bundles are represented by two strings, an entity type and a bundle name.
TODO D7 : document max length for field types, widget types, formatter names...
Login or register to post comments