function EntityType::__construct
Same name in other branches
- 9 core/lib/Drupal/Core/Entity/EntityType.php \Drupal\Core\Entity\EntityType::__construct()
- 10 core/lib/Drupal/Core/Entity/EntityType.php \Drupal\Core\Entity\EntityType::__construct()
- 11.x core/lib/Drupal/Core/Entity/EntityType.php \Drupal\Core\Entity\EntityType::__construct()
Constructs a new EntityType.
Parameters
array $definition: An array of values from the annotation.
Throws
\Drupal\Core\Entity\Exception\EntityTypeIdLengthException Thrown when attempting to instantiate an entity type with too long ID.
2 calls to EntityType::__construct()
- ConfigEntityType::__construct in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityType.php - ContentEntityType::__construct in core/
lib/ Drupal/ Core/ Entity/ ContentEntityType.php - Constructs a new EntityType.
2 methods override EntityType::__construct()
- ConfigEntityType::__construct in core/
lib/ Drupal/ Core/ Config/ Entity/ ConfigEntityType.php - ContentEntityType::__construct in core/
lib/ Drupal/ Core/ Entity/ ContentEntityType.php - Constructs a new EntityType.
File
-
core/
lib/ Drupal/ Core/ Entity/ EntityType.php, line 300
Class
- EntityType
- Provides an implementation of an entity type and its metadata.
Namespace
Drupal\Core\EntityCode
public function __construct($definition) {
// Throw an exception if the entity type ID is longer than 32 characters.
if (mb_strlen($definition['id']) > static::ID_MAX_LENGTH) {
throw new EntityTypeIdLengthException('Attempt to create an entity type with an ID longer than ' . static::ID_MAX_LENGTH . " characters: {$definition['id']}.");
}
foreach ($definition as $property => $value) {
$this->set($property, $value);
}
// Ensure defaults.
$this->entity_keys += [
'revision' => '',
'bundle' => '',
'langcode' => '',
'default_langcode' => 'default_langcode',
'revision_translation_affected' => 'revision_translation_affected',
];
$this->handlers += [
'access' => 'Drupal\\Core\\Entity\\EntityAccessControlHandler',
];
if (isset($this->handlers['storage'])) {
$this->checkStorageClass($this->handlers['storage']);
}
// Automatically add the "EntityChanged" constraint if the entity type
// tracks the changed time.
if ($this->entityClassImplements(EntityChangedInterface::class)) {
$this->addConstraint('EntityChanged');
}
// Automatically add the "EntityUntranslatableFields" constraint if we have
// an entity type supporting translatable fields and pending revisions.
if ($this->entityClassImplements(ContentEntityInterface::class)) {
$this->addConstraint('EntityUntranslatableFields');
}
// Ensure a default list cache tag is set.
if (empty($this->list_cache_tags)) {
$this->list_cache_tags = [
$definition['id'] . '_list',
];
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.