8.3.x EntityType.php public EntityType::__construct($definition)
8.0.x EntityType.php public EntityType::__construct($definition)
8.1.x EntityType.php public EntityType::__construct($definition)
8.2.x EntityType.php public EntityType::__construct($definition)
8.4.x EntityType.php public EntityType::__construct($definition)

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 278

Class

EntityType
Provides an implementation of an entity type and its metadata.

Namespace

Drupal\Core\Entity

Code

public function __construct($definition) {
  // Throw an exception if the entity type ID is longer than 32 characters.
  if (Unicode::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 += array(
    'revision' => '',
    'bundle' => '',
    'langcode' => '',
    'default_langcode' => 'default_langcode',
  );
  $this->handlers += array(
    '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->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface')) {
    $this->addConstraint('EntityChanged');
  }

  // Ensure a default list cache tag is set.
  if (empty($this->list_cache_tags)) {
    $this->list_cache_tags = [$definition['id'] . '_list'];
  }
}