annotate core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Entity;
Chris@0 4
Chris@0 5 use Drupal\Core\Field\FieldStorageDefinitionInterface;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Defines an interface for managing entity definition updates.
Chris@0 9 *
Chris@0 10 * During the application lifetime, the definitions of various entity types and
Chris@0 11 * their data components (e.g., fields for fieldable entity types) can change.
Chris@0 12 * For example, updated code can be deployed. Some entity handlers may need to
Chris@0 13 * perform complex or long-running logic in response to the change. For
Chris@0 14 * example, a SQL-based storage handler may need to update the database schema.
Chris@0 15 *
Chris@0 16 * To support this, \Drupal\Core\Entity\EntityManagerInterface has methods to
Chris@0 17 * retrieve the last installed definitions as well as the definitions specified
Chris@0 18 * by the current codebase. It also has create/update/delete methods to bring
Chris@0 19 * the former up to date with the latter.
Chris@0 20 *
Chris@0 21 * However, it is not the responsibility of the entity manager to decide how to
Chris@0 22 * report the differences or when to apply each update. This interface is for
Chris@0 23 * managing that.
Chris@0 24 *
Chris@0 25 * This interface also provides methods to retrieve instances of the definitions
Chris@0 26 * to be updated ready to be manipulated. In fact when definitions change in
Chris@0 27 * code the system needs to be notified about that and the definitions stored in
Chris@0 28 * state need to be reconciled with the ones living in code. This typically
Chris@0 29 * happens in Update API functions, which need to take the system from a known
Chris@0 30 * state to another known state. Relying on the definitions living in code might
Chris@0 31 * prevent this, as the system might transition directly to the last available
Chris@0 32 * state, and thus skipping the intermediate steps. Manipulating the definitions
Chris@0 33 * in state allows to avoid this and ensures that the various steps of the
Chris@0 34 * update process are predictable and repeatable.
Chris@0 35 *
Chris@0 36 * @see \Drupal\Core\Entity\EntityManagerInterface::getDefinition()
Chris@0 37 * @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledDefinition()
Chris@0 38 * @see \Drupal\Core\Entity\EntityManagerInterface::getFieldStorageDefinitions()
Chris@0 39 * @see \Drupal\Core\Entity\EntityManagerInterface::getLastInstalledFieldStorageDefinitions()
Chris@0 40 * @see hook_update_N()
Chris@0 41 */
Chris@0 42 interface EntityDefinitionUpdateManagerInterface {
Chris@0 43
Chris@0 44 /**
Chris@0 45 * Indicates that a definition has just been created.
Chris@0 46 *
Chris@0 47 * @var int
Chris@0 48 */
Chris@0 49 const DEFINITION_CREATED = 1;
Chris@0 50
Chris@0 51 /**
Chris@0 52 * Indicates that a definition has changes.
Chris@0 53 *
Chris@0 54 * @var int
Chris@0 55 */
Chris@0 56 const DEFINITION_UPDATED = 2;
Chris@0 57
Chris@0 58 /**
Chris@0 59 * Indicates that a definition has just been deleted.
Chris@0 60 *
Chris@0 61 * @var int
Chris@0 62 */
Chris@0 63 const DEFINITION_DELETED = 3;
Chris@0 64
Chris@0 65 /**
Chris@0 66 * Checks if there are any definition updates that need to be applied.
Chris@0 67 *
Chris@0 68 * @return bool
Chris@0 69 * TRUE if updates are needed.
Chris@0 70 */
Chris@0 71 public function needsUpdates();
Chris@0 72
Chris@0 73 /**
Chris@0 74 * Gets a human readable summary of the detected changes.
Chris@0 75 *
Chris@0 76 * @return array
Chris@0 77 * An associative array keyed by entity type id. Each entry is an array of
Chris@0 78 * human-readable strings, each describing a change.
Chris@0 79 */
Chris@0 80 public function getChangeSummary();
Chris@0 81
Chris@0 82 /**
Chris@0 83 * Applies all the detected valid changes.
Chris@0 84 *
Chris@0 85 * Use this with care, as it will apply updates for any module, which will
Chris@0 86 * lead to unpredictable results.
Chris@0 87 *
Chris@0 88 * @throws \Drupal\Core\Entity\EntityStorageException
Chris@0 89 * This exception is thrown if a change cannot be applied without
Chris@0 90 * unacceptable data loss. In such a case, the site administrator needs to
Chris@0 91 * apply some other process, such as a custom update function or a
Chris@0 92 * migration via the Migrate module.
Chris@0 93 */
Chris@0 94 public function applyUpdates();
Chris@0 95
Chris@0 96 /**
Chris@0 97 * Returns an entity type definition ready to be manipulated.
Chris@0 98 *
Chris@0 99 * When needing to apply updates to existing entity type definitions, this
Chris@0 100 * method should always be used to retrieve a definition ready to be
Chris@0 101 * manipulated.
Chris@0 102 *
Chris@0 103 * @param string $entity_type_id
Chris@0 104 * The entity type identifier.
Chris@0 105 *
Chris@0 106 * @return \Drupal\Core\Entity\EntityTypeInterface
Chris@0 107 * The entity type definition.
Chris@0 108 */
Chris@0 109 public function getEntityType($entity_type_id);
Chris@0 110
Chris@0 111 /**
Chris@17 112 * Returns all the entity type definitions, ready to be manipulated.
Chris@17 113 *
Chris@17 114 * When needing to apply updates to existing entity type definitions, this
Chris@17 115 * method should always be used to retrieve all the definitions ready to be
Chris@17 116 * manipulated.
Chris@17 117 *
Chris@17 118 * @return \Drupal\Core\Entity\EntityTypeInterface[]
Chris@17 119 * The last installed entity type definitions, keyed by the entity type ID.
Chris@17 120 */
Chris@17 121 public function getEntityTypes();
Chris@17 122
Chris@17 123 /**
Chris@0 124 * Installs a new entity type definition.
Chris@0 125 *
Chris@0 126 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 127 * The entity type definition.
Chris@0 128 */
Chris@0 129 public function installEntityType(EntityTypeInterface $entity_type);
Chris@0 130
Chris@0 131 /**
Chris@0 132 * Applies any change performed to the passed entity type definition.
Chris@0 133 *
Chris@0 134 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 135 * The entity type definition.
Chris@0 136 */
Chris@0 137 public function updateEntityType(EntityTypeInterface $entity_type);
Chris@0 138
Chris@0 139 /**
Chris@0 140 * Uninstalls an entity type definition.
Chris@0 141 *
Chris@0 142 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 143 * The entity type definition.
Chris@0 144 */
Chris@0 145 public function uninstallEntityType(EntityTypeInterface $entity_type);
Chris@0 146
Chris@0 147 /**
Chris@0 148 * Returns a field storage definition ready to be manipulated.
Chris@0 149 *
Chris@0 150 * When needing to apply updates to existing field storage definitions, this
Chris@0 151 * method should always be used to retrieve a storage definition ready to be
Chris@0 152 * manipulated.
Chris@0 153 *
Chris@0 154 * @param string $name
Chris@0 155 * The field name.
Chris@0 156 * @param string $entity_type_id
Chris@0 157 * The entity type identifier.
Chris@0 158 *
Chris@0 159 * @return \Drupal\Core\Field\FieldStorageDefinitionInterface
Chris@0 160 * The field storage definition.
Chris@0 161 *
Chris@0 162 * @todo Make this return a mutable storage definition interface when we have
Chris@0 163 * one. See https://www.drupal.org/node/2346329.
Chris@0 164 */
Chris@0 165 public function getFieldStorageDefinition($name, $entity_type_id);
Chris@0 166
Chris@0 167 /**
Chris@0 168 * Installs a new field storage definition.
Chris@0 169 *
Chris@0 170 * @param string $name
Chris@0 171 * The field storage definition name.
Chris@0 172 * @param string $entity_type_id
Chris@0 173 * The target entity type identifier.
Chris@0 174 * @param string $provider
Chris@0 175 * The name of the definition provider.
Chris@0 176 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 177 * The field storage definition.
Chris@0 178 */
Chris@0 179 public function installFieldStorageDefinition($name, $entity_type_id, $provider, FieldStorageDefinitionInterface $storage_definition);
Chris@0 180
Chris@0 181 /**
Chris@0 182 * Applies any change performed to the passed field storage definition.
Chris@0 183 *
Chris@0 184 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 185 * The field storage definition.
Chris@0 186 */
Chris@0 187 public function updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
Chris@0 188
Chris@0 189 /**
Chris@0 190 * Uninstalls a field storage definition.
Chris@0 191 *
Chris@0 192 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 193 * The field storage definition.
Chris@0 194 */
Chris@0 195 public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
Chris@0 196
Chris@0 197 }