ee53e398f054a9952b215116454d3b825892ccfa
[yaffs-website] / web / core / lib / Drupal / Core / Entity / RevisionableInterface.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 /**
6  * Provides methods for an entity to support revisions.
7  *
8  * Classes implementing this interface do not necessarily support revisions.
9  *
10  * To detect whether an entity type supports revisions, call
11  * EntityTypeInterface::isRevisionable().
12  *
13  * Many entity interfaces are composed of numerous other interfaces such as this
14  * one, which allow implementations to pick and choose which features to.
15  * support through stub implementations of various interface methods. This means
16  * that even if an entity class implements RevisionableInterface, it might only
17  * have a stub implementation and not a functional one.
18  *
19  * @see \Drupal\Core\Entity\EntityTypeInterface::isRevisionable()
20  * @see https://www.drupal.org/docs/8/api/entity-api/structure-of-an-entity-annotation
21  * @see https://www.drupal.org/docs/8/api/entity-api/making-an-entity-revisionable
22  */
23 interface RevisionableInterface {
24
25   /**
26    * Determines whether a new revision should be created on save.
27    *
28    * @return bool
29    *   TRUE if a new revision should be created.
30    *
31    * @see \Drupal\Core\Entity\EntityInterface::setNewRevision()
32    */
33   public function isNewRevision();
34
35   /**
36    * Enforces an entity to be saved as a new revision.
37    *
38    * @param bool $value
39    *   (optional) Whether a new revision should be saved.
40    *
41    * @throws \LogicException
42    *   Thrown if the entity does not support revisions.
43    *
44    * @see \Drupal\Core\Entity\EntityInterface::isNewRevision()
45    */
46   public function setNewRevision($value = TRUE);
47
48   /**
49    * Gets the revision identifier of the entity.
50    *
51    * @return
52    *   The revision identifier of the entity, or NULL if the entity does not
53    *   have a revision identifier.
54    */
55   public function getRevisionId();
56
57   /**
58    * Gets the loaded Revision ID of the entity.
59    *
60    * @return int
61    *   The loaded Revision identifier of the entity, or NULL if the entity
62    *   does not have a revision identifier.
63    */
64   public function getLoadedRevisionId();
65
66   /**
67    * Updates the loaded Revision ID with the revision ID.
68    *
69    * This method should not be used, it could unintentionally cause the original
70    * revision ID property value to be lost.
71    *
72    * @internal
73    *
74    * @return $this
75    */
76   public function updateLoadedRevisionId();
77
78   /**
79    * Checks if this entity is the default revision.
80    *
81    * @param bool $new_value
82    *   (optional) A Boolean to (re)set the isDefaultRevision flag.
83    *
84    * @return bool
85    *   TRUE if the entity is the default revision, FALSE otherwise. If
86    *   $new_value was passed, the previous value is returned.
87    */
88   public function isDefaultRevision($new_value = NULL);
89
90   /**
91    * Checks whether the entity object was a default revision when it was saved.
92    *
93    * @return bool
94    *   TRUE if the entity object was a revision, FALSE otherwise.
95    */
96   public function wasDefaultRevision();
97
98   /**
99    * Checks if this entity is the latest revision.
100    *
101    * @return bool
102    *   TRUE if the entity is the latest revision, FALSE otherwise.
103    */
104   public function isLatestRevision();
105
106   /**
107    * Acts on a revision before it gets saved.
108    *
109    * @param EntityStorageInterface $storage
110    *   The entity storage object.
111    * @param \stdClass $record
112    *   The revision object.
113    */
114   public function preSaveRevision(EntityStorageInterface $storage, \stdClass $record);
115
116 }