core/lib/Drupal/Core/Entity/ContentEntityBase.php | 5 +++-- core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php | 1 + core/modules/rest/src/Plugin/rest/resource/EntityResource.php | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 575f1a4..10f4f1e 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -158,7 +158,7 @@ protected $loadedRevisionId; /** - * The list of field names of any fields that have changed. + * The list of field names of any fields that have changed, keyed by langcode. * * @var string[] */ @@ -262,6 +262,7 @@ protected function getLanguages() { * {@inheritdoc} */ public function postCreate(EntityStorageInterface $storage) { + // @todo TEST COVERAGE FOR CHANGES IN THIS HUNK if ($this->isDefaultTranslation()) { $this->newRevision = TRUE; } @@ -721,7 +722,7 @@ protected function updateFieldLangcodes($langcode) { * {@inheritdoc} */ public function onChange($name) { - // Add the field to the changed fields list. + // Add the field to the dirty fields list for this translation. $this->dirtyFields[$this->activeLangcode][$name] = TRUE; // Check if the changed name is the value of an entity key and if the value diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 6449470..25804d2 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -135,6 +135,7 @@ public function createTranslation(ContentEntityInterface $entity, $langcode, arr $values[$this->getEntityType()->getKey('default_langcode')] = FALSE; $this->initFieldValues($translation, $values, $field_names); $this->invokeHook('translation_create', $translation); + // @todo TEST COVERAGE FOR CHANGES IN THIS HUNK $translation->postCreate($this); return $translation; } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 5083fcd..16be299 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -7,6 +7,7 @@ use Drupal\Core\Cache\CacheableResponseInterface; use Drupal\Core\Config\Entity\ConfigEntityType; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Entity\EntityWithDirtyFieldsInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; @@ -258,8 +259,9 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity throw new AccessDeniedHttpException($entity_access->getReason() ?: $this->generateFallbackAccessDeniedMessage($entity, 'update')); } - // Overwrite the received properties. - if ($entity instanceof FieldableEntityInterface) { + // Overwrite the fields on the original entity that are dirty on the + // received entity. + if ($entity instanceof EntityWithDirtyFieldsInterface) { $entity_keys = $entity->getEntityType()->getKeys(); foreach ($entity->getDirtyFields() as $field_name => $field) {