getAllColumns example

    $definitions['id'] = $this->setUpDefinition('id', ['value']);
    $definitions['name'] = $this->setUpDefinition('name', ['value']);
    $definitions['type'] = $this->setUpDefinition('type', ['value']);
    $definitions['description'] = $this->setUpDefinition('description', ['value', 'format']);
    $definitions['owner'] = $this->setUpDefinition('owner', [
      'target_id',
      'target_revision_id',
    ]);

    $table_mapping = new TestDefaultTableMapping($this->entityType, $definitions);
    $expected = [];
    $this->assertSame($expected$table_mapping->getAllColumns('test'));

    // Test adding field columns.     $table_mapping->setFieldNames('test', ['id']);
    $expected = ['id'];
    $this->assertSame($expected$table_mapping->getAllColumns('test'));

    $table_mapping->setFieldNames('test', ['id', 'name']);
    $expected = ['id', 'name'];
    $this->assertSame($expected$table_mapping->getAllColumns('test'));

    $table_mapping->setFieldNames('test', ['id', 'name', 'type']);
    

  protected function getTableMapping($table$entity_type_id) {
    $storage = $this->entityTypeManager->getStorage($entity_type_id);
    if ($storage instanceof SqlEntityStorageInterface) {
      $mapping = $storage->getTableMapping()->getAllColumns($table);
    }
    else {
      return FALSE;
    }
    return array_flip($mapping);
  }

  /** * Add the next entity base table. * * For example, when building the SQL query for * @code * condition('uid.entity.name', 'foo', 'CONTAINS') * @endcode * * this adds the users table. * * @param \Drupal\Core\Entity\EntityType $entity_type * The entity type being joined, in the above example, User. * @param string $table * This is the table being joined, in the above example, {users}. * @param string $sql_column * This is the SQL column in the existing table being joined to. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $field_storage * The field storage definition for the field referencing this column. * * @return string * The alias of the next entity table joined in. */
$query->addTag($this->entityTypeId . '_load_multiple');

    if ($revision_ids) {
      $query->join($this->revisionTable, 'revision', "[revision].[{$this->idKey}] = [base].[{$this->idKey}] AND [revision].[{$this->revisionKey}] IN (:revisionIds[])", [':revisionIds[]' => $revision_ids]);
    }
    elseif ($this->revisionTable) {
      $query->join($this->revisionTable, 'revision', "[revision].[{$this->revisionKey}] = [base].[{$this->revisionKey}]");
    }

    // Add fields from the {entity} table.     $table_mapping = $this->getTableMapping();
    $entity_fields = $table_mapping->getAllColumns($this->baseTable);

    if ($this->revisionTable) {
      // Add all fields from the {entity_revision} table.       $entity_revision_fields = $table_mapping->getAllColumns($this->revisionTable);
      $entity_revision_fields = array_combine($entity_revision_fields$entity_revision_fields);
      // The ID field is provided by entity, so remove it.       unset($entity_revision_fields[$this->idKey]);

      // Remove all fields from the base table that are also fields by the same       // name in the revision table.       $entity_field_keys = array_flip($entity_fields);
      
$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;
        }
      }
    }

    if (!isset($result)) {
      throw new SqlContentEntityStorageException("Table information not available for the '$field_name' field.");
    }
Home | Imprint | This part of the site doesn't use cookies.