RevisionableInterface.php 3.3 KB

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