FieldDefinitionInterface

Defines an interface for entity field definitions.

An entity field is a data object that holds the values of a particular field for a particular entity (see \Drupal\Core\Field\FieldItemListInterface). For example, $node_1->body and $node_2->body contain different data and therefore are different field objects.

In contrast, an entity field *definition* is an object that returns information *about* a field (e.g., its type and settings) rather than its values. As such, if all the information about $node_1->body and $node_2->body is the same, then the same field definition object can be used to describe both.

It is up to the class implementing this interface to manage where the information comes from. For example, field.module provides an implementation based on two levels of configuration. It allows the site administrator to add custom fields to any entity type and bundle via the "field_storage_config" and "field_config" configuration entities. The former for storing configuration that is independent of which entity type and bundle the field is added to, and the latter for storing configuration that is specific to the entity type and bundle. The class that implements "field_config" configuration entities also implements this interface, returning information from either itself, or from the corresponding "field_storage_config" configuration, as appropriate.

However, entity base fields, such as $node->title, are not managed by field.module and its "field_storage_config"/"field_config" configuration entities. Therefore, their definitions are provided by different objects based on the class \Drupal\Core\Field\BaseFieldDefinition, which implements this interface as well.

Field definitions may fully define a concrete data object (e.g., $node_1->body), or may provide a best-guess definition for a data object that might come into existence later. For example, $node_1->body and $node_2->body may have different definitions (e.g., if the node types are different). When adding the "body" field to a View that can return nodes of different types, the View can get a field definition that represents the "body" field abstractly, and present Views configuration options to the administrator based on that abstract definition, even though that abstract definition can differ from the concrete definition of any particular node's body field.

Hierarchy

File

core/lib/Drupal/Core/Field/FieldDefinitionInterface.php, line 51

Namespace

Drupal\Core\Field

Members

Name Modifiers Type Description
CacheableDependencyInterface::getCacheContexts public function The cache contexts associated with this object.
CacheableDependencyInterface::getCacheMaxAge public function The maximum age for which this object may be cached.
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object.
DataDefinitionInterface::addConstraint public function Adds a validation constraint.
DataDefinitionInterface::createFromDataType public static function Creates a new data definition object.
DataDefinitionInterface::getClass public function Returns the class used for creating the typed data object.
DataDefinitionInterface::getConstraint public function Returns a validation constraint.
DataDefinitionInterface::getConstraints public function Returns an array of validation constraints.
DataDefinitionInterface::getDataType public function Returns the data type of the data.
DataDefinitionInterface::getDescription public function Returns a human readable description.
DataDefinitionInterface::getLabel public function Returns a human readable label.
DataDefinitionInterface::getSetting public function Returns the value of a given setting.
DataDefinitionInterface::getSettings public function Returns the array of settings, as required by the used class.
DataDefinitionInterface::isComputed public function Determines whether the data value is computed.
DataDefinitionInterface::isList public function Returns whether the data is multi-valued, i.e. a list of data items.
DataDefinitionInterface::isReadOnly public function Determines whether the data is read-only.
FieldDefinitionInterface::getConfig public function Gets an object that can be saved in configuration.
FieldDefinitionInterface::getDefaultValue public function Returns the default value for the field in a newly created entity.
FieldDefinitionInterface::getDefaultValueCallback public function Returns the default value callback for the field.
FieldDefinitionInterface::getDefaultValueLiteral public function Returns the default value literal for the field.
FieldDefinitionInterface::getDisplayOptions public function Returns the default display options for the field.
FieldDefinitionInterface::getFieldStorageDefinition public function Returns the field storage definition.
FieldDefinitionInterface::getName public function Returns the machine name of the field.
FieldDefinitionInterface::getTargetBundle public function Gets the bundle the field is attached to.
FieldDefinitionInterface::getTargetEntityTypeId public function Returns the ID of the entity type the field is attached to.
FieldDefinitionInterface::getType public function Returns the field type.
FieldDefinitionInterface::isDisplayConfigurable public function Returns whether the display for the field can be configured.
FieldDefinitionInterface::isRequired public function Returns whether the field can be empty. Overrides DataDefinitionInterface::isRequired
FieldDefinitionInterface::isTranslatable public function Returns whether the field is translatable.
ListDataDefinitionInterface::createFromItemType public static function Creates a new list data definition for items of the given data type.
ListDataDefinitionInterface::getItemDefinition public function Gets the data definition of an item of the list.
doc_Drupal
2016-10-29 09:11:23
Comments
Leave a Comment

Please login to continue.