DynamicallyFieldableEntityStorageSchemaInterface.php 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Drupal\Core\Entity\Schema;
  3. use Drupal\Core\Field\FieldStorageDefinitionInterface;
  4. use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
  5. /**
  6. * A storage schema that supports entity types with dynamic field definitions.
  7. *
  8. * A storage schema that implements this interface can react to the entity
  9. * type's field definitions changing, due to modules being installed or
  10. * uninstalled, or via field UI, or via code changes to the entity class.
  11. *
  12. * For example, configurable fields defined and exposed by field.module.
  13. */
  14. interface DynamicallyFieldableEntityStorageSchemaInterface extends EntityStorageSchemaInterface, FieldStorageDefinitionListenerInterface {
  15. /**
  16. * Checks if the changes to the storage definition requires schema changes.
  17. *
  18. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  19. * The updated field storage definition.
  20. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $original
  21. * The original field storage definition.
  22. *
  23. * @return bool
  24. * TRUE if storage schema changes are required, FALSE otherwise.
  25. */
  26. public function requiresFieldStorageSchemaChanges(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original);
  27. /**
  28. * Checks if existing data would be lost if the schema changes were applied.
  29. *
  30. * If there are no schema changes needed, then no data needs to be migrated,
  31. * but it is not the responsibility of this function to recheck what
  32. * requiresFieldStorageSchemaChanges() checks. Rather, the meaning of what
  33. * this function returns when requiresFieldStorageSchemaChanges() returns
  34. * FALSE is undefined. Callers are expected to only call this function when
  35. * requiresFieldStorageSchemaChanges() is TRUE.
  36. *
  37. * This function can return FALSE if any of these conditions apply:
  38. * - There are no existing entities for the entity type to which this field
  39. * is attached.
  40. * - There are existing entities, but none with existing values for this
  41. * field.
  42. * - There are existing field values, but the schema changes can be applied
  43. * without losing them (e.g., if the schema changes can be performed by
  44. * altering tables rather than dropping and recreating them).
  45. * - The only field values that would be lost are ones that are not valid for
  46. * the new definition (e.g., if changing a field from revisionable to
  47. * non-revisionable, then it's okay to drop data for the non-default
  48. * revision).
  49. *
  50. * When this function returns FALSE, site administrators will be unable to
  51. * perform an automated update, and will instead need to perform a site
  52. * migration or invoke some custom update process.
  53. *
  54. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  55. * The updated field storage definition.
  56. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $original
  57. * The original field storage definition.
  58. *
  59. * @return bool
  60. * TRUE if data migration is required, FALSE otherwise.
  61. *
  62. * @see self::requiresFieldStorageSchemaChanges()
  63. */
  64. public function requiresFieldDataMigration(FieldStorageDefinitionInterface $storage_definition, FieldStorageDefinitionInterface $original);
  65. /**
  66. * Performs final cleanup after all data of a field has been purged.
  67. *
  68. * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
  69. * The field being purged.
  70. */
  71. public function finalizePurge(FieldStorageDefinitionInterface $storage_definition);
  72. }