annotate core/lib/Drupal/Core/Entity/SynchronizableInterface.php @ 19:fa3358dc1485 tip

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