interface FieldStorageDefinitionInterface implements CacheableDependencyInterface (View source)

Defines an interface for entity field storage definitions.

Field storage definitions represent the part of full field definitions (see FieldDefinitionInterface) that is responsible for defining how the field is stored. While field definitions may differ by entity bundle, all of those bundle fields have to share the same common field storage definition. Thus, the storage definitions can be defined by entity type only. The bundle fields corresponding to a field storage definition may provide additional information; e.g., they may provide bundle-specific settings or constraints that are not present in the storage definition. However bundle fields may not override or alter any information provided by the storage definition except for the label and the description; e.g., any constraints and settings on the storage definition must be present on the bundle field as well.

Constants

CARDINALITY_UNLIMITED

Value indicating a field accepts an unlimited number of values.

Methods

string[]
getCacheContexts()

The cache contexts associated with this object.

string[]
getCacheTags()

The cache tags associated with this object.

int
getCacheMaxAge()

The maximum age for which this object may be cached.

string
getName()

Returns the machine name of the field.

string
getType()

Returns the field type.

array
getSettings()

Returns the storage settings.

mixed
getSetting(string $setting_name)

Returns the value of a given storage setting.

bool
isTranslatable()

Returns whether the field supports translation.

$this
setTranslatable(bool $translatable)

Sets whether the field supports translation.

bool
isRevisionable()

Returns whether the field storage is revisionable.

string
getLabel()

Returns the human-readable label for the field.

string|null
getDescription()

Returns the human-readable description for the field.

getOptionsProvider(string $property_name, FieldableEntityInterface $entity)

Gets an options provider for the given field item property.

bool
isMultiple()

Returns whether the field can contain multiple items.

int
getCardinality()

Returns the maximum number of items allowed for the field.

getPropertyDefinition(string $name)

Gets the definition of a contained property.

getPropertyDefinitions()

Gets an array of property definitions of contained properties.

string[]
getPropertyNames()

Returns the names of the field's subproperties.

string|null
getMainPropertyName()

Returns the name of the main property, if any.

string
getTargetEntityTypeId()

Returns the ID of the entity type the field is attached to.

array[]
getSchema()

Returns the field schema.

array[]
getColumns()

Returns the field columns, as defined in the field schema.

array[]
getConstraints()

Returns an array of validation constraints.

array
getConstraint(string $constraint_name)

Returns a validation constraint.

string
getProvider()

Returns the name of the provider of this field.

bool
hasCustomStorage()

Returns the storage behavior for this field.

bool
isBaseField()

Determines whether the field is a base field.

string
getUniqueStorageIdentifier()

Returns a unique identifier for the field storage.

bool
isDeleted()

Returns whether the field is deleted or not.

Details

string[] getCacheContexts()

The cache contexts associated with this object.

These identify a specific variation/representation of the object.

Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Return Value

string[]

An array of cache context tokens, used to generate a cache ID.

See also

CacheContextsManager::convertTokensToKeys

string[] getCacheTags()

The cache tags associated with this object.

When this object is modified, these cache tags will be invalidated.

Return Value

string[]

A set of cache tags.

int getCacheMaxAge()

The maximum age for which this object may be cached.

Return Value

int

The maximum time in seconds that this object may be cached.

string getName()

Returns the machine name of the field.

This defines how the field data is accessed from the entity. For example, if the field name is "foo", then $entity->foo returns its data.

Return Value

string

The field name.

string getType()

Returns the field type.

Return Value

string

The field type, i.e. the id of a field type plugin. For example 'text'.

See also

FieldTypePluginManagerInterface

array getSettings()

Returns the storage settings.

Each field type defines the settings that are meaningful for that type. For example, a text field can define a 'max_length' setting, and an image field can define an 'alt_field_required' setting.

The method always returns an array of all available settings for this field type, possibly with the default values merged in if values have not been provided for all available settings.

Return Value

array

An array of key/value pairs.

mixed getSetting(string $setting_name)

Returns the value of a given storage setting.

Parameters

string $setting_name

The setting name.

Return Value

mixed

The setting value.

bool isTranslatable()

Returns whether the field supports translation.

Return Value

bool

TRUE if the field supports translation.

$this setTranslatable(bool $translatable)

Sets whether the field supports translation.

Parameters

bool $translatable

Whether the field supports translation.

Return Value

$this

bool isRevisionable()

Returns whether the field storage is revisionable.

Note that if the entity type is revisionable and the field storage has a cardinality higher than 1, the field storage is considered revisionable by default.

Return Value

bool

TRUE if the field is revisionable.

string getLabel()

Returns the human-readable label for the field.

Return Value

string

The field label.

string|null getDescription()

Returns the human-readable description for the field.

This is displayed in addition to the label in places where additional descriptive information is helpful. For example, as help text below the form element in entity edit forms.

Return Value

string|null

The field description, or NULL if no description is available.

OptionsProviderInterface|null getOptionsProvider(string $property_name, FieldableEntityInterface $entity)

Gets an options provider for the given field item property.

Parameters

string $property_name

The name of the property to get options for; e.g., 'value'.

FieldableEntityInterface $entity

The entity for which the options should be provided.

Return Value

OptionsProviderInterface|null

An options provider, or NULL if no options are defined.

bool isMultiple()

Returns whether the field can contain multiple items.

Return Value

bool

TRUE if the field can contain multiple items, FALSE otherwise.

int getCardinality()

Returns the maximum number of items allowed for the field.

Possible values are positive integers or FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.

Return Value

int

The field cardinality.

DataDefinitionInterface|null getPropertyDefinition(string $name)

Gets the definition of a contained property.

Parameters

string $name

The name of property.

Return Value

DataDefinitionInterface|null

The definition of the property or NULL if the property does not exist.

DataDefinitionInterface[] getPropertyDefinitions()

Gets an array of property definitions of contained properties.

Return Value

DataDefinitionInterface[]

An array of property definitions of contained properties, keyed by property name.

string[] getPropertyNames()

Returns the names of the field's subproperties.

A field is a list of items, and each item can contain one or more properties. All items for a given field contain the same property names, but the values can be different for each item.

For example, an email field might just contain a single 'value' property, while a link field might contain 'title' and 'url' properties, and a text field might contain 'value', 'summary', and 'format' properties.

Return Value

string[]

The property names.

string|null getMainPropertyName()

Returns the name of the main property, if any.

Some field items consist mainly of one main property, e.g. the value of a text field or the @code target_id @endcode of an entity reference. If the field item has no main property, the method returns NULL.

Return Value

string|null

The name of the value property, or NULL if there is none.

string getTargetEntityTypeId()

Returns the ID of the entity type the field is attached to.

This method should not be confused with EntityInterface::getEntityTypeId() (configurable fields are config entities, and thus implement both interfaces):

  • FieldStorageDefinitionInterface::getTargetEntityTypeId() answers "as a field storage, which entity type are you attached to?".
  • EntityInterface::getEntityTypeId() answers "as a (config) entity, what is your own entity type?".

Return Value

string

The entity type ID.

array[] getSchema()

Returns the field schema.

Note that this method returns an empty array for computed fields which have no schema.

Return Value

array[]

The field schema, as an array of key/value pairs in the format returned by \Drupal\Core\Field\FieldItemInterface::schema():

  • columns: An array of Schema API column specifications, keyed by column name. This specifies what comprises a single value for a given field. No assumptions should be made on how storage backends internally use the original column name to structure their storage.
  • indexes: An array of Schema API index definitions. Some storage backends might not support indexes.
  • unique keys: An array of Schema API unique key definitions. Some storage backends might not support unique keys.
  • foreign keys: An array of Schema API foreign key definitions. Note, however, that depending on the storage backend specified for the field, the field data is not necessarily stored in SQL.

array[] getColumns()

Returns the field columns, as defined in the field schema.

Return Value

array[]

The array of field columns, keyed by column name, in the same format returned by getSchema().

See also

FieldStorageDefinitionInterface::getSchema

array[] getConstraints()

Returns an array of validation constraints.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Return Value

array[]

An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.

See also

Constraint

array getConstraint(string $constraint_name)

Returns a validation constraint.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.

Parameters

string $constraint_name

The name of the constraint, i.e. its plugin id.

Return Value

array

A validation constraint definition which can be used for instantiating a \Symfony\Component\Validator\Constraint object.

See also

Constraint

string getProvider()

Returns the name of the provider of this field.

Return Value

string

The provider name; e.g., the module name.

bool hasCustomStorage()

Returns the storage behavior for this field.

Indicates whether the entity type's storage should take care of storing the field values or whether it is handled separately; e.g. by the module providing the field.

Return Value

bool

FALSE if the storage takes care of storing the field, TRUE otherwise.

bool isBaseField()

Determines whether the field is a base field.

Base fields are not specific to a given bundle or a set of bundles. This excludes configurable fields, as they are always attached to a specific bundle.

Return Value

bool

Whether the field is a base field.

string getUniqueStorageIdentifier()

Returns a unique identifier for the field storage.

Return Value

string

bool isDeleted()

Returns whether the field is deleted or not.

Return Value

bool

TRUE if the field is deleted, FALSE otherwise.