Commit 314ea3cb authored by alexpott's avatar alexpott

Issue #2947351 by amateescu, hchonov: DefaultTableMapping does not return the...

Issue #2947351 by amateescu, hchonov: DefaultTableMapping does not return the revision table name for multi-valued base fields
parent 86746fce
......@@ -232,7 +232,9 @@ public function setTranslatable($translatable) {
* {@inheritdoc}
*/
public function isRevisionable() {
return !empty($this->definition['revisionable']);
// Multi-valued base fields are always considered revisionable, just like
// configurable fields.
return !empty($this->definition['revisionable']) || $this->isMultiple();
}
/**
......@@ -263,6 +265,10 @@ public function getCardinality() {
* Possible values are positive integers or
* FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED.
*
* Note that if the entity type that this base field is attached to is
* revisionable and the field has a cardinality higher than 1, the field is
* considered revisionable by default.
*
* @param int $cardinality
* The field cardinality.
*
......
......@@ -97,7 +97,11 @@ public function isTranslatable();
public function setTranslatable($translatable);
/**
* Returns whether the field is revisionable.
* Returns whether the field storage is revisionable.
*
* Note that if the entity type is revisionable and the field storage has a
* cardinality higher than 1, the field storage is considered revisionable
* by default.
*
* @return bool
* TRUE if the field is revisionable.
......
......@@ -19,7 +19,7 @@ class DefaultTableMappingIntegrationTest extends EntityKernelTestBase {
/**
* The table mapping for the tested entity type.
*
* @var \Drupal\Core\Entity\Sql\TableMappingInterface
* @var \Drupal\Core\Entity\Sql\DefaultTableMapping
*/
protected $tableMapping;
......@@ -39,11 +39,18 @@ protected function setUp() {
->setName('multivalued_base_field')
->setTargetEntityTypeId('entity_test_mulrev')
->setTargetBundle('entity_test_mulrev')
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
// Base fields are non-translatable and non-revisionable by default, but
// we explicitly set these values here for extra clarity.
->setTranslatable(FALSE)
->setRevisionable(FALSE);
$this->state->set('entity_test_mulrev.additional_base_field_definitions', $definitions);
$this->entityManager->clearCachedDefinitions();
$this->tableMapping = $this->entityManager->getStorage('entity_test_mulrev')->getTableMapping();
// Ensure that the tables for the new field are created.
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
}
/**
......@@ -68,4 +75,33 @@ public function testGetFieldTableName() {
$this->assertEquals($this->tableMapping->getFieldTableName('multivalued_base_field'), $expected);
}
/**
* Tests DefaultTableMapping::getTableNames().
*
* @covers ::getTableNames
*/
public function testGetTableNames() {
$storage_definitions = $this->entityManager->getFieldStorageDefinitions('entity_test_mulrev');
$dedicated_data_table = $this->tableMapping->getDedicatedDataTableName($storage_definitions['multivalued_base_field']);
$dedicated_revision_table = $this->tableMapping->getDedicatedRevisionTableName($storage_definitions['multivalued_base_field']);
// Check that both the data and the revision tables exist for a multi-valued
// base field.
$database_schema = \Drupal::database()->schema();
$this->assertTrue($database_schema->tableExists($dedicated_data_table));
$this->assertTrue($database_schema->tableExists($dedicated_revision_table));
// Check that the table mapping contains both the data and the revision
// tables exist for a multi-valued base field.
$expected = [
'entity_test_mulrev',
'entity_test_mulrev_property_data',
'entity_test_mulrev_revision',
'entity_test_mulrev_property_revision',
$dedicated_data_table,
$dedicated_revision_table,
];
$this->assertEquals($expected, $this->tableMapping->getTableNames());
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment