BaseFieldOverride
class BaseFieldOverride extends FieldConfigBase (View source)
Defines the base field override entity.
Allows base fields to be overridden on the bundle level.
Traits
A trait used to assist in the normalization of raw input field values.
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.
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. |
from FieldConfigBase |
| protected string | $field_name | The field name. |
from FieldConfigBase |
| protected string | $field_type | The field type. |
from FieldConfigBase |
| protected string | $entity_type | The name of the entity type the field is attached to. |
from FieldConfigBase |
| protected string | $bundle | The name of the bundle the field is attached to. |
from FieldConfigBase |
| protected string | $label | The human-readable label for the field. |
from FieldConfigBase |
| protected string | $description | The field description. |
from FieldConfigBase |
| protected array | $settings | Field-type specific settings. |
from FieldConfigBase |
| protected bool | $required | Flag indicating whether the field is required. |
from FieldConfigBase |
| protected bool | $translatable | Flag indicating whether the field is translatable. |
from FieldConfigBase |
| protected array | $default_value | Default field value. |
from FieldConfigBase |
| protected string | $default_value_callback | The name of a callback function that returns default values. |
from FieldConfigBase |
| protected FieldStorageDefinitionInterface | $fieldStorage | The field storage object. |
from FieldConfigBase |
| protected FieldItemDataDefinition | $itemDefinition | The data definition of a field item. |
from FieldConfigBase |
| protected array | $constraints | Array of constraint options keyed by constraint plugin ID. |
from FieldConfigBase |
| protected array[] | $propertyConstraints | Array of property constraint options keyed by property ID. The values are associative array of constraint options keyed by constraint plugin ID. |
from FieldConfigBase |
| protected BaseFieldDefinition | $baseFieldDefinition | The base field definition. |
Methods
Sets cacheability; useful for value object constructors.
Implements the magic __sleep() method.
Constructs a BaseFieldOverride object.
Gets the entity type bundle info service.
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.
Ensure a field value is transformed into a format keyed by delta.
Returns the ID of the entity type the field is attached to.
Sets whether the field is translatable.
Returns the array of settings, as required by the used class.
Sets the value for a field setting by name.
Returns the default value for the field in a newly created entity.
Returns the default value literal for the field.
Returns the default value callback for the field.
Sets a custom default value callback.
Creates a new list data definition for items of the given data type.
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.
Gets the data definition of an item of the list.
Gets an object that can be saved in configuration.
Sets the array of validation constraints for the FieldItemList.
Adds a validation constraint to the FieldItemList.
Sets constraints for a given field item property.
Adds constraints for a given field item property.
Creates a base field override object.
Returns the field storage definition.
Returns whether the display for the field can be configured.
Returns the default display options for the field.
Determines whether the data is read-only.
Determines whether the data value is computed.
Returns a unique identifier for the field.
Gets the base field definition.
Loads a base field bundle override config entity.
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.
__wakeup()
{@inheritdoc}
__construct(array $values, string $entity_type = 'base_field_override')
Constructs a BaseFieldOverride object.
In most cases, base field override entities are created via BaseFieldOverride::createFromBaseFieldDefinition($definition, 'bundle')
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)
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 $field_overrides)
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.
static protected array
normalizeValue(mixed $value, string $main_property_name)
Ensure a field value is transformed into a format keyed by delta.
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).
string|TranslatableMarkup
getLabel()
Returns a human readable label.
$this
setLabel(string $label)
Sets the field definition label.
string|null
getDescription()
Returns a human readable description.
Descriptions are usually used on user interfaces where the data is edited or displayed.
$this
setDescription(string $description)
Sets a human readable description.
Descriptions are usually used on user interfaces where the data is edited or displayed.
bool
isTranslatable()
Returns whether the field is translatable.
$this
setTranslatable(bool $translatable)
Sets whether the field is translatable.
array
getSettings()
Returns the array of settings, as required by the used class.
See the documentation of the class for supported or required settings.
$this
setSettings(array $settings)
Sets field settings.
Note that the method does not unset existing settings not specified in the incoming $settings array.
For example:
mixed
getSetting(string $setting_name)
Returns the value of a given setting.
$this
setSetting(string $setting_name, mixed $value)
Sets the value for a field setting by name.
bool
isRequired()
Determines whether a data value is required.
For required data a non-NULL value is mandatory.
$this
setRequired(bool $required)
Sets whether the field can be empty.
If a field is required, an entity needs to have at least a valid, non-empty item in that field's FieldItemList in order to pass validation.
An item is considered empty if its isEmpty() method returns TRUE. Typically, that is if at least one of its required properties is empty.
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.
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.
$this
setDefaultValue(mixed $value)
Sets a default value.
Note that if a default value callback is set, it will take precedence over any value set here.
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.
$this
setDefaultValueCallback(string|null $callback)
Sets a custom default value callback.
If set, the callback overrides any set default value.
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.:
static DataDefinitionInterface
createFromDataType($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.
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.
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[]
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
getItemDefinition()
Gets the data definition of an item of the list.
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.
$this
setConstraints(array $constraints)
Sets the array of validation constraints for the FieldItemList.
NOTE: This will overwrite any previously set constraints. In most cases FieldConfigInterface::addConstraint() should be used instead.
Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().
DataDefinitionInterface
addConstraint(string $constraint_name, array|null $options = NULL)
Adds a validation constraint to the FieldItemList.
Note: If you wish to apply a constraint to just a property of a FieldItem use \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints() instead.
FieldConfigInterface
setPropertyConstraints(string $name, array $constraints)
Sets constraints for a given field item property.
Note: this overwrites any existing property constraints. If you need to add to the existing constraints, use \Drupal\Core\Field\FieldConfigInterface::addPropertyConstraints()
Note that constraints added via this method are not stored in configuration and as such need to be added at runtime using hook_entity_bundle_field_info_alter().
FieldConfigInterface
addPropertyConstraints(string $name, array $constraints)
Adds constraints for a given field item property.
Adds a constraint to a property of a field item. e.g.
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.
The implications of this method are left to the discretion of the caller. For example, a module providing an HTTP API may not expose entities of this type, or a custom entity reference field settings form may deprioritize entities of this type in a select list.
static BaseFieldOverride
createFromBaseFieldDefinition(BaseFieldDefinition $base_field_definition, string $bundle)
Creates a base field override object.
FieldStorageDefinitionInterface
getFieldStorageDefinition()
Returns the field storage definition.
bool
isDisplayConfigurable($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.
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.
string
getUniqueIdentifier()
Returns a unique identifier for the field.
protected BaseFieldDefinition
getBaseFieldDefinition()
Gets the base field definition.
static FieldConfigInterface|null
loadByName(string $entity_type_id, string $bundle, string $field_name)
Loads a base field bundle override config entity.