Unverified Commit d4437e28 authored by alexpott's avatar alexpott

Issue #3001800 by Mile23, Berdir, amateescu, larowlan: Fix "The revision_user...

Issue #3001800 by Mile23, Berdir, amateescu, larowlan: Fix "The revision_user revision metadata key is not set." and friends
parent 21ba3dfc
......@@ -88,15 +88,15 @@ public function getRevisionMetadataKeys($include_backwards_compatibility_field_n
if ((!$this->revision_metadata_keys || ($this->revision_metadata_keys == $this->requiredRevisionMetadataKeys)) && $include_backwards_compatibility_field_names) {
$base_fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($this->id());
if ((isset($base_fields['revision_uid']) && $revision_user = 'revision_uid') || (isset($base_fields['revision_user']) && $revision_user = 'revision_user')) {
@trigger_error('The revision_user revision metadata key is not set.', E_USER_DEPRECATED);
@trigger_error('The revision_user revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_user'] = $revision_user;
}
if ((isset($base_fields['revision_timestamp']) && $revision_timestamp = 'revision_timestamp') || (isset($base_fields['revision_created'])) && $revision_timestamp = 'revision_created') {
@trigger_error('The revision_created revision metadata key is not set.', E_USER_DEPRECATED);
@trigger_error('The revision_created revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_created'] = $revision_timestamp;
}
if ((isset($base_fields['revision_log']) && $revision_log = 'revision_log') || (isset($base_fields['revision_log_message']) && $revision_log = 'revision_log_message')) {
@trigger_error('The revision_log_message revision metadata key is not set.', E_USER_DEPRECATED);
@trigger_error('The revision_log_message revision metadata key is not set for entity type: ' . $this->id . ' See: https://www.drupal.org/node/2831499', E_USER_DEPRECATED);
$this->revision_metadata_keys['revision_log_message'] = $revision_log;
}
}
......
......@@ -5,6 +5,7 @@
* Test module for the entity API providing a bundle field.
*/
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\entity_test\FieldStorageDefinition;
......@@ -14,13 +15,23 @@
* Implements hook_entity_type_alter().
*/
function entity_schema_test_entity_type_alter(array &$entity_types) {
// Allow a test to tell us whether or not to alter the entity type.
if (\Drupal::state()->get('entity_schema_update')) {
$entity_type = $entity_types['entity_test'];
$entity_type->set('translatable', TRUE);
$entity_type->set('data_table', 'entity_test_field_data');
$keys = $entity_type->getKeys();
$keys['revision'] = 'revision_id';
$entity_type->set('entity_keys', $keys);
if ($entity_type instanceof ContentEntityTypeInterface) {
$entity_type->set('translatable', TRUE);
$entity_type->set('data_table', 'entity_test_field_data');
// Update the keys with a revision ID.
$keys = $entity_type->getKeys();
$keys['revision'] = 'revision_id';
$entity_type->set('entity_keys', $keys);
// We can't use getRevisionMetadataKeys() because it causes recursion.
$revision_metadata_keys = $entity_type->get('revision_metadata_keys');
$revision_metadata_keys = array_merge($revision_metadata_keys, [
'revision_log_message' => 'revision_log',
]);
$entity_type->set('revision_metadata_keys', $revision_metadata_keys);
}
}
}
......
......@@ -9,6 +9,9 @@
/**
* Tests the upgrade path for moving the revision metadata fields.
*
* This test uses the entity_test_revlog module, which intentionally omits the
* entity_metadata_keys fields. This causes deprecation errors.
*
* @group Update
* @group legacy
*/
......@@ -27,6 +30,10 @@ public function setDatabaseDumpFiles() {
/**
* Tests that the revision metadata fields are moved correctly.
*
* @expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
*/
public function testSystemUpdate8400() {
$this->runUpdates();
......@@ -87,6 +94,10 @@ public function testSystemUpdate8400() {
* This test ensures that already cached entity instances will only return the
* required revision metadata keys they have been cached with and only new
* instances will return all the new required revision metadata keys.
*
* @expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
*/
public function testAddingRequiredRevisionMetadataKeys() {
// Ensure that cached entity types without required revision metadata keys
......@@ -194,6 +205,10 @@ public function testAddingRequiredRevisionMetadataKeys() {
/**
* Tests that the revision metadata key BC layer was updated correctly.
*
* @expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
*/
public function testSystemUpdate8501() {
$this->runUpdates();
......
......@@ -9,8 +9,14 @@
use Drupal\user\UserInterface;
/**
* Test the revision system.
*
* This test uses the entity_test_revlog module, which intentionally omits the
* entity_metadata_keys fields. This causes deprecation errors.
*
* @coversDefaultClass \Drupal\Core\Entity\RevisionableContentEntityBase
* @group Entity
* @group legacy
*/
class RevisionableContentEntityBaseTest extends EntityKernelTestBase {
......@@ -29,6 +35,10 @@ protected function setUp() {
/**
* Tests the correct functionality CRUD operations of entity revisions.
*
* @expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
*/
public function testRevisionableContentEntity() {
$entity_type = 'entity_test_mul_revlog';
......@@ -89,6 +99,10 @@ public function testRevisionableContentEntity() {
* Tests the behavior of the "revision_default" flag.
*
* @covers \Drupal\Core\Entity\ContentEntityBase::wasDefaultRevision
*
* @expectedDeprecation The revision_user revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_created revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
* @expectedDeprecation The revision_log_message revision metadata key is not set for entity type: entity_test_mul_revlog See: https://www.drupal.org/node/2831499
*/
public function testWasDefaultRevision() {
$entity_type_id = 'entity_test_mul_revlog';
......
......@@ -100,9 +100,6 @@ private function willBeIsolated($test) {
public static function getSkippedDeprecations() {
return [
'Install profile will be a mandatory parameter in Drupal 9.0.',
'The revision_user revision metadata key is not set.',
'The revision_created revision metadata key is not set.',
'The revision_log_message revision metadata key is not set.',
'MigrateCckField is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateField instead.',
'MigrateCckFieldPluginManager is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManager instead.',
'MigrateCckFieldPluginManagerInterface is deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.x. Use \Drupal\migrate_drupal\Annotation\MigrateFieldPluginManagerInterface instead.',
......
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