Version 1
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityChangedTrait.php
diff --git a/web/core/lib/Drupal/Core/Entity/EntityChangedTrait.php b/web/core/lib/Drupal/Core/Entity/EntityChangedTrait.php
new file mode 100644 (file)
index 0000000..f94441b
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+namespace Drupal\Core\Entity;
+
+/**
+ * Provides a trait for accessing changed time.
+ */
+trait EntityChangedTrait {
+
+  /**
+   * Returns the timestamp of the last entity change across all translations.
+   *
+   * @return int
+   *   The timestamp of the last entity save operation across all
+   *   translations.
+   */
+  public function getChangedTimeAcrossTranslations() {
+    $changed = $this->getUntranslated()->getChangedTime();
+    foreach ($this->getTranslationLanguages(FALSE) as $language) {
+      $translation_changed = $this->getTranslation($language->getId())->getChangedTime();
+      $changed = max($translation_changed, $changed);
+    }
+    return $changed;
+  }
+
+  /**
+   * Gets the timestamp of the last entity change for the current translation.
+   *
+   * @return int
+   *   The timestamp of the last entity save operation.
+   */
+  public function getChangedTime() {
+    return $this->get('changed')->value;
+  }
+
+  /**
+   * Sets the timestamp of the last entity change for the current translation.
+   *
+   * @param int $timestamp
+   *   The timestamp of the last entity save operation.
+   *
+   * @return $this
+   */
+  public function setChangedTime($timestamp) {
+    $this->set('changed', $timestamp);
+    return $this;
+  }
+
+}