comparison core/lib/Drupal/Core/Entity/EntityChangedTrait.php @ 0:4c8ae668cc8c

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