EntityTypeInterface
interface EntityTypeInterface implements PluginDefinitionInterface (View source)
Provides an interface for an entity type and its metadata.
Entity type classes can provide docblock annotations. The entity type manager will use these annotations to populate the entity type object with properties.
Additional properties can be defined by module implementations of hook_entity_type_build(). Existing data can be altered in implementations of hook_entity_type_alter(), which can also be used to fill in defaults. Module-specific properties should be documented in the hook implementations defining them.
Constants
| ID_MAX_LENGTH |
The maximum length of ID, in characters. |
| BUNDLE_MAX_LENGTH |
The maximum length of bundle name, in characters. |
Methods
Gets any arbitrary property.
Sets a value to an arbitrary property.
Gets the name of the original entity type class.
Gets an array of entity keys.
Gets a specific entity key.
Indicates if a given entity key exists.
Indicates whether entities should be statically cached.
Indicates whether the rendered output of entities should be cached.
Indicates if the persistent cache of field data should be used.
Determines if there is a handler for a given type.
No description
Gets an array of handlers.
Gets the storage class.
Sets the storage class.
Gets the form class for a specific operation.
Sets a form class for a specific operation.
Indicates if this entity type has any forms.
Indicates if this entity type has any route provider.
Gets all the route provide handlers.
Gets the list class.
Sets the list class.
Indicates if this entity type has a list class.
Gets the view builder class.
Gets the view builder class.
Indicates if this entity type has a view builder.
Gets the access control class.
Sets the access control handler class.
Indicates if the entity type class implements the given interface.
Indicates if the entity type is a subclass of the given class or interface.
Sets the handlers for a given type.
Gets the name of the default administrative permission.
Gets the permission granularity level.
Gets the link templates using the URI template syntax.
Gets the link template for a given key.
Indicates if a link template exists for a given key.
Sets a single link template.
Gets the name of the entity type which provides bundles.
Gets the entity type for which this entity provides bundles.
Gets the label for the bundle.
Gets the name of the entity's base table.
Indicates whether the entity data is internal.
Indicates whether entities of this type have multilingual support.
Indicates whether the revision form fields should be added to the form.
Indicates whether entities of this type have revision support.
Gets the name of the entity's revision data table.
Gets the name of the entity's revision table.
Gets the name of the entity's data table.
Gets the human-readable name of the entity type.
Gets the uppercase plural form of the name of the entity type.
Gets the indefinite singular form of the name of the entity type.
Gets the indefinite plural form of the name of the entity type.
Gets the label's definite article form for use with a count of entities.
Gets a callable that can be used to provide the entity URI.
Sets a callable to use to provide the entity URI.
Gets the machine name of the entity type group.
Gets the human-readable name of the entity type group.
The list cache contexts associated with this entity type.
The list cache tags associated with this entity type.
Gets the key that is used to store configuration dependencies.
Indicates whether this entity type is commonly used as a reference target.
Gets an array of validation constraints.
Sets the array of validation constraints for the FieldItemList.
Adds a validation constraint.
Gets the config dependency info for this entity, if any exists.
Details
string
id()
Gets the unique identifier of the plugin.
PluginDefinitionInterface
setClass(string $class)
Sets the class.
string
getClass()
Gets the class.
string
getProvider()
Gets the plugin provider.
The provider is the name of the module that provides the plugin, or "core', or "component".
mixed
get(string $property)
Gets any arbitrary property.
$this
set(string $property, mixed $value)
Sets a value to an arbitrary property.
string
getOriginalClass()
Gets the name of the original entity type class.
In case the class name was changed with setClass(), this will return the initial value. Useful when trying to identify the entity type ID based on the class.
array
getKeys()
Gets an array of entity keys.
string|bool
getKey(string $key)
Gets a specific entity key.
bool
hasKey(string $key)
Indicates if a given entity key exists.
bool
isStaticallyCacheable()
Indicates whether entities should be statically cached.
bool
isRenderCacheable()
Indicates whether the rendered output of entities should be cached.
bool
isPersistentlyCacheable()
Indicates if the persistent cache of field data should be used.
bool
hasHandlerClass(string $handler_type, string|false $nested = FALSE)
Determines if there is a handler for a given type.
array|string|null
getHandlerClass(string $handler_type, string|false $nested = FALSE)
No description
array
getHandlerClasses()
Gets an array of handlers.
string
getStorageClass()
Gets the storage class.
$this
setStorageClass(string $class)
Sets the storage class.
string|null
getFormClass(string $operation)
Gets the form class for a specific operation.
$this
setFormClass(string $operation, string $class)
Sets a form class for a specific operation.
bool
hasFormClasses()
Indicates if this entity type has any forms.
bool
hasRouteProviders()
Indicates if this entity type has any route provider.
string[]
getRouteProviderClasses()
Gets all the route provide handlers.
Much like forms you can define multiple route provider handlers.
string
getListBuilderClass()
Gets the list class.
$this
setListBuilderClass(string $class)
Sets the list class.
bool
hasListBuilderClass()
Indicates if this entity type has a list class.
string
getViewBuilderClass()
Gets the view builder class.
$this
setViewBuilderClass(string $class)
Gets the view builder class.
bool
hasViewBuilderClass()
Indicates if this entity type has a view builder.
string
getAccessControlClass()
Gets the access control class.
$this
setAccessClass(string $class)
Sets the access control handler class.
bool
entityClassImplements(string $interface)
Indicates if the entity type class implements the given interface.
bool
isSubclassOf(string $class)
deprecated
deprecated
Indicates if the entity type is a subclass of the given class or interface.
$this
setHandlerClass(string $handler_type, array|string $value)
Sets the handlers for a given type.
string|bool
getAdminPermission()
Gets the name of the default administrative permission.
The default \Drupal\Core\Entity\EntityAccessControlHandler class checks this permission for all operations in its checkAccess() method. Entities with more complex permissions can extend this class to do their own access checks.
string
getPermissionGranularity()
Gets the permission granularity level.
The allowed values are respectively "entity_type" or "bundle".
array
getLinkTemplates()
Gets the link templates using the URI template syntax.
Links are an array of standard link relations to the URI template that should be used for them. Where possible, link relationships should use established IANA relationships rather than custom relationships.
Every entity type should, at minimum, define "canonical", which is the pattern for URIs to that entity. Even if the entity will have no HTML page exposed to users it should still have a canonical URI in order to be compatible with web services. Entities that will be user-editable via an HTML page must also define an "edit-form" relationship.
By default, the following placeholders are supported:
- [entityType]: The entity type itself will also be a valid token for the ID of the entity. For instance, a placeholder of {node} used on the Node class.
- [bundleEntityType]: The bundle machine name itself. For instance, a placeholder of {node_type} used on the Node class.
Specific entity types may also expand upon this list by overriding the Entity::urlRouteParameters() method.
string|bool
getLinkTemplate(string $key)
Gets the link template for a given key.
bool
hasLinkTemplate(string $key)
Indicates if a link template exists for a given key.
$this
setLinkTemplate(string $key, string $path)
Sets a single link template.
string|null
getBundleEntityType()
Gets the name of the entity type which provides bundles.
string|null
getBundleOf()
Gets the entity type for which this entity provides bundles.
It can be used by other modules to act accordingly; for example, the Field UI module uses it to add operation links to manage fields and displays.
string
getBundleLabel()
Gets the label for the bundle.
string|null
getBaseTable()
Gets the name of the entity's base table.
bool
isInternal()
Indicates whether the entity data is internal.
This can be used in a scenario when it is not desirable to expose data of this entity type 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.
bool
isTranslatable()
Indicates whether entities of this type have multilingual support.
At an entity level, this indicates language support and at a bundle level this indicates translation support.
bool
showRevisionUi()
Indicates whether the revision form fields should be added to the form.
bool
isRevisionable()
Indicates whether entities of this type have revision support.
string|null
getRevisionDataTable()
Gets the name of the entity's revision data table.
string|null
getRevisionTable()
Gets the name of the entity's revision table.
string|null
getDataTable()
Gets the name of the entity's data table.
string|TranslatableMarkup
getLabel()
Gets the human-readable name of the entity type.
This label should be used to present a human-readable name of the entity type.
string|TranslatableMarkup
getCollectionLabel()
Gets the uppercase plural form of the name of the entity type.
This should return a human-readable version of the name that can refer to all the entities of the given type, collectively. An example usage of this is the page title of a page devoted to a collection of entities such as "Workflows" (instead of "Workflow entities").
string|TranslatableMarkup
getSingularLabel()
Gets the indefinite singular form of the name of the entity type.
This should return the human-readable name for a single instance of the entity type. For example: "opportunity" (with the plural as "opportunities"), "child" (with the plural as "children"), or "content item" (with the plural as "content items").
Think of it as an "in a full sentence, this is what we call this" label. As a consequence, the English version is lowercase.
string|TranslatableMarkup
getPluralLabel()
Gets the indefinite plural form of the name of the entity type.
This should return the human-readable name for more than one instance of the entity type. For example: "opportunities" (with the singular as "opportunity"), "children" (with the singular as "child"), or "content items" (with the singular as "content item").
string|TranslatableMarkup
getCountLabel(int $count)
Gets the label's definite article form for use with a count of entities.
This label should be used when the quantity of entities is provided. The name should be returned in a form usable with a count of the entities. For example: "1 opportunity", "5 opportunities", "1 child", "6 children", "1 content item", "25 content items".
callable|null
getUriCallback()
Gets a callable that can be used to provide the entity URI.
This is only called if there is no matching link template for the link relationship type, and there is no bundle-specific callback provided.
$this
setUriCallback(callable $callback)
Sets a callable to use to provide the entity URI.
string
getGroup()
Gets the machine name of the entity type group.
string|TranslatableMarkup
getGroupLabel()
Gets the human-readable name of the entity type group.
string[]
getListCacheContexts()
The list cache contexts associated with this entity type.
Enables code listing entities of this type to ensure that rendered listings are varied as necessary, typically to ensure users of role A see other entities listed than users of role B.
string[]
getListCacheTags()
The list cache tags associated with this entity type.
Enables code listing entities of this type to ensure that newly created entities show up immediately.
string
getConfigDependencyKey()
Gets the key that is used to store configuration dependencies.
bool
isCommonReferenceTarget()
Indicates whether this entity type is commonly used as a reference target.
array[]
getConstraints()
Gets an array of validation constraints.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details on how constraints are defined.
$this
setConstraints(array $constraints)
Sets the array of validation constraints for the FieldItemList.
NOTE: This will overwrite any previously set constraints. In most cases ContentEntityTypeInterface::addConstraint() should be used instead. See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details on how constraints are defined.
$this
addConstraint(string $constraint_name, array|null $options = NULL)
Adds a validation constraint.
See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details on how constraints are defined.
array
getBundleConfigDependency(string $bundle)
Gets the config dependency info for this entity, if any exists.