getFieldTableName example


      $query->condition($or);
      if (!$as_bool) {
        $query
          ->fields('t', ['entity_id'])
          ->distinct(TRUE);
      }
    }
    elseif ($table_mapping->allowsSharedTableStorage($storage_definition)) {
      // Ascertain the table this field is mapped too.       $field_name = $storage_definition->getName();
      $table_name = $table_mapping->getFieldTableName($field_name);
      $query = $this->database->select($table_name, 't');
      $or = $query->orConditionGroup();
      foreach (array_keys($storage_definition->getColumns()) as $property_name) {
        $or->isNotNull($table_mapping->getFieldColumnName($storage_definition$property_name));
      }
      $query->condition($or);
      if (!$as_bool) {
        $query
          ->fields('t', [$this->idKey])
          ->distinct(TRUE);
      }
    }
    // field storage definition is added. Since the cardinality of the field is     // greater than 1, the table name retrieved from getFieldTableName() should     // be the dedicated table.     $field_storage = FieldStorageConfig::create([
      'entity_type' => 'entity_test_rev',
      'field_name' => 'some_field_name',
      'type' => 'test_field',
      'cardinality' => 2,
    ]);
    $field_storage->save();
    $table_mapping = \Drupal::entityTypeManager()->getStorage('entity_test_rev')->getTableMapping();
    $this->assertEquals($table_mapping->getDedicatedDataTableName($field_storage)$table_mapping->getFieldTableName('some_field_name'));
  }

}

  protected function getLangcodeTable(QueryPluginBase $query$relationship) {
    /** @var \Drupal\Core\Entity\Sql\SqlContentEntityStorage $storage */
    $storage = \Drupal::entityTypeManager()->getStorage($this->entityType->id());
    $langcode_key = $this->entityType->getKey('langcode');
    $langcode_table = $storage->getTableMapping()->getFieldTableName($langcode_key);

    // If the entity type is revisionable, we need to take into account views of     // entity revisions. Usually the view will use the entity data table as the     // query base table, however, in case of an entity revision view, we need to     // use the revision table or the revision data table, depending on which one     // is being used as query base table.     if ($this->entityType->isRevisionable()) {
      $query_base_table = $query->relationships[$relationship]['base'] ??
        $this->view->storage->get('base_table');
      $revision_table = $storage->getRevisionTable();
      $revision_data_table = $storage->getRevisionDataTable();
      
$data_table_row = $this->database->select('entity_test_update_data')
        ->fields('entity_test_update_data')
        ->condition('id', 1, '=')
        ->condition('langcode', 'ro', '=')
        ->execute()
        ->fetchAllAssoc('id');
      $this->assertEquals('test entity - 1 - ro', $data_table_row[1]->name);
      $this->assertEquals('shared table - 1 - value 1 - ro', $data_table_row[1]->test_multiple_properties__value1);
      $this->assertEquals('shared table - 1 - value 2 - ro', $data_table_row[1]->test_multiple_properties__value2);

      $dedicated_table_name = $table_mapping->getFieldTableName('test_multiple_properties_multiple_values');
      $dedicated_table_row = $this->database->select($dedicated_table_name)
        ->fields($dedicated_table_name)
        ->condition('entity_id', 1, '=')
        ->condition('langcode', 'en', '=')
        ->execute()
        ->fetchAllAssoc('delta');
      $this->assertEquals('dedicated table - 1 - delta 0 - value 1 - en', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value1);
      $this->assertEquals('dedicated table - 1 - delta 0 - value 2 - en', $dedicated_table_row[0]->test_multiple_properties_multiple_values_value2);
      $this->assertEquals('dedicated table - 1 - delta 1 - value 1 - en', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value1);
      $this->assertEquals('dedicated table - 1 - delta 1 - value 2 - en', $dedicated_table_row[1]->test_multiple_properties_multiple_values_value2);

      
    if (!$this->storage->countFieldData($storage_definition, TRUE)) {
      $this->performFieldSchemaOperation('delete', $storage_definition);
      return;
    }

    // There's nothing else we can do if the field storage has a custom storage.     if ($storage_definition->hasCustomStorage()) {
      return;
    }

    $table_mapping = $this->getTableMapping($this->entityType, [$storage_definition]);
    $field_table_name = $table_mapping->getFieldTableName($storage_definition->getName());

    if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) {
      // Move the table to a unique name while the table contents are being       // deleted.       $table = $table_mapping->getDedicatedDataTableName($storage_definition);
      $new_table = $table_mapping->getDedicatedDataTableName($storage_definition, TRUE);
      $this->database->schema()->renameTable($table$new_table);
      if ($this->entityType->isRevisionable()) {
        $revision_table = $table_mapping->getDedicatedRevisionTableName($storage_definition);
        $revision_new_table = $table_mapping->getDedicatedRevisionTableName($storage_definition, TRUE);
        $this->database->schema()->renameTable($revision_table$revision_new_table);
      }


  /** * Tests DefaultTableMapping::getFieldTableName(). * * @covers ::getFieldTableName */
  public function testGetFieldTableName() {
    // Test the field table name for a single-valued base field, which is stored     // in the entity's base table.     $expected = 'entity_test_mulrev';
    $this->assertEquals($this->tableMapping->getFieldTableName('uuid')$expected);

    // Test the field table name for a translatable and revisionable base field,     // which is stored in the entity's data table.     $expected = 'entity_test_mulrev_property_data';
    $this->assertEquals($this->tableMapping->getFieldTableName('name')$expected);

    // Test the field table name for a multi-valued base field, which is stored     // in a dedicated table.     $expected = 'entity_test_mulrev__multivalued_base_field';
    $this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field')$expected);
  }

  
->method('getRevisionMetadataKeys')
      ->willReturn([]);

    $table_mapping = new TestDefaultTableMapping($this->entityType, [$field_name => $definition]);

    // Add the field to all the defined tables to ensure the correct one is     // picked.     foreach ($table_names as $table_name) {
      $table_mapping->setFieldNames($table_name[$field_name]);
    }

    $this->assertEquals($expected$table_mapping->getFieldTableName('test'));
  }

  /** * Provides test data for testGetFieldColumnName(). * * @return array[] * A nested array where each inner array has the following values: a list of * table names and the expected table name. */
  public function providerTestGetFieldTableName() {
    $data = [];

    
// Return early if we already computed this value.     if (isset($this->vocabularyHierarchyType[$vid])) {
      return $this->vocabularyHierarchyType[$vid];
    }

    $parent_field_storage = $this->entityFieldManager->getFieldStorageDefinitions($this->entityTypeId)['parent'];
    $table_mapping = $this->getTableMapping();

    $target_id_column = $table_mapping->getFieldColumnName($parent_field_storage, 'target_id');
    $delta_column = $table_mapping->getFieldColumnName($parent_field_storage, TableMappingInterface::DELTA);

    $query = $this->database->select($table_mapping->getFieldTableName('parent'), 'p');
    $query->addExpression("MAX([$target_id_column])", 'max_parent_id');
    $query->addExpression("MAX([$delta_column])", 'max_delta');
    $query->condition('bundle', $vid);

    $result = $query->execute()->fetchAll();

    // If all the terms have the same parent, the parent can only be root (0).     if ((int) $result[0]->max_parent_id === 0) {
      $this->vocabularyHierarchyType[$vid] = VocabularyInterface::HIERARCHY_DISABLED;
    }
    // If no term has a delta higher than 0, no term has multiple parents.
Home | Imprint | This part of the site doesn't use cookies.