annotate core/lib/Drupal/Core/Entity/EntityChangedTrait.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Entity;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Provides a trait for accessing changed time.
Chris@0 7 */
Chris@0 8 trait EntityChangedTrait {
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Returns the timestamp of the last entity change across all translations.
Chris@0 12 *
Chris@0 13 * @return int
Chris@0 14 * The timestamp of the last entity save operation across all
Chris@0 15 * translations.
Chris@0 16 */
Chris@0 17 public function getChangedTimeAcrossTranslations() {
Chris@0 18 $changed = $this->getUntranslated()->getChangedTime();
Chris@0 19 foreach ($this->getTranslationLanguages(FALSE) as $language) {
Chris@0 20 $translation_changed = $this->getTranslation($language->getId())->getChangedTime();
Chris@0 21 $changed = max($translation_changed, $changed);
Chris@0 22 }
Chris@0 23 return $changed;
Chris@0 24 }
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Gets the timestamp of the last entity change for the current translation.
Chris@0 28 *
Chris@0 29 * @return int
Chris@0 30 * The timestamp of the last entity save operation.
Chris@0 31 */
Chris@0 32 public function getChangedTime() {
Chris@0 33 return $this->get('changed')->value;
Chris@0 34 }
Chris@0 35
Chris@0 36 /**
Chris@0 37 * Sets the timestamp of the last entity change for the current translation.
Chris@0 38 *
Chris@0 39 * @param int $timestamp
Chris@0 40 * The timestamp of the last entity save operation.
Chris@0 41 *
Chris@0 42 * @return $this
Chris@0 43 */
Chris@0 44 public function setChangedTime($timestamp) {
Chris@0 45 $this->set('changed', $timestamp);
Chris@0 46 return $this;
Chris@0 47 }
Chris@0 48
Chris@0 49 }