Skip to content
Snippets Groups Projects

Issue #2329253 by kksandr: Allow the ChangedItem to skip updating the entitys...

Closed Issue #2329253 by kksandr: Allow the ChangedItem to skip updating the entitys...
All threads resolved!
Closed kksandr requested to merge issue/drupal-2329253:2329253-changeditem-sync into 11.x
All threads resolved!
2 files
+ 33
7
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -5,6 +5,7 @@
use Drupal\Core\Field\Attribute\FieldType;
use Drupal\Core\Field\ChangedFieldItemList;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Entity\SynchronizableInterface;
/**
* Defines the 'changed' entity field type.
@@ -44,13 +45,15 @@ public function preSave() {
// \Drupal\content_translation\ContentTranslationMetadataWrapperInterface::setChangedTime().
/** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
$entity = $this->getEntity();
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
$original = $entity->original;
$langcode = $entity->language()->getId();
if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) {
$original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value;
if ($this->value == $original_value && $entity->hasTranslationChanges()) {
$this->value = \Drupal::time()->getRequestTime();
if (!$entity instanceof SynchronizableInterface || !$entity->isSyncing()) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
$original = $entity->original;
$langcode = $entity->language()->getId();
if (!$entity->isNew() && $original && $original->hasTranslation($langcode)) {
$original_value = $original->getTranslation($langcode)->get($this->getFieldDefinition()->getName())->value;
if ($this->value == $original_value && $entity->hasTranslationChanges()) {
$this->value = \Drupal::time()->getRequestTime();
}
}
}
}
Loading