setTableMapping example

->range(0, $step_size)
      ->execute()
      ->fetchCol();

    /** @var \Drupal\Core\Entity\ContentEntityInterface[] $entities */
    $entities = $load_revisions ? $this->storage->loadMultipleRevisions($entity_identifiers) : $this->storage->loadMultiple($entity_identifiers);

    /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $temporary_storage */
    $temporary_storage = $this->entityTypeManager->createHandlerInstance($entity_type->getStorageClass()$entity_type);
    $temporary_storage->setEntityType($entity_type);
    $temporary_storage->setFieldStorageDefinitions($field_storage_definitions);
    $temporary_storage->setTableMapping($sandbox['temporary_table_mapping']);

    foreach ($entities as $identifier => $entity) {
      try {
        if (!$original->isRevisionable() && $entity_type->isRevisionable()) {
          // Set the revision ID to be same as the entity ID.           $entity->set($revision_id_key$entity->id());

          // We had no revisions so far, so the existing data belongs to the           // default revision now.           $entity->set($revision_default_key, TRUE);
        }

        
$this->getTableNames($entity_type$field_storage_definitions$sandbox['new_table_mapping']),
      $this->getTableNames($entity_type$field_storage_definitions$sandbox['temporary_table_mapping'])
    );
    $this->entityType = $entity_type;
    $this->fieldStorageDefinitions = $field_storage_definitions;

    // Update the storage's entity type and field storage definitions because     // ::getEntitySchema() and ::getSharedTableFieldSchema() overrides are     // retrieving table names from these definitions.     $this->storage->setEntityType($entity_type);
    $this->storage->setFieldStorageDefinitions($field_storage_definitions);
    $this->storage->setTableMapping($sandbox['new_table_mapping']);

    $schema = $this->getEntitySchema($entity_type, TRUE);
    $sandbox['new_entity_schema'] = $schema;

    // Filter out tables which are not part of the table mapping.     $schema = array_intersect_key($schema$temporary_table_names);

    // Create entity tables.     foreach ($schema as $table_name => $table_schema) {
      $this->database->schema()->createTable($temporary_table_names[$table_name]$table_schema);
    }

    
$updated_entity_type->expects($this->any())
      ->method('id')
      ->willReturn($this->entityTypeId);
    $updated_entity_type->expects($this->any())
      ->method('isRevisionable')
      ->willReturn(TRUE);
    $updated_entity_type->expects($this->any())
      ->method('isTranslatable')
      ->willReturn(TRUE);

    $table_mapping = new DefaultTableMapping($updated_entity_type[]);
    $this->entityStorage->setTableMapping($table_mapping);

    $this->assertSame('entity_test', $this->entityStorage->getBaseTable());
    $this->assertSame('entity_test_revision', $this->entityStorage->getRevisionTable());
    $this->assertSame('entity_test_field_data', $this->entityStorage->getDataTable());
    $this->assertSame('entity_test_field_revision', $this->entityStorage->getRevisionDataTable());
  }

  /** * Tests ContentEntityDatabaseStorage::onEntityTypeCreate(). * * @covers ::__construct * @covers ::onEntityTypeCreate * @covers ::getTableMapping */
Home | Imprint | This part of the site doesn't use cookies.