Issue #2955442 by amateescu, plach, jibran, Berdir: Add a way to get all the tables in which a field is stored from TableMappingInterface
parent
63c85acafa
commit
329a3d9d9c
|
@ -394,6 +394,15 @@ class DefaultTableMapping implements TableMappingInterface {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getAllFieldTableNames($field_name) {
|
||||
return array_keys(array_filter($this->fieldNames, function ($table_fields) use ($field_name) {
|
||||
return in_array($field_name, $table_fields, TRUE);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
|
|
|
@ -120,4 +120,26 @@ interface TableMappingInterface {
|
|||
*/
|
||||
public function getFieldTableName($field_name);
|
||||
|
||||
/**
|
||||
* Gets all the table names in which an entity field is stored.
|
||||
*
|
||||
* The returned table names are ordered by the amount of data stored in each
|
||||
* table. For example, a revisionable and translatable entity type which uses
|
||||
* core's default table mapping strategy would return the table names for the
|
||||
* entity ID field in the following order:
|
||||
* - base table
|
||||
* - data table
|
||||
* - revision table
|
||||
* - revision data table
|
||||
*
|
||||
* @param string $field_name
|
||||
* The name of the entity field to return the tables names for.
|
||||
*
|
||||
* @return string[]
|
||||
* An array of table names in which the given field is stored.
|
||||
*
|
||||
* @throws \Drupal\Core\Entity\Sql\SqlContentEntityStorageException
|
||||
*/
|
||||
public function getAllFieldTableNames($field_name);
|
||||
|
||||
}
|
||||
|
|
|
@ -77,6 +77,43 @@ class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
|
|||
$this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field'), $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAllFieldTableNames
|
||||
*/
|
||||
public function testGetAllFieldTableNames() {
|
||||
// Check a field that is stored in all the shared tables.
|
||||
$expected = [
|
||||
'entity_test_mulrev',
|
||||
'entity_test_mulrev_property_data',
|
||||
'entity_test_mulrev_revision',
|
||||
'entity_test_mulrev_property_revision',
|
||||
];
|
||||
$this->assertEquals($expected, $this->tableMapping->getAllFieldTableNames('id'));
|
||||
|
||||
// Check a field that is stored only in the base table.
|
||||
$expected = ['entity_test_mulrev'];
|
||||
$this->assertEquals($expected, $this->tableMapping->getAllFieldTableNames('uuid'));
|
||||
|
||||
// Check a field that is stored only in the revision table.
|
||||
$expected = ['entity_test_mulrev_revision'];
|
||||
$this->assertEquals($expected, $this->tableMapping->getAllFieldTableNames('revision_default'));
|
||||
|
||||
// Check a field that field that is stored in the data and revision data
|
||||
// tables.
|
||||
$expected = [
|
||||
'entity_test_mulrev_property_data',
|
||||
'entity_test_mulrev_property_revision',
|
||||
];
|
||||
$this->assertEquals($expected, $this->tableMapping->getAllFieldTableNames('name'));
|
||||
|
||||
// Check a field that is stored in dedicated data and revision data tables.
|
||||
$expected = [
|
||||
'entity_test_mulrev__multivalued_base_field',
|
||||
'entity_test_mulrev_r__f86e511394',
|
||||
];
|
||||
$this->assertEquals($expected, $this->tableMapping->getAllFieldTableNames('multivalued_base_field'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests DefaultTableMapping::getTableNames().
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue