SynchronizableInterface.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace Drupal\Core\Entity;
  3. /**
  4. * Defines methods for an entity that supports synchronization.
  5. */
  6. interface SynchronizableInterface extends EntityInterface {
  7. /**
  8. * Sets the status of the synchronization flag.
  9. *
  10. * @param bool $status
  11. * The status of the synchronization flag.
  12. *
  13. * @return $this
  14. */
  15. public function setSyncing($status);
  16. /**
  17. * Returns whether this entity is being changed as part of a synchronization.
  18. *
  19. * If you are writing code that responds to a change in this entity (insert,
  20. * update, delete, presave, etc.), and your code would result in a change to
  21. * this entity itself, a configuration change (whether related to this entity,
  22. * another entity, or non-entity configuration), you need to check and see if
  23. * this entity change is part of a synchronization process, and skip executing
  24. * your code if that is the case.
  25. *
  26. * For example, \Drupal\node\Entity\NodeType::postSave() adds the default body
  27. * field to newly created node type configuration entities, which is a
  28. * configuration change. You would not want this code to run during an import,
  29. * because imported entities were already given the body field when they were
  30. * originally created, and the imported configuration includes all of their
  31. * currently-configured fields. On the other hand,
  32. * \Drupal\field\Entity\FieldStorageConfig::preSave() and the methods it calls
  33. * make sure that the storage tables are created or updated for the field
  34. * storage configuration entity, which is not a configuration change, and it
  35. * must be done whether due to an import or not. So, the first method should
  36. * check $entity->isSyncing() and skip executing if it returns TRUE, and the
  37. * second should not perform this check.
  38. *
  39. * @return bool
  40. * TRUE if the configuration entity is being created, updated, or deleted
  41. * through a synchronization process.
  42. */
  43. public function isSyncing();
  44. }