Version 1
[yaffs-website] / web / core / modules / system / tests / modules / entity_test / src / Plugin / Field / FieldType / ChangedTestItem.php
1 <?php
2
3 namespace Drupal\entity_test\Plugin\Field\FieldType;
4
5 use Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem;
6
7 /**
8  * Defines the 'changed_test' entity field type.
9  *
10  * Wraps Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem.
11  *
12  * @FieldType(
13  *   id = "changed_test",
14  *   label = @Translation("Last changed"),
15  *   description = @Translation("An entity field containing a UNIX timestamp of when the entity has been last updated."),
16  *   no_ui = TRUE,
17  *   list_class = "\Drupal\Core\Field\ChangedFieldItemList"
18  * )
19  *
20  * @see \Drupal\Core\Entity\EntityChangedInterface
21  */
22 class ChangedTestItem extends ChangedItem {
23
24   /**
25    * {@inheritdoc}
26    */
27   public function preSave() {
28     parent::preSave();
29
30     if ($this->value == REQUEST_TIME) {
31       // During a test the request time is immutable. To allow tests of the
32       // algorithm of
33       // Drupal\Core\Field\Plugin\Field\FieldType\ChangedItem::preSave() we need
34       // to set a real time value here.
35       $this->value = time();
36     }
37   }
38
39 }