class ContentEntityType in Drupal 8
Same name in this branch
- 8 core/lib/Drupal/Core/Entity/ContentEntityType.php \Drupal\Core\Entity\ContentEntityType
- 8 core/lib/Drupal/Core/Entity/Annotation/ContentEntityType.php \Drupal\Core\Entity\Annotation\ContentEntityType
Same name and namespace in other branches
- 9 core/lib/Drupal/Core/Entity/ContentEntityType.php \Drupal\Core\Entity\ContentEntityType
- 10 core/lib/Drupal/Core/Entity/ContentEntityType.php \Drupal\Core\Entity\ContentEntityType
Provides an implementation of a content entity type and its metadata.
Hierarchy
- class \Drupal\Component\Plugin\Definition\PluginDefinition implements PluginDefinitionInterface
- class \Drupal\Core\Entity\EntityType implements EntityTypeInterface uses DependencySerializationTrait, StringTranslationTrait
- class \Drupal\Core\Entity\ContentEntityType implements ContentEntityTypeInterface
- class \Drupal\Core\Entity\EntityType implements EntityTypeInterface uses DependencySerializationTrait, StringTranslationTrait
Expanded class hierarchy of ContentEntityType
6 files declare their use of ContentEntityType
- EntityDefinitionUpdateTest.php in core/
tests/ Drupal/ KernelTests/ Core/ Entity/ EntityDefinitionUpdateTest.php - EntityViewsData.php in core/
modules/ views/ src/ EntityViewsData.php - EntityViewsDataTest.php in core/
modules/ views/ tests/ src/ Unit/ EntityViewsDataTest.php - Contains \Drupal\Tests\views\Unit\EntityViewsDataTest.
- ModerationInformationTest.php in core/
modules/ content_moderation/ tests/ src/ Unit/ ModerationInformationTest.php - MoveRevisionMetadataFieldsUpdateTest.php in core/
modules/ system/ tests/ src/ Functional/ Entity/ Update/ MoveRevisionMetadataFieldsUpdateTest.php
File
- core/
lib/ Drupal/ Core/ Entity/ ContentEntityType.php, line 8
Namespace
Drupal\Core\EntityView source
class ContentEntityType extends EntityType implements ContentEntityTypeInterface {
/**
* An array of entity revision metadata keys.
*
* @var array
*/
protected $revision_metadata_keys = [];
/**
* The required revision metadata keys.
*
* @var array
*/
protected $requiredRevisionMetadataKeys = [];
/**
* {@inheritdoc}
*/
public function __construct($definition) {
parent::__construct($definition);
$this->handlers += [
'storage' => 'Drupal\\Core\\Entity\\Sql\\SqlContentEntityStorage',
'view_builder' => 'Drupal\\Core\\Entity\\EntityViewBuilder',
];
// Only new instances should provide the required revision metadata keys.
// The cached instances should return only what already has been stored
// under the property $revision_metadata_keys. The BC layer in
// ::getRevisionMetadataKeys() has to detect if the revision metadata keys
// have been provided by the entity type annotation, therefore we add keys
// to the property $requiredRevisionMetadataKeys only if those keys aren't
// set in the entity type annotation.
if (!isset($this->revision_metadata_keys['revision_default'])) {
$this->requiredRevisionMetadataKeys['revision_default'] = 'revision_default';
}
// Add the required revision metadata fields here instead in the getter
// method, so that they are serialized as part of the object even if the
// getter method doesn't get called. This allows the list to be further
// extended. Only new instances of the class will contain the new list,
// while the cached instances contain the previous version of the list.
$this->revision_metadata_keys += $this->requiredRevisionMetadataKeys;
}
/**
* {@inheritdoc}
*/
public function getConfigDependencyKey() {
return 'content';
}
/**
* {@inheritdoc}
*
* @throws \InvalidArgumentException
* If the provided class does not implement
* \Drupal\Core\Entity\ContentEntityStorageInterface.
*
* @see \Drupal\Core\Entity\ContentEntityStorageInterface
*/
protected function checkStorageClass($class) {
$required_interface = ContentEntityStorageInterface::class;
if (!is_subclass_of($class, $required_interface)) {
throw new \InvalidArgumentException("{$class} does not implement {$required_interface}");
}
}
/**
* {@inheritdoc}
*/
public function getRevisionMetadataKeys($include_backwards_compatibility_field_names = TRUE) {
// Provide backwards compatibility in case the revision metadata keys are
// not defined in the entity annotation.
if ((!$this->revision_metadata_keys || $this->revision_metadata_keys == $this->requiredRevisionMetadataKeys) && $include_backwards_compatibility_field_names) {
$base_fields = \Drupal::service('entity_field.manager')
->getBaseFieldDefinitions($this
->id());
if (isset($base_fields['revision_uid']) && ($revision_user = 'revision_uid') || isset($base_fields['revision_user']) && ($revision_user = 'revision_user')) {
@trigger_error('The revision_user revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_user'] = $revision_user;
}
if (isset($base_fields['revision_timestamp']) && ($revision_timestamp = 'revision_timestamp') || isset($base_fields['revision_created']) && ($revision_timestamp = 'revision_created')) {
@trigger_error('The revision_created revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_created'] = $revision_timestamp;
}
if (isset($base_fields['revision_log']) && ($revision_log = 'revision_log') || isset($base_fields['revision_log_message']) && ($revision_log = 'revision_log_message')) {
@trigger_error('The revision_log_message revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_log_message'] = $revision_log;
}
}
return $this->revision_metadata_keys;
}
/**
* {@inheritdoc}
*/
public function getRevisionMetadataKey($key) {
$keys = $this
->getRevisionMetadataKeys();
return isset($keys[$key]) ? $keys[$key] : FALSE;
}
/**
* {@inheritdoc}
*/
public function hasRevisionMetadataKey($key) {
$keys = $this
->getRevisionMetadataKeys();
return isset($keys[$key]);
}
/**
* {@inheritdoc}
*/
public function setRevisionMetadataKey($key, $field_name) {
if ($field_name !== NULL) {
// Update the property holding the required revision metadata keys,
// which is used by the BC layer for retrieving the revision metadata
// keys.
// @see \Drupal\Core\Entity\ContentEntityType::getRevisionMetadataKeys()
$this->requiredRevisionMetadataKeys[$key] = $field_name;
// Add the new revision metadata key.
$this->revision_metadata_keys[$key] = $field_name;
}
else {
unset($this->requiredRevisionMetadataKeys[$key], $this->revision_metadata_keys[$key]);
}
return $this;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContentEntityType:: |
protected | property | The required revision metadata keys. | |
ContentEntityType:: |
protected | property | An array of entity revision metadata keys. | |
ContentEntityType:: |
protected | function |
Overrides EntityType:: |
|
ContentEntityType:: |
public | function |
Gets the key that is used to store configuration dependencies. Overrides EntityType:: |
|
ContentEntityType:: |
public | function |
Gets a specific entity revision metadata key. Overrides ContentEntityTypeInterface:: |
|
ContentEntityType:: |
public | function |
Gets an array of entity revision metadata keys. Overrides ContentEntityTypeInterface:: |
|
ContentEntityType:: |
public | function |
Indicates if a given entity revision metadata key exists. Overrides ContentEntityTypeInterface:: |
|
ContentEntityType:: |
public | function |
Sets a revision metadata key. Overrides ContentEntityTypeInterface:: |
|
ContentEntityType:: |
public | function |
Constructs a new EntityType. Overrides EntityType:: |
1 |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
EntityType:: |
protected | property | Any additional properties and values. | |
EntityType:: |
protected | property | The name of the default administrative permission. | |
EntityType:: |
protected | property | The name of the entity type's base table. | |
EntityType:: |
protected | property | The name of the entity type which provides bundles. | |
EntityType:: |
protected | property | The human-readable name of the entity bundles, e.g. Vocabulary. | |
EntityType:: |
protected | property | The name of the entity type for which bundles are provided. | |
EntityType:: |
protected | property | Indicates whether this entity type is commonly used as a reference target. | |
EntityType:: |
protected | property | Entity constraint definitions. | |
EntityType:: |
protected | property | The name of the entity type's data table. | |
EntityType:: |
protected | property | An array of entity keys. | |
EntityType:: |
protected | property | The route name used by field UI to attach its management pages. | |
EntityType:: |
protected | property | The machine name of the entity type group. | |
EntityType:: |
protected | property | The human-readable name of the entity type group. | |
EntityType:: |
protected | property | An array of handlers. | |
EntityType:: |
protected | property |
The unique identifier of this entity type. Overrides PluginDefinition:: |
|
EntityType:: |
protected | property | Indicates whether the entity data is internal. | |
EntityType:: |
protected | property | The human-readable name of the type. | |
EntityType:: |
protected | property | The name of a callback that returns the label of the entity. | |
EntityType:: |
protected | property | The human-readable label for a collection of entities of the type. | |
EntityType:: |
protected | property | A definite singular/plural name of the type. | |
EntityType:: |
protected | property | The indefinite plural name of the type. | |
EntityType:: |
protected | property | The indefinite singular name of the type. | |
EntityType:: |
protected | property | Link templates using the URI template syntax. | |
EntityType:: |
protected | property | The list cache contexts for this entity type. | |
EntityType:: |
protected | property | The list cache tags for this entity type. | |
EntityType:: |
protected | property | The name of the original entity type class. | |
EntityType:: |
protected | property | The permission granularity level. | |
EntityType:: |
protected | property | Indicates if the persistent cache of field data should be used. | |
EntityType:: |
protected | property | Indicates whether the rendered output of entities should be cached. | |
EntityType:: |
protected | property | The name of the entity type's revision data table. | |
EntityType:: |
protected | property | The name of the entity type's revision table. | |
EntityType:: |
protected | property | Indicates whether the revision form fields should be added to the form. | |
EntityType:: |
protected | property | Indicates whether entities should be statically cached. | 1 |
EntityType:: |
protected | property | Indicates whether entities of this type have multilingual support. | |
EntityType:: |
protected | property | A callable that can be used to provide the entity URI. | |
EntityType:: |
public | function |
Adds a validation constraint. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if the entity type class implements the given interface. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets any arbitrary property. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the access control class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the default administrative permission. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's base table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the config dependency info for this entity, if any exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity type which provides bundles. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the label for the bundle. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the entity type for which this entity provides bundles. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the uppercase plural form of the name of the entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets an array of validation constraints. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the label's definite article form for use with a count of entities. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's data table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the form class for a specific operation. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the machine name of the entity type group. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the human-readable name of the entity type group. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets an array of handlers. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets a specific entity key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets an array of entity keys. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the human-readable name of the entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the callback for the label of the entity. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the link template for a given key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the link templates using the URI template syntax. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
The list cache contexts associated with this entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
The list cache tags associated with this entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the lowercase form of the human-readable entity type name. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the original entity type class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the permission granularity level. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the indefinite plural form of the name of the entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the name of the entity's revision data table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets the name of the entity's revision table. Overrides EntityTypeInterface:: |
1 |
EntityType:: |
public | function |
Gets all the route provide handlers. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the indefinite singular form of the name of the entity type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the storage class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets a callable that can be used to provide the entity URI. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the view builder class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has any forms. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Determines if there is a handler for a given type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a given entity key exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a label callback exists. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if a link template exists for a given key. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has a list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has any route provider. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if this entity type has a view builder. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether this entity type is commonly used as a reference target. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the entity data is internal. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if the persistent cache of field data should be used. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the rendered output of entities should be cached. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities of this type have revision support. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities should be statically cached. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates if the entity type is a subclass of the given class or interface. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether entities of this type have multilingual support. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a value to an arbitrary property. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the access control handler class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the class. Overrides PluginDefinition:: |
|
EntityType:: |
public | function |
Sets the array of validation constraints for the FieldItemList. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a form class for a specific operation. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the handlers for a given type. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the label callback. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a single link template. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the list class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets the storage class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Sets a callable to use to provide the entity URI. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Gets the view builder class. Overrides EntityTypeInterface:: |
|
EntityType:: |
public | function |
Indicates whether the revision form fields should be added to the form. Overrides EntityTypeInterface:: |
|
EntityTypeInterface:: |
constant | The maximum length of bundle name, in characters. | ||
EntityTypeInterface:: |
constant | The maximum length of ID, in characters. | ||
PluginDefinition:: |
protected | property | A fully qualified class name. | |
PluginDefinition:: |
protected | property | The plugin provider. | |
PluginDefinition:: |
public | function |
Gets the class. Overrides PluginDefinitionInterface:: |
|
PluginDefinition:: |
public | function |
Gets the plugin provider. Overrides PluginDefinitionInterface:: |
|
PluginDefinition:: |
public | function |
Gets the unique identifier of the plugin. Overrides PluginDefinitionInterface:: |
1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |