interface ContentEntityTypeInterface implements EntityTypeInterface (View source)

Provides an interface for a content entity type and its metadata.

Methods

string
id()

Gets the unique identifier of the plugin.

setClass(string $class)

Sets the class.

string
getClass()

Gets the class.

string
getProvider()

Gets the plugin provider.

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.

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.

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

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.

string
getPermissionGranularity()

Gets the permission granularity level.

array
getLinkTemplates()

Gets the link templates using the URI template syntax.

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.

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.

bool
isTranslatable()

Indicates whether entities of this type have multilingual 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.

getLabel()

Gets the human-readable name of the entity type.

getCollectionLabel()

Gets the uppercase plural form of the name of the entity type.

getSingularLabel()

Gets the indefinite singular form of the name of the entity type.

getPluralLabel()

Gets the indefinite plural form of the name of the entity type.

getCountLabel(int $count)

Gets the label's definite article form for use with a count of entities.

callable|null
getUriCallback()

Gets a callable that can be used to provide the entity URI.

$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.

getGroupLabel()

Gets the human-readable name of the entity type group.

string[]
getListCacheContexts()

The list cache contexts associated with this entity type.

string[]
getListCacheTags()

The list cache tags associated with this entity type.

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.

$this
setConstraints(array $constraints)

Sets the array of validation constraints for the FieldItemList.

$this
addConstraint(string $constraint_name, array|null $options = NULL)

Adds a validation constraint.

array
getBundleConfigDependency(string $bundle)

Gets the config dependency info for this entity, if any exists.

array
getRevisionMetadataKeys()

Gets an array of entity revision metadata keys.

string|bool
getRevisionMetadataKey(string $key)

Gets a specific entity revision metadata key.

bool
hasRevisionMetadataKey(string $key)

Indicates if a given entity revision metadata key exists.

$this
setRevisionMetadataKey(string $key, string|null $field_name)

Sets a revision metadata key.

Details

string id()

Gets the unique identifier of the plugin.

Return Value

string

The unique identifier of the plugin.

PluginDefinitionInterface setClass(string $class)

Sets the class.

Parameters

string $class

A fully qualified class name.

Return Value

PluginDefinitionInterface

Exceptions

InvalidArgumentException

string getClass()

Gets the class.

Return Value

string

A fully qualified class name.

string getProvider()

Gets the plugin provider.

The provider is the name of the module that provides the plugin, or "core', or "component".

Return Value

string

The provider.

mixed get(string $property)

Gets any arbitrary property.

Parameters

string $property

The property to retrieve.

Return Value

mixed

The value for that property, or NULL if the property does not exist.

$this set(string $property, mixed $value)

Sets a value to an arbitrary property.

Parameters

string $property

The property to use for the value.

mixed $value

The value to set.

Return Value

$this

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.

Return Value

string

The name of the original entity type class.

array getKeys()

Gets an array of entity keys.

Return Value

array

An array describing how the Field API can extract certain information from objects of this entity type:

  • id: The name of the property that contains the primary ID of the entity. Every entity object passed to the Field API must have this property and its value must be numeric.
  • revision: (optional) The name of the property that contains the revision ID of the entity. The Field API assumes that all revision IDs are unique across all entities of a type. If this entry is omitted the entities of this type are not revisionable.
  • bundle: (optional) The name of the property that contains the bundle name for the entity. The bundle name defines which set of fields are attached to the entity (e.g. what nodes call "content type"). This entry can be omitted if this entity type exposes a single bundle (such that all entities have the same collection of fields). The name of this single bundle will be the same as the entity type.
  • label: (optional) The name of the property that contains the entity label. For example, if the entity's label is located in $entity->subject, then 'subject' should be specified here. If complex logic is required to build the label, \Drupal\Core\Entity\EntityInterface::label() should be used.
  • langcode: (optional) The name of the property that contains the language code. For instance, if the entity's language is located in $entity->langcode, then 'langcode' should be specified here.
  • uuid: (optional) The name of the property that contains the universally unique identifier of the entity, which is used to distinctly identify an entity across different systems.

string|bool getKey(string $key)

Gets a specific entity key.

Parameters

string $key

The name of the entity key to return.

Return Value

string|bool

The entity key, or FALSE if it does not exist.

See also

\Drupal\Core\Entity\self::getKeys()

bool hasKey(string $key)

Indicates if a given entity key exists.

Parameters

string $key

The name of the entity key to check.

Return Value

bool

TRUE if a given entity key exists, FALSE otherwise.

bool isStaticallyCacheable()

Indicates whether entities should be statically cached.

Return Value

bool

TRUE if static caching should be used; FALSE otherwise.

bool isRenderCacheable()

Indicates whether the rendered output of entities should be cached.

Return Value

bool

bool isPersistentlyCacheable()

Indicates if the persistent cache of field data should be used.

Used by ContentEntityStorageBase only. The persistent cache should usually only be disabled if a higher level persistent cache is available for the entity type.

Return Value

bool

bool hasHandlerClass(string $handler_type, string|false $nested = FALSE)

Determines if there is a handler for a given type.

Parameters

string $handler_type

The type of handler to check.

string|false $nested

(optional) The nested handler definition key, or FALSE if the handler does not have a nested definition. Defaults to FALSE.

Return Value

bool

TRUE if a handler of this type exists, FALSE otherwise.

array|string|null getHandlerClass(string $handler_type, string|false $nested = FALSE)

No description

Parameters

string $handler_type

The handler type to get.

string|false $nested

(optional) The nested handler definition key, or FALSE if the handler does not have a nested definition. Defaults to FALSE.

Return Value

array|string|null

The handlers for a given type, or NULL if none exist.

array getHandlerClasses()

Gets an array of handlers.

Return Value

array

An associative array where the keys are the names of different handler types (listed below) and the values are the names of the classes that implement that handler:

  • storage: The name of the class used to load the objects. The class must implement \Drupal\Core\Entity\EntityStorageInterface.
  • form: An associative array where the keys are the names of the different form operations (such as 'create', 'edit', or 'delete') and the values are the names of the handler classes for those operations. The name of the operation is passed also to the form handler's constructor, so that one class can be used for multiple entity forms when the forms are similar. The classes must implement \Drupal\Core\Entity\EntityFormInterface.
  • list_builder: The name of the class that provides listings of the entities. The class must implement \Drupal\Core\Entity\EntityListBuilderInterface.
  • view_builder: The name of the class that is used to render the entities. The class must implement \Drupal\Core\Entity\EntityViewBuilderInterface.
  • access: The name of the class that is used for access checks. The class must implement \Drupal\Core\Entity\EntityAccessControlHandlerInterface. Defaults to \Drupal\Core\Entity\EntityAccessControlHandler.
  • route_provider: (optional) A list of class names, keyed by a group string, which will be used to define routes related to this entity type. These classes must implement \Drupal\Core\Entity\Routing\EntityRouteProviderInterface.

string getStorageClass()

Gets the storage class.

Return Value

string

The class for this entity type's storage.

$this setStorageClass(string $class)

Sets the storage class.

Parameters

string $class

The class for this entity type's storage.

Return Value

$this

string|null getFormClass(string $operation)

Gets the form class for a specific operation.

Parameters

string $operation

The name of the operation to use, e.g., 'default'.

Return Value

string|null

The class for this operation's form for this entity type or NULL if the entity type does not have a form class for this operation.

See also

EntityFormBuilderInterface

$this setFormClass(string $operation, string $class)

Sets a form class for a specific operation.

Parameters

string $operation

The operation to use this form class for.

string $class

The form class implementing \Drupal\Core\Entity\EntityFormInterface.

Return Value

$this

See also

EntityFormBuilderInterface

bool hasFormClasses()

Indicates if this entity type has any forms.

Return Value

bool

TRUE if there are any forms for this entity type, FALSE otherwise.

bool hasRouteProviders()

Indicates if this entity type has any route provider.

Return Value

bool

string[] getRouteProviderClasses()

Gets all the route provide handlers.

Much like forms you can define multiple route provider handlers.

Return Value

string[]

string getListBuilderClass()

Gets the list class.

Return Value

string

The class for this entity type's list.

$this setListBuilderClass(string $class)

Sets the list class.

Parameters

string $class

The list class to use for the operation.

Return Value

$this

bool hasListBuilderClass()

Indicates if this entity type has a list class.

Return Value

bool

TRUE if there is a list for this entity type, FALSE otherwise.

string getViewBuilderClass()

Gets the view builder class.

Return Value

string

The class for this entity type's view builder.

$this setViewBuilderClass(string $class)

Gets the view builder class.

Parameters

string $class

The class for this entity type's view builder.

Return Value

$this

bool hasViewBuilderClass()

Indicates if this entity type has a view builder.

Return Value

bool

TRUE if there is a view builder for this entity type, FALSE otherwise.

string getAccessControlClass()

Gets the access control class.

Return Value

string

The class for this entity type's access control.

$this setAccessClass(string $class)

Sets the access control handler class.

Parameters

string $class

The class for this entity type's access control handler.

Return Value

$this

bool entityClassImplements(string $interface)

Indicates if the entity type class implements the given interface.

Parameters

string $interface

The class or interface to check.

Return Value

bool

TRUE if the entity type class implements the given interface.

bool isSubclassOf(string $class) deprecated

deprecated in drupal:8.3.0 and is removed from drupal:10.0.0. Use Drupal\Core\Entity\EntityTypeInterface::entityClassImplements() instead.

Indicates if the entity type is a subclass of the given class or interface.

Parameters

string $class

The class or interface to check.

Return Value

bool

TRUE if the entity type is a subclass of the class or interface.

See also

https://www.drupal.org/node/2842808

$this setHandlerClass(string $handler_type, array|string $value)

Sets the handlers for a given type.

Parameters

string $handler_type

The type of handler to set.

array|string $value

The value for a handler type.

Return Value

$this

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.

Return Value

string|bool

string getPermissionGranularity()

Gets the permission granularity level.

The allowed values are respectively "entity_type" or "bundle".

Return Value

string

Whether a module exposing permissions for the current entity type should use entity-type level granularity or bundle level granularity.

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.

Return Value

array

string|bool getLinkTemplate(string $key)

Gets the link template for a given key.

Parameters

string $key

The link type.

Return Value

string|bool

The path for this link, or FALSE if it doesn't exist.

bool hasLinkTemplate(string $key)

Indicates if a link template exists for a given key.

Parameters

string $key

The link type.

Return Value

bool

TRUE if the link template exists, FALSE otherwise.

$this setLinkTemplate(string $key, string $path)

Sets a single link template.

Parameters

string $key

The name of a link.

string $path

The route path to use for the link.

Return Value

$this

Exceptions

InvalidArgumentException

string|null getBundleEntityType()

Gets the name of the entity type which provides bundles.

Return Value

string|null

The name of the entity type which provides bundles, or NULL if the entity type does not have a bundle entity type.

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.

Return Value

string|null

The entity type for which this entity provides bundles, or NULL if does not provide bundles for another entity type.

string getBundleLabel()

Gets the label for the bundle.

Return Value

string

The bundle label.

string|null getBaseTable()

Gets the name of the entity's base table.

Used by SqlContentEntityStorage only.

Return Value

string|null

The name of the entity's base table, or NULL if none exists.

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.

Return Value

bool

TRUE if the entity data is internal, FALSE otherwise.

See also

DataDefinitionInterface::isInternal

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.

Return Value

bool

bool showRevisionUi()

Indicates whether the revision form fields should be added to the form.

Return Value

bool

TRUE if the form field should be added, FALSE otherwise.

bool isRevisionable()

Indicates whether entities of this type have revision support.

Return Value

bool

string|null getRevisionDataTable()

Gets the name of the entity's revision data table.

Used by SqlContentEntityStorage only.

Return Value

string|null

The name of the entity type's revision data table, or NULL if none exists.

string|null getRevisionTable()

Gets the name of the entity's revision table.

Used by SqlContentEntityStorage only.

Return Value

string|null

The name of the entity type's revision table, or NULL if none exists.

string|null getDataTable()

Gets the name of the entity's data table.

Used by SqlContentEntityStorage only.

Return Value

string|null

The name of the entity type's data table, or NULL if none exists.

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.

Return Value

string|TranslatableMarkup

The 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").

Return Value

string|TranslatableMarkup

The collection label.

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.

Return Value

string|TranslatableMarkup

The singular label.

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").

Return Value

string|TranslatableMarkup

The plural label.

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".

Parameters

int $count

The item count to display if the plural form was requested.

Return Value

string|TranslatableMarkup

The count label.

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.

Return Value

callable|null

A valid callback that is passed the entity or NULL if none is specified.

$this setUriCallback(callable $callback)

Sets a callable to use to provide the entity URI.

Parameters

callable $callback

A callback to use to provide a URI for the entity.

Return Value

$this

string getGroup()

Gets the machine name of the entity type group.

Return Value

string

string|TranslatableMarkup getGroupLabel()

Gets the human-readable name of the entity type group.

Return Value

string|TranslatableMarkup

The group label.

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.

Return Value

string[]

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.

Return Value

string[]

string getConfigDependencyKey()

Gets the key that is used to store configuration dependencies.

Return Value

string

The key to be used in configuration dependencies when storing dependencies on entities of this type.

bool isCommonReferenceTarget()

Indicates whether this entity type is commonly used as a reference target.

Return Value

bool

TRUE if the entity type is a common reference; FALSE otherwise.

array[] getConstraints()

Gets an array of validation constraints.

See \Drupal\Core\TypedData\DataDefinitionInterface::getConstraints() for details on how constraints are defined.

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

$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.

Parameters

array $constraints

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

Return Value

$this

See also

Constraint

$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.

Parameters

string $constraint_name

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

array|null $options

The constraint options as required by the constraint plugin, or NULL.

Return Value

$this

array getBundleConfigDependency(string $bundle)

Gets the config dependency info for this entity, if any exists.

Parameters

string $bundle

The bundle name.

Return Value

array

An associative array containing the following keys:

  • 'type': The config dependency type (e.g. 'module', 'config').
  • 'name': The name of the config dependency.

array getRevisionMetadataKeys()

Gets an array of entity revision metadata keys.

Return Value

array

An array describing how the Field API can extract revision metadata information of this entity type:

  • revision_log_message: The name of the property that contains description of the changes that were made in the current revision.
  • revision_user: The name of the property that contains the user ID of the author of the current revision.
  • revision_created: The name of the property that contains the timestamp of the current revision.

string|bool getRevisionMetadataKey(string $key)

Gets a specific entity revision metadata key.

Parameters

string $key

The name of the entity revision metadata key to return.

Return Value

string|bool

The entity revision metadata key, or FALSE if it does not exist.

See also

\Drupal\Core\Entity\self::getRevisionMetadataKeys()

bool hasRevisionMetadataKey(string $key)

Indicates if a given entity revision metadata key exists.

Parameters

string $key

The name of the entity revision metadata key to check.

Return Value

bool

TRUE if a given entity revision metadata key exists, FALSE otherwise.

$this setRevisionMetadataKey(string $key, string|null $field_name)

Sets a revision metadata key.

Parameters

string $key

The name of the entity revision metadata key to set.

string|null $field_name

The name of the entity field key to use for the revision metadata key. If NULL is passed, the value of the revision metadata key is unset.

Return Value

$this