class EntityType extends PluginDefinition implements EntityTypeInterface (View source)

Provides an implementation of an entity type and its metadata.

Traits

Provides dependency injection friendly methods for serialization.

Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.

Properties

protected string $id

The unique identifier of this entity type.

protected string $class

A fully qualified class name.

from  PluginDefinition
protected string $provider

The plugin provider.

from  PluginDefinition
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 TranslationInterface $stringTranslation

The string translation service.

from  StringTranslationTrait
protected bool $static_cache

Indicates whether entities should be statically cached.

protected bool $render_cache

Indicates whether the rendered output of entities should be cached.

protected bool $persistent_cache

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

protected array $entity_keys

An array of entity keys.

protected string $originalClass

The name of the original entity type class.

protected array $handlers

An array of handlers.

protected string $admin_permission

The name of the default administrative permission.

protected string $permission_granularity

The permission granularity level.

$links

Link templates using the URI template syntax.

protected callable|null deprecated $label_callback

The name of a callback that returns the label of the entity.

protected string $bundle_entity_type

The name of the entity type which provides bundles.

protected string|null $bundle_of

The name of the entity type for which bundles are provided.

protected string|null $bundle_label

The human-readable name of the entity bundles, e.g. Vocabulary.

protected string|null $base_table

The name of the entity type's base table.

protected string|null $revision_data_table

The name of the entity type's revision data table.

protected string|null $revision_table

The name of the entity type's revision table.

protected string|null $data_table

The name of the entity type's data table.

protected bool $internal

Indicates whether the entity data is internal.

protected bool $translatable

Indicates whether entities of this type have multilingual support.

protected bool $show_revision_ui

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

protected string|TranslatableMarkup $label

The human-readable name of the type.

protected string|TranslatableMarkup $label_collection

The human-readable label for a collection of entities of the type.

protected string|TranslatableMarkup $label_singular

The indefinite singular name of the type.

protected string|TranslatableMarkup $label_plural

The indefinite plural name of the type.

protected string|TranslatableMarkup $label_count

A definite singular/plural name of the type.

protected callable|null $uri_callback

A callable that can be used to provide the entity URI.

protected string $group

The machine name of the entity type group.

protected string|TranslatableMarkup $group_label

The human-readable name of the entity type group.

protected string $field_ui_base_route

The route name used by field UI to attach its management pages.

protected bool $common_reference_target

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

protected string[] $list_cache_contexts

The list cache contexts for this entity type.

protected string[] $list_cache_tags

The list cache tags for this entity type.

protected array[] $constraints

Entity constraint definitions.

protected array $additional

Any additional properties and values.

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.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

getStringTranslation()

Gets the string translation service.

$this
setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

__construct(array $definition)

Constructs a new EntityType.

mixed
get(string $property)

Gets any arbitrary property.

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

Sets a value to an arbitrary property.

bool
isInternal()

Indicates whether the entity data is internal.

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.

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.

string
getOriginalClass()

Gets the name of the original entity type class.

bool
entityClassImplements(string $interface)

Indicates if the entity type class implements the given interface.

bool
isSubclassOf(string $class)

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

array
getHandlerClasses()

Gets an array of handlers.

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

No description

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

Sets the handlers for a given type.

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

Determines if there is a handler for a given type.

string
getStorageClass()

Gets the storage class.

$this
setStorageClass(string $class)

Sets the storage class.

checkStorageClass(string $class)

Checks that the provided class is compatible with the current entity type.

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
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[]
getRouteProviderClasses()

Gets all the route provide handlers.

string
getAccessControlClass()

Gets the access control class.

$this
setAccessClass(string $class)

Sets the access control handler class.

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.

callable|null
getLabelCallback()

Gets the callback for the label of the entity.

$this
setLabelCallback(callable $callback)

Sets the label callback.

bool
hasLabelCallback()

Indicates if a label callback exists.

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
showRevisionUi()

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

bool
isTranslatable()

Indicates whether entities of this type have multilingual support.

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.

string
getLowercaseLabel()

Gets the lowercase form of the human-readable entity type name.

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.

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.

__sleep()

{@inheritdoc}

__wakeup()

{@inheritdoc}

protected TranslatableMarkup t(string $string, array $args = [], array $options = [])

Translates a string to the current language or to a given language.

See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.

In order for strings to be localized, make them available in one of the ways supported by the

Parameters

string $string

A string containing the English text to translate.

array $args

(optional) An associative array of replacements to make after translation. Based on the first character of the key, the value is escaped and/or themed. See \Drupal\Component\Render\FormattableMarkup::placeholderFormat() for details.

array $options

(optional) An associative array of additional options, with the following elements:

  • 'langcode' (defaults to the current language): A language code, to translate to a language other than what is used to display the page.
  • 'context' (defaults to the empty context): The context the source string belongs to. See the @link i18n Internationalization topic @endlink for more information about string contexts.

Return Value

TranslatableMarkup

An object that, when cast to a string, returns the translated string.

See also

FormattableMarkup::placeholderFormat
TranslatableMarkup::__construct

protected formatPlural($count, $singular, $plural, array $args = [], array $options = [])

Formats a string containing a count of items.

Parameters

$count
$singular
$plural
array $args
array $options

See also

TranslationInterface::formatPlural

protected getNumberOfPlurals($langcode = NULL)

Returns the number of plurals supported by a given language.

Parameters

$langcode

See also

PluralFormulaInterface::getNumberOfPlurals

protected TranslationInterface getStringTranslation()

Gets the string translation service.

Return Value

TranslationInterface

The string translation service.

$this setStringTranslation(TranslationInterface $translation)

Sets the string translation service to use.

Parameters

TranslationInterface $translation

The string translation service.

Return Value

$this

__construct(array $definition)

Constructs a new EntityType.

Parameters

array $definition

An array of values from the annotation.

Exceptions

EntityTypeIdLengthException

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

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.

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.

Return Value

bool

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.

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.

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.

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)

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.

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: The name of the class that provides listings of the entities. The class must implement \Drupal\Core\Entity\EntityListBuilderInterface.
  • render: 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.

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.

$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

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.

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

protected checkStorageClass(string $class)

Checks that the provided class is compatible with the current entity type.

Parameters

string $class

The class to check.

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.

$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

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 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[] getRouteProviderClasses()

Gets all the route provide handlers.

Much like forms you can define multiple route provider handlers.

Return Value

string[]

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

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

callable|null getLabelCallback()

Gets the callback for the label of the entity.

The function takes an entity and returns the label of the entity. Use language() on the entity to get information on the requested language. The entity label is the main string associated with an entity; for example, the title of a node or the subject of a comment. If there is an entity object property that defines the label, use the 'label' element of the 'entity_keys' return value component to provide this information. If more complex logic is needed to determine the label of an entity, you can instead specify a callback function here, which will be called to determine the entity label.

Return Value

callable|null

The callback, or NULL if none exists.

$this setLabelCallback(callable $callback)

Sets the label callback.

Parameters

callable $callback

A callable that returns the label of the entity.

Return Value

$this

bool hasLabelCallback()

Indicates if a label callback exists.

Return Value

bool

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.

Return Value

string|null

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

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

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.

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.

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 getLowercaseLabel()

Gets the lowercase form of the human-readable entity type name.

Return Value

string

The lowercase form of the human-readable entity type name.

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.

$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

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