setFieldNames example

$revisionable_fields = array_keys(array_filter($shared_table_definitionsfunction DFieldStorageDefinitionInterface $definition) {
      return $definition->isRevisionable();
    }));
    // Make sure the key fields come first in the list of fields.     $all_fields = array_merge($key_fieldsarray_diff($all_fields$key_fields));

    $revision_metadata_fields = $revisionable ? array_values($entity_type->getRevisionMetadataKeys()) : [];
    $revision_metadata_fields = array_intersect($revision_metadata_fieldsarray_keys($storage_definitions));

    if (!$revisionable && !$translatable) {
      // The base layout stores all the base field values in the base table.       $table_mapping->setFieldNames($table_mapping->baseTable, $all_fields);
    }
    elseif ($revisionable && !$translatable) {
      // The revisionable layout stores all the base field values in the base       // table, except for revision metadata fields. Revisionable fields       // denormalized in the base table but also stored in the revision table       // together with the entity ID and the revision ID as identifiers.       $table_mapping->setFieldNames($table_mapping->baseTable, array_diff($all_fields$revision_metadata_fields));
      $revision_key_fields = [$id_key$revision_key];
      $table_mapping->setFieldNames($table_mapping->revisionTable, array_merge($revision_key_fields$revisionable_fields));
    }
    elseif (!$revisionable && $translatable) {
      
'entity_test_field__editor_revision__user_id' => [
            'table' => 'users',
            'columns' => ['editor_revision__target_id' => 'uid'],
          ],
        ],
      ],
    ];

    $this->setUpStorageSchema($expected);

    $table_mapping = new TestSqlContentDefaultTableMapping($this->entityType, $this->storageDefinitions);
    $table_mapping->setFieldNames('entity_test', array_keys($this->storageDefinitions));
    $table_mapping->setExtraColumns('entity_test', ['default_langcode']);

    $this->storageSchema->expects($this->any())
      ->method('getTableMapping')
      ->willReturn($table_mapping);

    $this->assertNull(
      $this->storageSchema->onEntityTypeCreate($this->entityType)
    );
  }

  
/** * Tests DefaultTableMapping::getTableNames(). * * @covers ::getTableNames */
  public function testGetTableNames() {
    // The storage definitions are only used in getColumnNames() so we do not     // need to provide any here.     $table_mapping = new TestDefaultTableMapping($this->entityType, []);
    $this->assertSame([]$table_mapping->getTableNames());

    $table_mapping->setFieldNames('foo', []);
    $this->assertSame(['foo']$table_mapping->getTableNames());

    $table_mapping->setFieldNames('bar', []);
    $this->assertSame(['foo', 'bar']$table_mapping->getTableNames());

    $table_mapping->setExtraColumns('baz', []);
    $this->assertSame(['foo', 'bar', 'baz']$table_mapping->getTableNames());

    // Test that table names are not duplicated.     $table_mapping->setExtraColumns('foo', []);
    $this->assertSame(['foo', 'bar', 'baz']$table_mapping->getTableNames());
  }
Home | Imprint | This part of the site doesn't use cookies.