Issue #3055363 by hoanns, yogeshmpawar, alexpott, borisson_: EntityDefinitionUpdateManager: Show field_name when field has no label

merge-requests/2419/head
Alex Pott 2019-11-15 09:35:00 +00:00
parent 3637ce2d0b
commit f66921a662
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
3 changed files with 67 additions and 54 deletions

View File

@ -109,15 +109,15 @@ class EntityDefinitionUpdateManager implements EntityDefinitionUpdateManagerInte
foreach ($change_list['field_storage_definitions'] as $field_name => $change) {
switch ($change) {
case static::DEFINITION_CREATED:
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be installed.', ['%field_name' => $storage_definitions[$field_name]->getLabel()]);
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be installed.', ['%field_name' => $storage_definitions[$field_name]->getLabel() ?: $field_name]);
break;
case static::DEFINITION_UPDATED:
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be updated.', ['%field_name' => $storage_definitions[$field_name]->getLabel()]);
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be updated.', ['%field_name' => $storage_definitions[$field_name]->getLabel() ?: $field_name]);
break;
case static::DEFINITION_DELETED:
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be uninstalled.', ['%field_name' => $original_storage_definitions[$field_name]->getLabel()]);
$summary[$entity_type_id][] = $this->t('The %field_name field needs to be uninstalled.', ['%field_name' => $original_storage_definitions[$field_name]->getLabel() ?: $field_name]);
break;
}
}

View File

@ -227,12 +227,19 @@ trait EntityDefinitionTestTrait {
* @param bool $is_revisionable
* (optional) If the base field should be revisionable or not. Defaults to
* FALSE.
* @param bool $set_label
* (optional) If the base field should have a label or not. Defaults to
* TRUE.
*/
protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE) {
protected function addBaseField($type = 'string', $entity_type_id = 'entity_test_update', $is_revisionable = FALSE, $set_label = TRUE) {
$definitions['new_base_field'] = BaseFieldDefinition::create($type)
->setName('new_base_field')
->setRevisionable($is_revisionable)
->setLabel(t('A new base field'));
->setRevisionable($is_revisionable);
if ($set_label) {
$definitions['new_base_field']->setLabel(t('A new base field'));
}
$this->state->set($entity_type_id . '.additional_base_field_definitions', $definitions);
}

View File

@ -255,12 +255,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// creates its schema.
$this->addBaseField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be installed.', ['%field_name' => t('A new base field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new base field field needs to be installed.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Column created in shared table for new_base_field.');
@ -268,12 +265,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// and the update creates it.
$this->addBaseFieldIndex();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be updated.', ['%field_name' => t('A new base field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index created.');
@ -281,12 +275,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// update deletes it.
$this->removeBaseFieldIndex();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be updated.', ['%field_name' => t('A new base field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertFalse($this->database->schema()->indexExists('entity_test_update', 'entity_test_update_field__new_base_field'), 'Index deleted.');
@ -295,12 +286,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// accordingly.
$this->modifyBaseField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be updated.', ['%field_name' => t('A new base field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new base field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field'), 'Original column deleted in shared table for new_base_field.');
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update', 'new_base_field__value'), 'Value column created in shared table for new_base_field.');
@ -310,17 +298,44 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// update deletes the schema.
$this->removeBaseField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be uninstalled.', ['%field_name' => t('A new base field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new base field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_value'), 'Value column deleted from shared table for new_base_field.');
$this->assertFalse($this->database->schema()->fieldExists('entity_test_update', 'new_base_field_format'), 'Format column deleted from shared table for new_base_field.');
}
/**
* Tests creating, updating, and deleting a base field with no label set
*
* See testBaseFieldCreateUpdateDeleteWithoutData() for more details
*/
public function testBaseFieldWithoutLabelCreateUpdateDelete() {
// Add a base field, ensure the update manager reports it with the
// field id.
$this->addBaseField('string', 'entity_test_update', FALSE, FALSE);
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The new_base_field field needs to be installed.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
// Add an index on the base field, ensure the update manager reports it with
// the field id.
$this->addBaseFieldIndex();
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The new_base_field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
// Remove the base field, ensure the update manager reports it with the
// field id.
$this->removeBaseField();
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The new_base_field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0]));
}
/**
* Tests creating, updating, and deleting a bundle field if no entities exist.
*/
@ -329,12 +344,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// creates its schema.
$this->addBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be installed.', ['%field_name' => t('A new bundle field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be installed.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table created for new_bundle_field.');
@ -343,12 +355,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// accordingly.
$this->modifyBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be updated.', ['%field_name' => t('A new bundle field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be updated.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertTrue($this->database->schema()->fieldExists('entity_test_update__new_bundle_field', 'new_bundle_field_format'), 'Format column created in dedicated table for new_base_field.');
@ -356,12 +365,9 @@ class EntityDefinitionUpdateTest extends EntityKernelTestBase {
// update deletes the schema.
$this->removeBundleField();
$this->assertTrue($this->entityDefinitionUpdateManager->needsUpdates(), 'EntityDefinitionUpdateManager reports that updates are needed.');
$expected = [
'entity_test_update' => [
t('The %field_name field needs to be uninstalled.', ['%field_name' => t('A new bundle field')]),
],
];
$this->assertEqual($this->entityDefinitionUpdateManager->getChangeSummary(), $expected, 'EntityDefinitionUpdateManager reports the expected change summary.');
$changes = $this->entityDefinitionUpdateManager->getChangeSummary();
$this->assertCount(1, $changes['entity_test_update']);
$this->assertEquals('The A new bundle field field needs to be uninstalled.', strip_tags($changes['entity_test_update'][0]));
$this->applyEntityUpdates();
$this->assertFalse($this->database->schema()->tableExists('entity_test_update__new_bundle_field'), 'Dedicated table deleted for new_bundle_field.');
}