annotate core/lib/Drupal/Core/Entity/SynchronizableInterface.php @ 5:12f9dff5fda9 tip

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