getFieldColumnName example

$values[$value_key][$field_name][$langcode] = [];
        }

        // Ensure that records for non-translatable fields having invalid         // languages are skipped.         if ($langcode == LanguageInterface::LANGCODE_DEFAULT || $definitions[$bundle][$field_name]->isTranslatable()) {
          if ($storage_definition->getCardinality() == FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED || count($values[$value_key][$field_name][$langcode]) < $storage_definition->getCardinality()) {
            $item = [];
            // For each column declared by the field, populate the item from the             // prefixed database column.             foreach ($storage_definition->getColumns() as $column => $attributes) {
              $column_name = $table_mapping->getFieldColumnName($storage_definition$column);
              // Unserialize the value if specified in the column schema.               $item[$column] = (!empty($attributes['serialize'])) ? unserialize($row->$column_name) : $row->$column_name;
            }

            // Add the item to the field values for the entity.             $values[$value_key][$field_name][$langcode][] = $item;
          }
        }
      }
    }
  }

  

  public function getVocabularyHierarchyType($vid) {
    // 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) {
      
// The field still exists, deleted.     $fields = \Drupal::entityTypeManager()->getStorage('field_config')->loadByProperties(['field_storage_uuid' => $field_storage->uuid(), 'deleted' => TRUE, 'include_deleted' => TRUE]);
    $this->assertCount(1, $fields, 'There is one deleted field');
    $field = $fields[$field->uuid()];
    $this->assertEquals($bundle$field->getTargetBundle(), 'The deleted field is for the correct bundle');

    // Check that the actual stored content did not change during delete.     /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
    $table_mapping = $storage->getTableMapping();
    $table = $table_mapping->getDedicatedDataTableName($field_storage);
    $column = $table_mapping->getFieldColumnName($field_storage, 'value');
    $result = Database::getConnection()->select($table, 't')
      ->fields('t')
      ->execute();
    foreach ($result as $row) {
      $this->assertEquals($row->{$column}$this->entities[$row->entity_id]->{$field_name}->value);
    }

    // There are 0 entities of this bundle with non-deleted data.     $found = $storage
      ->getQuery()
      ->accessCheck(FALSE)
      
          // property definitions for the relationship. In the first case,           // also use the property definitions for column.           if ($key < $count) {
            $relationship_specifier = $specifiers[$key + 1];
            $propertyDefinitions = $field_storage->getPropertyDefinitions();

            // Prepare the next index prefix.             $next_index_prefix = "$relationship_specifier.$column";
          }
        }
        $table = $this->ensureFieldTable($index_prefix$field_storage$type$langcode$base_table$entity_id_field$field_id_field$delta);
        $sql_column = $table_mapping->getFieldColumnName($field_storage$column);
      }
      // The field is stored in a shared table.       else {
        // ensureEntityTable() decides whether an entity property will be         // queried from the data table or the base table based on where it         // finds the property first. The data table is preferred, which is why         // it gets added before the base table.         $entity_tables = [];
        $revision_table = NULL;
        if ($query_revisions) {
          $data_table = $entity_type->getRevisionDataTable();
          
/** * {@inheritdoc} */
  public function clickSort($order) {
    $this->ensureMyTable();

    // This could be derived from the content_moderation_state entity table     // mapping, however this is an internal entity type whose storage should     // remain constant.     $storage = $this->entityTypeManager->getStorage('content_moderation_state');
    $storage_definition = $this->entityFieldManager->getActiveFieldStorageDefinitions('content_moderation_state')['moderation_state'];
    $column_name = $storage->getTableMapping()->getFieldColumnName($storage_definition, 'value');
    $this->aliases[$column_name] = $this->tableAlias . '.' . $column_name;

    $this->query->addOrderBy(NULL, NULL, $order$this->aliases[$column_name]);
  }

}
$this->table = $table_mapping->getDedicatedDataTableName($this->fieldStorage);
    $this->revisionTable = $table_mapping->getDedicatedRevisionTableName($this->fieldStorage);
  }

  /** * Tests field loading works correctly by inserting directly in the tables. */
  public function testFieldLoad() {
    $entity_type = $bundle = 'entity_test_rev';
    $storage = $this->container->get('entity_type.manager')->getStorage($entity_type);

    $columns = ['bundle', 'deleted', 'entity_id', 'revision_id', 'delta', 'langcode', $this->tableMapping->getFieldColumnName($this->fieldStorage, 'value')];

    // Create an entity with four revisions.     $revision_ids = [];
    $entity = $this->container->get('entity_type.manager')
      ->getStorage($entity_type)
      ->create();
    $entity->save();
    $revision_ids[] = $entity->getRevisionId();
    for ($i = 0; $i < 4; $i++) {
      $entity->setNewRevision();
      $entity->save();
      
    // increase the performance of the query from     // \Drupal\taxonomy\TermStorage::getVocabularyHierarchyType().     if ($storage_definition->getName() === 'parent') {
      /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping $table_mapping */
      $table_mapping = $this->storage->getTableMapping();
      $dedicated_table_name = $table_mapping->getDedicatedDataTableName($storage_definition);

      unset($dedicated_table_schema[$dedicated_table_name]['indexes']['bundle']);
      $dedicated_table_schema[$dedicated_table_name]['indexes']['bundle_delta_target_id'] = [
        'bundle',
        'delta',
        $table_mapping->getFieldColumnName($storage_definition, 'target_id'),
      ];
    }

    return $dedicated_table_schema;
  }

}
if ($this->options['group_column'] != 'entity_id') {
        $options = [$this->options['group_column'] => $this->options['group_column']];
      }
      $options += is_array($this->options['group_columns']) ? $this->options['group_columns'] : [];

      // Go through the list and determine the actual column name from field api.       $fields = [];
      $table_mapping = $this->getTableMapping();
      $field_definition = $this->getFieldStorageDefinition();

      foreach ($options as $column) {
        $fields[$column] = $table_mapping->getFieldColumnName($field_definition$column);
      }

      $this->group_fields = $fields;
    }

    // Add additional fields (and the table join itself) if needed.     if ($this->add_field_table($use_groupby)) {
      $this->ensureMyTable();
      $this->addAdditionalFields($fields);
    }

    
$table = $table_mapping->getDedicatedDataTableName($storage_definition);
      $revision_table = $table_mapping->getDedicatedRevisionTableName($storage_definition);
      foreach ($schema['indexes'] as $name => $columns) {
        if (!isset($original_schema['indexes'][$name]) || $columns != $original_schema['indexes'][$name]) {
          $real_name = $this->getFieldIndexName($storage_definition$name);
          $real_columns = [];
          foreach ($columns as $column_name) {
            // Indexes can be specified as either a column name or an array with             // column name and length. Allow for either case.             if (is_array($column_name)) {
              $real_columns[] = [
                $table_mapping->getFieldColumnName($storage_definition$column_name[0]),
                $column_name[1],
              ];
            }
            else {
              $real_columns[] = $table_mapping->getFieldColumnName($storage_definition$column_name);
            }
          }
          // Check if the index exists because it might already have been           // created as part of the earlier entity type update event.           $this->addIndex($table$real_name$real_columns$actual_schema[$table]);
          $this->addIndex($revision_table$real_name$real_columns$actual_schema[$revision_table]);
        }

  public function testGetFieldColumnName($base_field$columns$column$expected) {
    $definitions['test'] = $this->setUpDefinition('test', $columns$base_field);
    $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);
    $result = $table_mapping->getFieldColumnName($definitions['test']$column);
    $this->assertEquals($expected$result);
  }

  /** * Tests DefaultTableMapping::getFieldColumnName() with invalid parameters. * * @param bool $base_field * Flag indicating whether the field should be treated as a base or bundle * field. * @param string[] $columns * An array of available field column names. * @param string $column * The name of the column to be processed. * * @covers ::getFieldColumnName * * @dataProvider providerTestGetFieldColumnName */
      $storage_definition = $this->fieldStorageDefinitions[$field_name];
      $table_names = array_filter([
        $this->dataTable,
        $this->baseTable,
        $this->revisionTable,
        $this->getDedicatedDataTableName($storage_definition),
      ]);

      // Collect field columns.       $field_columns = [];
      foreach (array_keys($storage_definition->getColumns()) as $property_name) {
        $field_columns[] = $this->getFieldColumnName($storage_definition$property_name);
      }

      foreach ($table_names as $table_name) {
        $columns = $this->getAllColumns($table_name);
        // We assume finding one field column belonging to the mapping is enough         // to identify the field table.         if (array_intersect($columns$field_columns)) {
          $result = $table_name;
          break;
        }
      }
    }
Home | Imprint | This part of the site doesn't use cookies.