Created
January 16, 2018 22:35
-
-
Save Berdir/410dc15cc4ff06aa2675503c7d500fa6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/lib/Drupal/Core/Entity/ContentEntityType.php b/core/lib/Drupal/Core/Entity/ContentEntityType.php | |
index 5be34c9ba5..145350e037 100644 | |
--- a/core/lib/Drupal/Core/Entity/ContentEntityType.php | |
+++ b/core/lib/Drupal/Core/Entity/ContentEntityType.php | |
@@ -25,8 +25,11 @@ public function __construct($definition) { | |
'view_builder' => 'Drupal\Core\Entity\EntityViewBuilder', | |
]; | |
+ // Only new instances should provide the default revision metadata keys. | |
+ // The stored instances should return only what already has been stored | |
+ // under the property $revision_metadata_keys. | |
$this->revision_metadata_keys += [ | |
- 'revision_default' => 'revision_default', | |
+ 'revision_default' => 'revision_default' | |
]; | |
} | |
@@ -59,7 +62,10 @@ protected function checkStorageClass($class) { | |
public function getRevisionMetadataKeys($include_backwards_compatibility_field_names = TRUE) { | |
// Provide backwards compatibility in case the revision metadata keys are | |
// not defined in the entity annotation. | |
- if (!$this->revision_metadata_keys && $include_backwards_compatibility_field_names) { | |
+ $required_revision_metadata_keys = [ | |
+ 'revision_default' => 'revision_default' | |
+ ]; | |
+ if ((!$this->revision_metadata_keys || ($this->revision_metadata_keys === $required_revision_metadata_keys)) && $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); | |
diff --git a/core/lib/Drupal/Core/Entity/EntityFieldManager.php b/core/lib/Drupal/Core/Entity/EntityFieldManager.php | |
index c19956491d..025d92cca1 100644 | |
--- a/core/lib/Drupal/Core/Entity/EntityFieldManager.php | |
+++ b/core/lib/Drupal/Core/Entity/EntityFieldManager.php | |
@@ -224,7 +224,9 @@ protected function buildBaseFieldDefinitions($entity_type_id) { | |
// Make sure that revisionable entity types are correctly defined. | |
if ($entity_type->isRevisionable()) { | |
- $field_name = $entity_type->getRevisionMetadataKey('revision_default'); | |
+ // Disable the BC layer to prevent a recursion, this only needs the | |
+ // revision_default key that is always set. | |
+ $field_name = $entity_type->getRevisionMetadataKeys(FALSE)['revision_default']; | |
$base_field_definitions[$field_name] = BaseFieldDefinition::create('boolean') | |
->setLabel($this->t('Default revision')) | |
->setDescription($this->t('A flag indicating whether this was a default revision when it was saved.')) | |
diff --git a/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php | |
index 5a17b858dc..cb9c7bbc0c 100644 | |
--- a/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php | |
+++ b/core/modules/system/tests/modules/entity_test_revlog/src/Entity/EntityTestMulWithRevisionLog.php | |
@@ -5,6 +5,9 @@ | |
/** | |
* Defines the test entity class. | |
* | |
+ * This entity type does not define revision_metadata_keys on purpose to test | |
+ * the BC layer. | |
+ * | |
* @ContentEntityType( | |
* id = "entity_test_mul_revlog", | |
* label = @Translation("Test entity - data table, revisions log"), | |
@@ -21,11 +24,6 @@ | |
* "label" = "name", | |
* "langcode" = "langcode", | |
* }, | |
- * revision_metadata_keys = { | |
- * "revision_user" = "revision_user", | |
- * "revision_created" = "revision_created", | |
- * "revision_log_message" = "revision_log_message" | |
- * }, | |
* ) | |
*/ | |
class EntityTestMulWithRevisionLog extends EntityTestWithRevisionLog { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment