FieldConfigInterface
interface FieldConfigInterface implements ConfigEntityInterface, FieldDefinitionInterface (View source)
Provides an interface defining a field entity.
Methods
Checks data value access.
The cache contexts associated with this object.
The cache tags associated with this object.
The maximum age for which this object may be cached.
Adds cache contexts.
Merges the maximum age (in seconds) with the existing maximum age.
Adds a dependency on an object: merges its cacheability metadata.
Gets the URL object for the entity.
Gets the URL object for the entity.
Deprecated way of generating a link to the entity. See toLink().
Generates the HTML for a link to this entity.
Indicates if a link template exists for a given key.
Gets a list of URI relationships supported by this entity.
Loads one or more entities.
Constructs a new entity object, without permanently saving it.
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.
Returns the cache tags that should be used to invalidate caches.
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.
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.
Sets the status of the synchronization flag.
Returns whether this entity is being changed as part of a synchronization.
Sets the status of the configuration entity.
Returns whether this entity is being changed during the uninstall process.
Sets the value of a property.
Calculates dependencies and stores them in the dependency property.
Informs the entity that entities it depends on will be deleted.
Creates a new data definition object.
Returns whether the data is multi-valued, i.e. a list of data items.
Returns the class used for creating the typed data object.
Returns the array of settings, as required by the used class.
Returns the value of a given setting.
Returns a validation constraint.
Adds a validation constraint.
Creates a new list data definition for items of the given data type.
Gets the data definition of an item of the list.
Returns the ID of the entity type the field is attached to.
Gets the bundle the field is attached to.
Returns whether the display for the field can be configured.
Returns the default display options for the field.
Returns the default value literal for the field.
Returns the default value callback for the field.
Returns the default value for the field in a newly created entity.
Returns the field storage definition.
Gets an object that can be saved in configuration.
Returns a unique identifier for the field.
Gets the deleted flag of the field.
Details
bool|AccessResultInterface
access(string $operation, AccountInterface $account = NULL, bool $return_as_object = FALSE)
Checks data value access.
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.
string[]
getCacheTags()
The cache tags associated with this object.
When this object is modified, these cache tags will be invalidated.
int
getCacheMaxAge()
The maximum age for which this object may be cached.
$this
addCacheContexts(array $cache_contexts)
Adds cache contexts.
$this
addCacheTags(array $cache_tags)
Adds cache tags.
$this
mergeCacheMaxAge(int $max_age)
Merges the maximum age (in seconds) with the existing maximum age.
The max age will be set to the given value if it is lower than the existing value.
$this
addCacheableDependency(CacheableDependencyInterface|object $other_object)
Adds a dependency on an object: merges its cacheability metadata.
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.
string|int|null
id()
Gets the identifier.
LanguageInterface
language()
Gets the language of the entity.
bool
isNew()
Determines whether the entity is new.
Usually an entity is new if no ID exists for it yet. However, entities may be enforced to be new with existing IDs too.
$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|null
label()
Gets the label of the entity.
Url
urlInfo(string $rel = 'canonical', array $options = [])
deprecated
deprecated
Gets the URL object for the entity.
Url
toUrl(string $rel = 'canonical', 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:
string
url(string $rel = 'canonical', array $options = [])
deprecated
deprecated
Gets the public URL for this entity.
string
link(string|null $text = NULL, string $rel = 'canonical', array $options = [])
deprecated
deprecated
Deprecated way of generating a link to the entity. See toLink().
Link
toLink(string|null $text = NULL, string $rel = 'canonical', array $options = [])
Generates the HTML for a link to this entity.
bool
hasLinkTemplate(string $key)
Indicates if a link template exists for a given key.
string[]
uriRelationships()
Gets a list of URI relationships supported by this entity.
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.
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.
preSave(EntityStorageInterface $storage)
Acts on an entity before the presave hook is invoked.
Used before the entity is saved and before invoking the presave 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. This is different from its counterpart in the Field API, FieldItemListInterface::preSave(), which is fired on all field translations automatically.
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 $entities)
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 $entities)
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
createDuplicate()
Creates a duplicate of the entity.
EntityTypeInterface
getEntityType()
Gets the entity type definition.
EntityInterface[]
referencedEntities()
Gets a list of entities referenced by this entity.
int|string|null
getOriginalId()
Gets the original ID.
string[]
getCacheTagsToInvalidate()
Returns the cache tags that should be used to invalidate caches.
This will not return additional cache tags added through addCacheTags().
$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.
$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.
$this
setSyncing(bool $status)
Sets the status of the synchronization flag.
bool
isSyncing()
Returns whether this entity is being changed as part of a synchronization.
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 change to this entity itself, a configuration change (whether related to this entity, another entity, or non-entity configuration), you need to check and see if this entity change is part of a synchronization process, and skip executing your code if that is the case.
For example, \Drupal\node\Entity\NodeType::postSave() adds the default body field to newly created node type configuration entities, which is a configuration change. You would not want this code to run during an import, because imported entities were already given the body field when they were originally created, and the imported configuration includes all of their currently-configured fields. On the other hand, \Drupal\field\Entity\FieldStorageConfig::preSave() and the methods it calls make sure that the storage tables are created or updated for the field storage configuration entity, which is not a configuration change, and it must be done whether due to an import or not. So, the first method should check $entity->isSyncing() and skip executing if it returns TRUE, and the second should not perform this check.
$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.
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.
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
calculateDependencies()
Calculates dependencies and stores them in the dependency property.
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.
array
getDependencies()
Gets the configuration dependencies.
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.
static DataDefinitionInterface
createFromDataType(string $data_type)
Creates a new data definition object.
This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createDataDefinition() to build a definition object for an arbitrary data type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:
string
getDataType()
Returns the data type of the data.
string|TranslatableMarkup
getLabel()
Returns a human readable label.
string|null
getDescription()
Returns a human readable description.
Descriptions are usually used on user interfaces where the data is edited or displayed.
bool
isList()
Returns whether the data is multi-valued, i.e. a list of data items.
This is equivalent to checking whether the data definition implements the \Drupal\Core\TypedData\ListDefinitionInterface interface.
bool
isReadOnly()
Determines whether the data is read-only.
bool
isComputed()
Determines whether the data value is computed.
For example, data could be computed depending on some other values.
bool
isRequired()
Determines whether a data value is required.
For required data a non-NULL value is mandatory.
string
getClass()
Returns the class used for creating the typed data object.
If not specified, the default class of the data type will be returned.
array
getSettings()
Returns the array of settings, as required by the used class.
See the documentation of the class for supported or required settings.
mixed
getSetting(string $setting_name)
Returns the value of a given setting.
array[]
getConstraints()
Returns an array of validation constraints.
The validation constraints of a definition consist of any for it defined constraints and default constraints, which are generated based on the definition and its data type. See \Drupal\Core\TypedData\TypedDataManager::getDefaultConstraints().
Constraints are defined via an array, having constraint plugin IDs as key and constraint options as values, e.g.
array
getConstraint(string $constraint_name)
Returns a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
DataDefinitionInterface
addConstraint(string $constraint_name, array|null $options = NULL)
Adds a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details.
bool
isInternal()
Determines whether the data value is internal.
This can be used in a scenario when it is not desirable to expose this data value to an external system.
static ListDataDefinitionInterface
createFromItemType(string $item_type)
Creates a new list data definition for items of the given data type.
This method is typically used by \Drupal\Core\TypedData\TypedDataManager::createListDataDefinition() to build a definition object for an arbitrary item type. When the definition class is known, it is recommended to directly use the static create() method on that class instead; e.g.:
DataDefinitionInterface
getItemDefinition()
Gets the data definition of an item of the list.
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.
string
getType()
Returns the field type.
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):
- FieldDefinitionInterface::getTargetEntityTypeId() answers "as a field, which entity type are you attached to?".
- EntityInterface::getEntityTypeId() answers "as a (config) entity, what is your own entity type?".
string|null
getTargetBundle()
Gets the bundle the field is attached to.
This method should not be confused with EntityInterface::bundle() (configurable fields are config entities, and thus implement both interfaces):
- FieldDefinitionInterface::getTargetBundle() answers "as a field, which bundle are you attached to?".
- EntityInterface::bundle() answers "as a (config) entity, what is your own bundle?" (not relevant in our case, the config entity types used to store the definitions of configurable fields do not have bundles).
bool
isDisplayConfigurable(string $display_context)
Returns whether the display for the field can be configured.
array|null
getDisplayOptions(string $display_context)
Returns the default display options for the field.
If the field's display is configurable, the returned display options act as default values and may be overridden via the respective entity display. Otherwise, the display options will be applied to entity displays as is.
array
getDefaultValueLiteral()
Returns the default value literal for the field.
This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.
string|null
getDefaultValueCallback()
Returns the default value callback for the field.
This method retrieves the raw property assigned to the field definition. When computing the runtime default value for a field in a given entity, ::getDefaultValue() should be used instead.
array
getDefaultValue(FieldableEntityInterface $entity)
Returns the default value for the field in a newly created entity.
This method computes the runtime default value for a field in a given entity. To access the raw properties assigned to the field definition, ::getDefaultValueLiteral() or ::getDefaultValueCallback() should be used instead.
bool
isTranslatable()
Returns whether the field is translatable.
FieldStorageDefinitionInterface
getFieldStorageDefinition()
Returns the field storage definition.
FieldConfigInterface
getConfig(string $bundle)
Gets an object that can be saved in configuration.
Base fields are defined in code. In order to configure field definition properties per bundle use this method to create an override that can be saved in configuration.
string
getUniqueIdentifier()
Returns a unique identifier for the field.
bool
isDeleted()
Gets the deleted flag of the field.