You are here

public function CiviEntityStorage::getTableMapping in CiviCRM Entity 8.3

Gets a table mapping for the entity's SQL tables.

Parameters

\Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions: (optional) An array of field storage definitions to be used to compute the table mapping. Defaults to the ones provided by the entity manager.

Return value

\Drupal\Core\Entity\Sql\TableMappingInterface A table mapping object for the entity's tables.

Overrides SqlContentEntityStorage::getTableMapping

6 calls to CiviEntityStorage::getTableMapping()
CiviEntityStorage::countFieldData in src/CiviEntityStorage.php
CiviEntityStorage::doDeleteFieldItems in src/CiviEntityStorage.php
Deletes entity field values from the storage.
CiviEntityStorage::doSaveFieldItems in src/CiviEntityStorage.php
Writes entity field values to the storage.
CiviEntityStorage::loadFromDedicatedTables in src/CiviEntityStorage.php
Loads values of fields stored in dedicated tables for a group of entities.
CiviEntityStorage::onFieldStorageDefinitionDelete in src/CiviEntityStorage.php
Reacts to the deletion of a field storage definition.

... See full list

File

src/CiviEntityStorage.php, line 452

Class

CiviEntityStorage
Defines entity class for external CiviCRM entities.

Namespace

Drupal\civicrm_entity

Code

public function getTableMapping(array $storage_definitions = NULL) {
  $table_mapping = $this->tableMapping;
  if ($table_mapping) {
    return $table_mapping;
  }
  $table_mapping_class = DefaultTableMapping::class;
  $definitions = $this
    ->getEntityFieldManager()
    ->getFieldStorageDefinitions($this->entityTypeId);

  /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping|\Drupal\Core\Entity\Sql\TemporaryTableMapping $table_mapping */
  $table_mapping = new $table_mapping_class($this->entityType, $definitions);

  // Add dedicated tables.
  $dedicated_table_definitions = array_filter($definitions, function (FieldStorageDefinitionInterface $definition) use ($table_mapping) {
    return $table_mapping
      ->requiresDedicatedTableStorage($definition);
  });
  $extra_columns = [
    'bundle',
    'deleted',
    'entity_id',
    'revision_id',
    'langcode',
    'delta',
  ];
  foreach ($dedicated_table_definitions as $field_name => $definition) {
    $tables = [
      $table_mapping
        ->getDedicatedDataTableName($definition),
    ];
    foreach ($tables as $table_name) {
      $table_mapping
        ->setFieldNames($table_name, [
        $field_name,
      ]);
      $table_mapping
        ->setExtraColumns($table_name, $extra_columns);
    }
  }
  $this->tableMapping = $table_mapping;
  return $table_mapping;
}