FieldStorageConfig
class FieldStorageConfig extends ConfigEntityBase implements FieldStorageConfigInterface (View source)
Defines the Field storage configuration entity.
Traits
Provides a trait for calculating the dependencies of a plugin.
Provides a trait for accessing synchronization information.
Provides a trait for managing an object's dependencies.
Trait for \Drupal\Core\Cache\RefinableCacheableDependencyInterface.
Provides dependency injection friendly methods for serialization.
Trait for \Drupal\Core\Cache\CacheableDependencyInterface.
Constants
| NAME_MAX_LENGTH |
The maximum length of the field name, in characters. For fields created through Field UI, this includes the 'field_' prefix. |
Properties
| protected string[] | $cacheContexts | Cache contexts. |
from CacheableDependencyTrait |
| protected string[] | $cacheTags | Cache tags. |
from CacheableDependencyTrait |
| protected int | $cacheMaxAge | Cache max-age. |
from CacheableDependencyTrait |
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected string | $entityTypeId | The entity type. |
from EntityBase |
| protected bool | $enforceIsNew | Boolean indicating whether the entity should be forced to be new. |
from EntityBase |
| protected ComplexDataInterface | $typedData | A typed data object wrapping this entity. |
from EntityBase |
| protected array | $dependencies | The object's dependencies. |
from DependencyTrait |
| protected bool | $isSyncing | Whether this entity is being created, updated or deleted through a synchronization process. |
from SynchronizableEntityTrait |
| protected string | $originalId | The original ID of the configuration entity. |
from ConfigEntityBase |
| protected bool | $status | The enabled/disabled status of the configuration entity. |
from ConfigEntityBase |
| protected string | $uuid | The UUID for this entity. |
from ConfigEntityBase |
| protected string | $langcode | The language code of the entity's default language. |
from ConfigEntityBase |
| protected array | $third_party_settings | Third party entity settings. |
from ConfigEntityBase |
| protected array | $_core | Information maintained by Drupal core about configuration. |
from ConfigEntityBase |
| protected bool | $trustedData | Trust supplied data and not use configuration schema on save. |
from ConfigEntityBase |
| protected string | $id | The field ID. |
|
| protected string | $field_name | The field name. |
|
| protected string | $entity_type | The name of the entity type the field can be attached to. |
|
| protected string | $type | The field type. |
|
| protected string | $module | The name of the module that provides the field type. |
|
| protected array | $settings | Field-type specific settings. |
|
| protected int | $cardinality | The field cardinality. |
|
| protected bool | $translatable | Flag indicating whether the field is translatable. |
|
| protected bool | $locked | Flag indicating whether the field is available for editing. |
|
| protected bool | $persist_with_no_fields | Flag indicating whether the field storage should be deleted when orphaned. |
|
| bool | $custom_storage | A boolean indicating whether or not the field item uses custom storage. |
|
| protected array | $indexes | The custom storage indexes for the field data storage. |
|
| protected bool | $deleted | Flag indicating whether the field is deleted. |
|
| protected array | $schema | The field schema. |
|
| protected DataDefinitionInterface[] | $propertyDefinitions | An array of field property definitions. |
|
| static protected bool | $inDeletion | Static flag set to prevent recursion during field deletes. |
Methods
Sets cacheability; useful for value object constructors.
Implements the magic __sleep() method.
Constructs a FieldStorageConfig object.
Gets the entity type bundle info service.
Gets the identifier.
Gets the URL object for the entity.
Generates the HTML for a link to this entity.
Gets an array of placeholders for this entity.
Gets a list of URI relationships supported by this entity.
Checks data value access.
Acts on a saved entity before the insert or update hook is invoked.
Changes the values of an entity before it is created.
Acts on entities before they are deleted and before hooks are invoked.
Acts on deleted entities before the delete hook is invoked.
Gets a list of entities referenced by this entity.
The list cache tags to invalidate for this entity.
Returns the cache tags that should be used to invalidate caches.
Loads one or more entities.
Constructs a new entity object, without permanently saving it.
Invalidates an entity's cache tags upon save.
Invalidates an entity's cache tags upon delete.
Gets a typed data object for this entity object.
Gets the key that is used to store configuration dependencies.
Gets the configuration target identifier for the entity.
Calculates and returns dependencies of a specific plugin instance.
Calculates and adds dependencies of a specific plugin instance.
Returns whether this entity is being changed during the uninstall process.
Helper callback for uasort() to sort configuration entities by weight and label.
Calculates dependencies and stores them in the dependency property.
Informs the entity that entities it depends on will be deleted.
Sets the value of a third-party setting.
Gets the value of a third-party setting.
Gets all third-party settings of a given module.
Unsets a third-party setting.
Gets the list of third parties that store information.
Returns the field schema.
Returns the storage behavior for this field.
Determines whether the field is a base field.
Returns the field columns, as defined in the field schema.
Returns the list of bundles where the field storage has fields.
Returns the machine name of the field.
Returns whether the field is deleted or not.
Returns the name of the module providing the field type.
Returns the field type.
Returns the storage settings.
Returns the value of a given storage setting.
Sets the value for a field setting by name.
Sets field storage settings.
Returns whether the field supports translation.
Returns whether the field storage is revisionable.
Sets whether the field is translatable.
Returns the name of the provider of this field.
Returns the human-readable label for the field.
Returns the human-readable description for the field.
Returns the maximum number of items allowed for the field.
Sets the maximum number of items allowed for the field.
Gets an options provider for the given field item property.
Returns whether the field can contain multiple items.
Returns whether the field storage is locked or not.
Sets the locked flag.
Returns the ID of the entity type the field is attached to.
Determines whether a field has any data.
Returns an array of validation constraints.
Returns a validation constraint.
Gets the definition of a contained property.
Gets an array of property definitions of contained properties.
Returns the names of the field's subproperties.
Returns the name of the main property, if any.
Returns a unique identifier for the field storage.
Helper to retrieve the field item class.
Loads a field config entity based on the entity type and field name.
Checks if the field storage can be deleted.
Returns the custom storage indexes for the field data storage.
Sets the custom storage indexes for the field data storage.
Details
protected $this
setCacheability(CacheableDependencyInterface $cacheability)
Sets cacheability; useful for value object constructors.
getCacheTags()
{@inheritdoc}
getCacheContexts()
{@inheritdoc}
getCacheMaxAge()
{@inheritdoc}
addCacheableDependency($other_object)
{@inheritdoc}
addCacheContexts(array $cache_contexts)
{@inheritdoc}
addCacheTags(array $cache_tags)
{@inheritdoc}
mergeCacheMaxAge($max_age)
{@inheritdoc}
__sleep()
Implements the magic __sleep() method.
Using the Serialize interface and serialize() / unserialize() methods breaks entity forms in PHP 5.4.
__wakeup()
{@inheritdoc}
__construct(array $values, string $entity_type = 'field_storage_config')
Constructs a FieldStorageConfig object.
In most cases, Field entities are created via FieldStorageConfig::create($values)), where $values is the same parameter as in this constructor.
protected EntityTypeManagerInterface
entityTypeManager()
Gets the entity type manager.
protected EntityTypeBundleInfoInterface
entityTypeBundleInfo()
Gets the entity type bundle info service.
protected LanguageManagerInterface
languageManager()
Gets the language manager.
protected UuidInterface
uuidGenerator()
Gets the UUID generator.
string|int|null
id()
Gets the identifier.
string|null
uuid()
Gets the entity UUID (Universally Unique Identifier).
The UUID is guaranteed to be unique and can be used to identify an entity across multiple systems.
bool
isNew()
Overrides Entity::isNew().
EntityInterface::enforceIsNew() is only supported for newly created configuration entities but has no effect after saving, since each configuration entity is unique.
$this
enforceIsNew(bool $value = TRUE)
Enforces an entity to be new.
Allows migrations to create entities with pre-defined IDs by forcing the entity to be new before saving.
string
getEntityTypeId()
Gets the ID of the type of the entity.
string
bundle()
Gets the bundle of the entity.
string|TranslatableMarkup|null
label()
Gets the label of the entity.
Url
toUrl(string $rel = 'edit-form', array $options = [])
Gets the URL object for the entity.
The entity must have an id already. Content entities usually get their IDs by saving them.
URI templates might be set in the links array in an annotation, for example:
bool
hasLinkTemplate($rel)
Indicates if a link template exists for a given key.
protected array
linkTemplates()
Gets an array link templates.
Link
toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])
Generates the HTML for a link to this entity.
protected array
urlRouteParameters(string $rel)
Gets an array of placeholders for this entity.
Individual entity classes may override this method to add additional placeholders if desired. If so, they should be sure to replicate the property caching logic.
string[]
uriRelationships()
Gets a list of URI relationships supported by this entity.
bool|AccessResultInterface
access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)
Checks data value access.
LanguageInterface
language()
Gets the language of the entity.
int
save()
Saves an entity permanently.
When saving existing entities, the entity is assumed to be complete, partial updates of entities are not supported.
delete()
Deletes an entity permanently.
EntityInterface
createDuplicate()
Creates a duplicate of the entity.
EntityTypeInterface
getEntityType()
Gets the entity type definition.
preSave(EntityStorageInterface $storage)
Overrides \Drupal\Core\Entity\Entity::preSave().
postSave(EntityStorageInterface $storage, bool $update = TRUE)
Acts on a saved entity before the insert or update hook is invoked.
Used after the entity is saved, but before invoking the insert or update hook. Note that in case of translatable content entities this callback is only fired on their current translation. It is up to the developer to iterate over all translations if needed.
static
preCreate(EntityStorageInterface $storage, array $values)
Changes the values of an entity before it is created.
Load defaults for example.
postCreate(EntityStorageInterface $storage)
Acts on a created entity before hooks are invoked.
Used after the entity is created, but before saving the entity and before any of the presave hooks are invoked.
See the @link entity_crud Entity CRUD topic @endlink for more information.
static
preDelete(EntityStorageInterface $storage, array $field_storages)
Acts on entities before they are deleted and before hooks are invoked.
Used before the entities are deleted and before invoking the delete hook.
static
postDelete(EntityStorageInterface $storage, array $fields)
Acts on deleted entities before the delete hook is invoked.
Used after the entities are deleted but before invoking the delete hook.
static
postLoad(EntityStorageInterface $storage, array $entities)
Acts on loaded entities.
EntityInterface[]
referencedEntities()
Gets a list of entities referenced by this entity.
protected string[]
getListCacheTagsToInvalidate()
The list cache tags to invalidate for this entity.
string[]
getCacheTagsToInvalidate()
Returns the cache tags that should be used to invalidate caches.
This will not return additional cache tags added through addCacheTags().
static EntityInterface|null
load(mixed $id)
Loads an entity.
static EntityInterface[]
loadMultiple(array $ids = NULL)
Loads one or more entities.
static EntityInterface
create(array $values = [])
Constructs a new entity object, without permanently saving it.
protected
invalidateTagsOnSave(bool $update)
Invalidates an entity's cache tags upon save.
static protected
invalidateTagsOnDelete(EntityTypeInterface $entity_type, array $entities)
Invalidates an entity's cache tags upon delete.
int|string|null
getOriginalId()
Gets the original ID.
$this
setOriginalId(int|string|null $id)
Sets the original ID.
array
toArray()
Gets an array of all property values.
ComplexDataInterface
getTypedData()
Gets a typed data object for this entity object.
The returned typed data object wraps this entity and allows dealing with entities based on the generic typed data API.
string
getConfigDependencyKey()
Gets the key that is used to store configuration dependencies.
string
getConfigDependencyName()
Gets the configuration dependency name.
Configuration entities can depend on content and configuration entities. They store an array of content and config dependency names in their "dependencies" key.
string
getConfigTarget()
Gets the configuration target identifier for the entity.
Used to supply the correct format for storing a reference targeting this entity in configuration.
protected $this
addDependency(string $type, string $name)
Adds a dependency.
protected
addDependencies(array $dependencies)
Adds multiple dependencies.
protected array
getPluginDependencies(PluginInspectionInterface $instance)
Calculates and returns dependencies of a specific plugin instance.
Dependencies are added for the module that provides the plugin, as well as any dependencies declared by the instance's calculateDependencies() method, if it implements \Drupal\Component\Plugin\DependentPluginInterface.
protected
calculatePluginDependencies(PluginInspectionInterface $instance)
Calculates and adds dependencies of a specific plugin instance.
Dependencies are added for the module that provides the plugin, as well as any dependencies declared by the instance's calculateDependencies() method, if it implements \Drupal\Component\Plugin\DependentPluginInterface.
protected ModuleHandlerInterface
moduleHandler()
Wraps the module handler.
protected ThemeHandlerInterface
themeHandler()
Wraps the theme handler.
setSyncing($syncing)
{@inheritdoc}
isSyncing()
{@inheritdoc}
mixed
get(string $property_name)
Returns the value of a property.
$this
set(string $property_name, mixed $value)
Sets the value of a property.
$this
enable()
Enables the configuration entity.
$this
disable()
Disables the configuration entity.
$this
setStatus(bool $status)
Sets the status of the configuration entity.
bool
status()
Returns whether the configuration entity is enabled.
Status implementations for configuration entities should follow these general rules:
- Status does not affect the loading of entities. I.e. Disabling configuration entities should only have UI/access implications.
- It should only take effect when a 'status' key is explicitly declared in the entity_keys info of a configuration entity's annotation data.
- Each entity implementation (entity/controller) is responsible for checking and managing the status.
setUninstalling($uninstalling)
{@inheritdoc}
bool
isUninstalling()
Returns whether this entity is being changed during the uninstall process.
If you are writing code that responds to a change in this entity (insert, update, delete, presave, etc.), and your code would result in a configuration change (whether related to this configuration entity, another configuration entity, or non-entity configuration) or your code would result in a change to this entity itself, you need to check and see if this entity change is part of an uninstall process, and skip executing your code if that is the case.
For example, \Drupal\language\Entity\ConfigurableLanguage::preDelete() prevents the API from deleting the default language. However during an uninstall of the language module it is expected that the default language should be deleted.
static
sort(ConfigEntityInterface $a, ConfigEntityInterface $b)
Helper callback for uasort() to sort configuration entities by weight and label.
protected TypedConfigManagerInterface
getTypedConfig()
Gets the typed config manager.
$this
calculateDependencies()
Calculates dependencies and stores them in the dependency property.
array
getDependencies()
Gets the configuration dependencies.
bool
onDependencyRemoval(array $dependencies)
Informs the entity that entities it depends on will be deleted.
This method allows configuration entities to remove dependencies instead of being deleted themselves. Configuration entities can use this method to avoid being unnecessarily deleted during an extension uninstallation. For example, entity displays remove references to widgets and formatters if the plugin that supplies them depends on a module that is being uninstalled.
If this method returns TRUE then the entity needs to be re-saved by the caller for the changes to take effect. Implementations should not save the entity.
$this
setThirdPartySetting(string $module, string $key, mixed $value)
Sets the value of a third-party setting.
mixed
getThirdPartySetting(string $module, string $key, mixed $default = NULL)
Gets the value of a third-party setting.
array
getThirdPartySettings(string $module)
Gets all third-party settings of a given module.
mixed
unsetThirdPartySetting(string $module, string $key)
Unsets a third-party setting.
array
getThirdPartyProviders()
Gets the list of third parties that store information.
static protected ConfigManager
getConfigManager()
Gets the configuration manager.
bool
isInstallable()
Checks whether this entity is installable.
For example, a default view might not be installable if the base table doesn't exist.
$this
trustData()
Sets that the data should be trusted.
If the data is trusted then dependencies will not be calculated on save and schema will not be used to cast the values. Generally this is only used during module and theme installation. Once the config entity has been saved the data will no longer be marked as trusted. This is an optimization for creation of configuration during installation.
bool
hasTrustedData()
Gets whether on not the data is trusted.
protected
preSaveNew(EntityStorageInterface $storage)
Prepares saving a new field definition.
protected
preSaveUpdated(EntityStorageInterface $storage)
Prepares saving an updated field definition.
array[]
getSchema()
Returns the field schema.
Note that this method returns an empty array for computed fields which have no schema.
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.
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.
array[]
getColumns()
Returns the field columns, as defined in the field schema.
array
getBundles()
Returns the list of bundles where the field storage has fields.
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.
bool
isDeleted()
Returns whether the field is deleted or not.
string
getTypeProvider()
Returns the name of the module providing the field type.
string
getType()
Returns the field type.
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.
mixed
getSetting(string $setting_name)
Returns the value of a given storage setting.
$this
setSetting(string $setting_name, mixed $value)
Sets the value for a field setting by name.
$this
setSettings(array $settings)
Sets field storage settings.
Note that the method does not unset existing settings not specified in the incoming $settings array.
For example:
bool
isTranslatable()
Returns whether the field supports translation.
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.
$this
setTranslatable(bool $translatable)
Sets whether the field is translatable.
string
getProvider()
Returns the name of the provider of this field.
string
getLabel()
Returns the human-readable label for the field.
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.
int
getCardinality()
Returns the maximum number of items allowed for the field.
Possible values are positive integers or FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
$this
setCardinality(int $cardinality)
Sets the maximum number of items allowed for the field.
OptionsProviderInterface|null
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.
bool
isLocked()
Returns whether the field storage is locked or not.
$this
setLocked(bool $locked)
Sets the locked flag.
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?".
bool
hasData()
Determines whether a field has any data.
array[]
getConstraints()
Returns an array of validation constraints.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
array
getConstraint(string $constraint_name)
Returns a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
DataDefinitionInterface|null
getPropertyDefinition(string $name)
Gets the definition of a contained property.
DataDefinitionInterface[]
getPropertyDefinitions()
Gets an array of property definitions of contained properties.
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.
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.
string
getUniqueStorageIdentifier()
Returns a unique identifier for the field storage.
protected
getFieldItemClass()
Helper to retrieve the field item class.
static FieldStorageConfigInterface|null
loadByName(string $entity_type_id, string $field_name)
Loads a field config entity based on the entity type and field name.
bool
isDeletable()
Checks if the field storage can be deleted.
array
getIndexes()
Returns the custom storage indexes for the field data storage.
$this
setIndexes(array $indexes)
Sets the custom storage indexes for the field data storage.
.