You are here

public function DefaultTableMapping::__construct in Drupal 9

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php \Drupal\Core\Entity\Sql\DefaultTableMapping::__construct()

Constructs a DefaultTableMapping.

Parameters

\Drupal\Core\Entity\ContentEntityTypeInterface $entity_type: The entity type definition.

\Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions: A list of field storage definitions that should be available for the field columns of this table mapping.

string $prefix: (optional) A prefix to be used by all the tables of this mapping. Defaults to an empty string.

File

core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php, line 127

Class

DefaultTableMapping
Defines a default table mapping class.

Namespace

Drupal\Core\Entity\Sql

Code

public function __construct(ContentEntityTypeInterface $entity_type, array $storage_definitions, $prefix = '') {
  $this->entityType = $entity_type;
  $this->fieldStorageDefinitions = $storage_definitions;
  $this->prefix = $prefix;

  // @todo Remove table names from the entity type definition in
  //   https://www.drupal.org/node/2232465.
  $this->baseTable = $this->prefix . $entity_type
    ->getBaseTable() ?: $entity_type
    ->id();
  if ($entity_type
    ->isRevisionable()) {
    $this->revisionTable = $this->prefix . $entity_type
      ->getRevisionTable() ?: $entity_type
      ->id() . '_revision';
  }
  if ($entity_type
    ->isTranslatable()) {
    $this->dataTable = $this->prefix . $entity_type
      ->getDataTable() ?: $entity_type
      ->id() . '_field_data';
  }
  if ($entity_type
    ->isRevisionable() && $entity_type
    ->isTranslatable()) {
    $this->revisionDataTable = $this->prefix . $entity_type
      ->getRevisionDataTable() ?: $entity_type
      ->id() . '_field_revision';
  }
}