ContentEntityType
class ContentEntityType extends EntityType implements ContentEntityTypeInterface (View source)
Provides an implementation of a content 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. |
from EntityType |
| 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. |
from EntityType |
| protected bool | $render_cache | Indicates whether the rendered output of entities should be cached. |
from EntityType |
| protected bool | $persistent_cache | Indicates if the persistent cache of field data should be used. |
from EntityType |
| protected array | $entity_keys | An array of entity keys. |
from EntityType |
| protected string | $originalClass | The name of the original entity type class. |
from EntityType |
| protected array | $handlers | An array of handlers. |
from EntityType |
| protected string | $admin_permission | The name of the default administrative permission. |
from EntityType |
| protected string | $permission_granularity | The permission granularity level. |
from EntityType |
| protected array | $links | Link templates using the URI template syntax. |
from EntityType |
| protected string | $bundle_entity_type | The name of the entity type which provides bundles. |
from EntityType |
| protected string|null | $bundle_of | The name of the entity type for which bundles are provided. |
from EntityType |
| protected string|null | $bundle_label | The human-readable name of the entity bundles, e.g. Vocabulary. |
from EntityType |
| protected string|null | $base_table | The name of the entity type's base table. |
from EntityType |
| protected string|null | $revision_data_table | The name of the entity type's revision data table. |
from EntityType |
| protected string|null | $revision_table | The name of the entity type's revision table. |
from EntityType |
| protected string|null | $data_table | The name of the entity type's data table. |
from EntityType |
| protected bool | $internal | Indicates whether the entity data is internal. |
from EntityType |
| protected bool | $translatable | Indicates whether entities of this type have multilingual support. |
from EntityType |
| protected bool | $show_revision_ui | Indicates whether the revision form fields should be added to the form. |
from EntityType |
| protected string|TranslatableMarkup | $label | The human-readable name of the type. |
from EntityType |
| protected string|TranslatableMarkup | $label_collection | The human-readable label for a collection of entities of the type. |
from EntityType |
| protected string|TranslatableMarkup | $label_singular | The indefinite singular name of the type. |
from EntityType |
| protected string|TranslatableMarkup | $label_plural | The indefinite plural name of the type. |
from EntityType |
| protected string|TranslatableMarkup | $label_count | A definite singular/plural name of the type. |
from EntityType |
| protected callable|null | $uri_callback | A callable that can be used to provide the entity URI. |
from EntityType |
| protected string | $group | The machine name of the entity type group. |
from EntityType |
| protected string|TranslatableMarkup | $group_label | The human-readable name of the entity type group. |
from EntityType |
| protected string | $field_ui_base_route | The route name used by field UI to attach its management pages. |
from EntityType |
| protected bool | $common_reference_target | Indicates whether this entity type is commonly used as a reference target. |
from EntityType |
| protected string[] | $list_cache_contexts | The list cache contexts for this entity type. |
from EntityType |
| protected string[] | $list_cache_tags | The list cache tags for this entity type. |
from EntityType |
| protected array[] | $constraints | Entity constraint definitions. |
from EntityType |
| protected array | $additional | Any additional properties and values. |
from EntityType |
| protected array | $revision_metadata_keys | An array of entity revision metadata keys. |
Methods
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Constructs a new EntityType.
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.
Indicates if the entity type class implements the given interface.
Indicates if the entity type is a subclass of the given class or interface.
No description
Sets the handlers for a given type.
Determines if there is a handler for a given type.
Checks that the provided class is compatible with the current entity type.
Gets the form class for a specific operation.
Sets a form class for a specific operation.
Gets the name of the default administrative permission.
Indicates if a link template exists for a given key.
Gets the name of the entity type which provides bundles.
Gets the entity type for which this entity provides bundles.
Indicates whether the revision form fields should be added to the form.
Indicates whether entities of this type have multilingual support.
Indicates whether entities of this type have revision support.
Gets the name of the entity's revision 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 human-readable name of the entity type group.
The list cache contexts 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.
Sets the array of validation constraints for the FieldItemList.
Adds a validation constraint.
Gets the config dependency info for this entity, if any exists.
Gets an array of entity revision metadata keys.
Gets a specific entity revision metadata key.
Indicates if a given entity revision metadata key exists.
Sets a revision metadata key.
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".
__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
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
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.
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
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.
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.
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.
protected
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.
Much like forms you can define multiple route provider 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.
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
showRevisionUi()
Indicates whether the revision form fields should be added to the form.
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
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.
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.