EntityLastInstalledSchemaRepositoryInterface.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. use Drupal\Core\Field\FieldStorageDefinitionInterface;
  4. /**
  5. * Provides an interface for an installed entity definition repository.
  6. */
  7. interface EntityLastInstalledSchemaRepositoryInterface {
  8. /**
  9. * Gets the entity type definition in its most recently installed state.
  10. *
  11. * During the application lifetime, entity type definitions can change. For
  12. * example, updated code can be deployed. The getDefinition() method will
  13. * always return the definition as determined by the current codebase. This
  14. * method, however, returns what the definition was when the last time that
  15. * one of the \Drupal\Core\Entity\EntityTypeListenerInterface events was last
  16. * fired and completed successfully. In other words, the definition that
  17. * the entity type's handlers have incorporated into the application state.
  18. * For example, if the entity type's storage handler is SQL-based, the
  19. * definition for which database tables were created.
  20. *
  21. * Application management code can check if getDefinition() differs from
  22. * getLastInstalledDefinition() and decide whether to:
  23. * - Invoke the appropriate \Drupal\Core\Entity\EntityTypeListenerInterface
  24. * event so that handlers react to the new definition.
  25. * - Raise a warning that the application state is incompatible with the
  26. * codebase.
  27. * - Perform some other action.
  28. *
  29. * @param string $entity_type_id
  30. * The entity type ID.
  31. *
  32. * @return \Drupal\Core\Entity\EntityTypeInterface|null
  33. * The installed entity type definition, or NULL if the entity type has
  34. * not yet been installed via onEntityTypeCreate().
  35. *
  36. * @see \Drupal\Core\Entity\EntityTypeListenerInterface
  37. */
  38. public function getLastInstalledDefinition($entity_type_id);
  39. /**
  40. * Stores the entity type definition in the application state.
  41. *
  42. * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
  43. * The entity type definition.
  44. *
  45. * @return $this
  46. */
  47. public function setLastInstalledDefinition(EntityTypeInterface $entity_type);
  48. /**
  49. * Deletes the entity type definition from the application state.
  50. *
  51. * @param string $entity_type_id
  52. * The entity type definition identifier.
  53. *
  54. * @return $this
  55. */
  56. public function deleteLastInstalledDefinition($entity_type_id);
  57. /**
  58. * Gets the entity type's most recently installed field storage definitions.
  59. *
  60. * During the application lifetime, field storage definitions can change. For
  61. * example, updated code can be deployed. The getFieldStorageDefinitions()
  62. * method will always return the definitions as determined by the current
  63. * codebase. This method, however, returns what the definitions were when the
  64. * last time that one of the
  65. * \Drupal\Core\Field\FieldStorageDefinitionListenerInterface events was last
  66. * fired and completed successfully. In other words, the definitions that
  67. * the entity type's handlers have incorporated into the application state.
  68. * For example, if the entity type's storage handler is SQL-based, the
  69. * definitions for which database tables were created.
  70. *
  71. * Application management code can check if getFieldStorageDefinitions()
  72. * differs from getLastInstalledFieldStorageDefinitions() and decide whether
  73. * to:
  74. * - Invoke the appropriate
  75. * \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
  76. * events so that handlers react to the new definitions.
  77. * - Raise a warning that the application state is incompatible with the
  78. * codebase.
  79. * - Perform some other action.
  80. *
  81. * @param string $entity_type_id
  82. * The entity type ID.
  83. *
  84. * @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
  85. * The array of installed field storage definitions for the entity type,
  86. * keyed by field name.
  87. *
  88. * @see \Drupal\Core\Entity\EntityTypeListenerInterface
  89. */
  90. public function getLastInstalledFieldStorageDefinitions($entity_type_id);
  91. /**
  92. * Stores the entity type's field storage definitions in the application state.
  93. *
  94. * @param string $entity_type_id
  95. * The entity type identifier.
  96. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $storage_definitions
  97. * An array of field storage definitions.
  98. */
  99. public function setLastInstalledFieldStorageDefinitions($entity_type_id, array $storage_definitions);
  100. /**
  101. * Stores the field storage definition in the application state.
  102. *
  103. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  104. * The field storage definition.
  105. */
  106. public function setLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
  107. /**
  108. * Deletes the field storage definition from the application state.
  109. *
  110. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  111. * The field storage definition.
  112. */
  113. public function deleteLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
  114. }