You are here

public function EntityType::__construct in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 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 259
Contains \Drupal\Core\Entity\EntityType.

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',
    ];
  }
}