function ContentEntityType::__construct

Constructs a new EntityType.

Parameters

array $definition: An array of values from the annotation.

Overrides EntityType::__construct

1 call to ContentEntityType::__construct()
TestRevisionMetadataBcLayerEntityType::__construct in core/modules/system/tests/src/Functional/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
Constructs a new EntityType.
1 method overrides ContentEntityType::__construct()
TestRevisionMetadataBcLayerEntityType::__construct in core/modules/system/tests/src/Functional/Entity/Update/MoveRevisionMetadataFieldsUpdateTest.php
Constructs a new EntityType.

File

core/lib/Drupal/Core/Entity/ContentEntityType.php, line 27

Class

ContentEntityType
Provides an implementation of a content entity type and its metadata.

Namespace

Drupal\Core\Entity

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.