annotate core/lib/Drupal/Core/Entity/EntityDefinitionUpdateManagerInterface.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@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@18 83 * Gets a list of changes to entity type and field storage definitions.
Chris@18 84 *
Chris@18 85 * @return array
Chris@18 86 * An associative array keyed by entity type ID of change descriptors. Every
Chris@18 87 * entry is an associative array with the following optional keys:
Chris@18 88 * - entity_type: a scalar having one value among:
Chris@18 89 * - EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED
Chris@18 90 * - EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED
Chris@18 91 * - field_storage_definitions: an associative array keyed by field name of
Chris@18 92 * scalars having one value among:
Chris@18 93 * - EntityDefinitionUpdateManagerInterface::DEFINITION_CREATED
Chris@18 94 * - EntityDefinitionUpdateManagerInterface::DEFINITION_UPDATED
Chris@18 95 * - EntityDefinitionUpdateManagerInterface::DEFINITION_DELETED
Chris@18 96 */
Chris@18 97 public function getChangeList();
Chris@18 98
Chris@18 99 /**
Chris@0 100 * Applies all the detected valid changes.
Chris@0 101 *
Chris@0 102 * Use this with care, as it will apply updates for any module, which will
Chris@0 103 * lead to unpredictable results.
Chris@0 104 *
Chris@0 105 * @throws \Drupal\Core\Entity\EntityStorageException
Chris@0 106 * This exception is thrown if a change cannot be applied without
Chris@0 107 * unacceptable data loss. In such a case, the site administrator needs to
Chris@0 108 * apply some other process, such as a custom update function or a
Chris@0 109 * migration via the Migrate module.
Chris@18 110 *
Chris@18 111 * @deprecated in Drupal 8.7.0, will be removed before Drupal 9.0.0. Use
Chris@18 112 * \Drupal\Core\Entity\EntityDefinitionUpdateManagerInterface::getChangeList()
Chris@18 113 * and execute each entity type and field storage update manually instead.
Chris@18 114 *
Chris@18 115 * @see https://www.drupal.org/node/3034742
Chris@0 116 */
Chris@0 117 public function applyUpdates();
Chris@0 118
Chris@0 119 /**
Chris@0 120 * Returns an entity type definition ready to be manipulated.
Chris@0 121 *
Chris@0 122 * When needing to apply updates to existing entity type definitions, this
Chris@0 123 * method should always be used to retrieve a definition ready to be
Chris@0 124 * manipulated.
Chris@0 125 *
Chris@0 126 * @param string $entity_type_id
Chris@0 127 * The entity type identifier.
Chris@0 128 *
Chris@0 129 * @return \Drupal\Core\Entity\EntityTypeInterface
Chris@0 130 * The entity type definition.
Chris@0 131 */
Chris@0 132 public function getEntityType($entity_type_id);
Chris@0 133
Chris@0 134 /**
Chris@17 135 * Returns all the entity type definitions, ready to be manipulated.
Chris@17 136 *
Chris@17 137 * When needing to apply updates to existing entity type definitions, this
Chris@17 138 * method should always be used to retrieve all the definitions ready to be
Chris@17 139 * manipulated.
Chris@17 140 *
Chris@17 141 * @return \Drupal\Core\Entity\EntityTypeInterface[]
Chris@17 142 * The last installed entity type definitions, keyed by the entity type ID.
Chris@17 143 */
Chris@17 144 public function getEntityTypes();
Chris@17 145
Chris@17 146 /**
Chris@0 147 * Installs a new entity type definition.
Chris@0 148 *
Chris@0 149 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 150 * The entity type definition.
Chris@0 151 */
Chris@0 152 public function installEntityType(EntityTypeInterface $entity_type);
Chris@0 153
Chris@0 154 /**
Chris@0 155 * Applies any change performed to the passed entity type definition.
Chris@0 156 *
Chris@0 157 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 158 * The entity type definition.
Chris@0 159 */
Chris@0 160 public function updateEntityType(EntityTypeInterface $entity_type);
Chris@0 161
Chris@0 162 /**
Chris@0 163 * Uninstalls an entity type definition.
Chris@0 164 *
Chris@0 165 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@0 166 * The entity type definition.
Chris@0 167 */
Chris@0 168 public function uninstallEntityType(EntityTypeInterface $entity_type);
Chris@0 169
Chris@0 170 /**
Chris@18 171 * Applies any change performed to a fieldable entity type definition.
Chris@18 172 *
Chris@18 173 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
Chris@18 174 * The updated entity type definition.
Chris@18 175 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface[] $field_storage_definitions
Chris@18 176 * The updated field storage definitions, including possibly new ones.
Chris@18 177 * @param array &$sandbox
Chris@18 178 * (optional) A sandbox array provided by a hook_update_N() implementation
Chris@18 179 * or a Batch API callback. If the entity schema update requires a data
Chris@18 180 * migration, this parameter is mandatory. Defaults to NULL.
Chris@18 181 */
Chris@18 182 public function updateFieldableEntityType(EntityTypeInterface $entity_type, array $field_storage_definitions, array &$sandbox = NULL);
Chris@18 183
Chris@18 184 /**
Chris@0 185 * Returns a field storage definition ready to be manipulated.
Chris@0 186 *
Chris@0 187 * When needing to apply updates to existing field storage definitions, this
Chris@0 188 * method should always be used to retrieve a storage definition ready to be
Chris@0 189 * manipulated.
Chris@0 190 *
Chris@0 191 * @param string $name
Chris@0 192 * The field name.
Chris@0 193 * @param string $entity_type_id
Chris@0 194 * The entity type identifier.
Chris@0 195 *
Chris@0 196 * @return \Drupal\Core\Field\FieldStorageDefinitionInterface
Chris@0 197 * The field storage definition.
Chris@0 198 *
Chris@0 199 * @todo Make this return a mutable storage definition interface when we have
Chris@0 200 * one. See https://www.drupal.org/node/2346329.
Chris@0 201 */
Chris@0 202 public function getFieldStorageDefinition($name, $entity_type_id);
Chris@0 203
Chris@0 204 /**
Chris@0 205 * Installs a new field storage definition.
Chris@0 206 *
Chris@0 207 * @param string $name
Chris@0 208 * The field storage definition name.
Chris@0 209 * @param string $entity_type_id
Chris@0 210 * The target entity type identifier.
Chris@0 211 * @param string $provider
Chris@0 212 * The name of the definition provider.
Chris@0 213 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 214 * The field storage definition.
Chris@0 215 */
Chris@0 216 public function installFieldStorageDefinition($name, $entity_type_id, $provider, FieldStorageDefinitionInterface $storage_definition);
Chris@0 217
Chris@0 218 /**
Chris@0 219 * Applies any change performed to the passed field storage definition.
Chris@0 220 *
Chris@0 221 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 222 * The field storage definition.
Chris@0 223 */
Chris@0 224 public function updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
Chris@0 225
Chris@0 226 /**
Chris@0 227 * Uninstalls a field storage definition.
Chris@0 228 *
Chris@0 229 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
Chris@0 230 * The field storage definition.
Chris@0 231 */
Chris@0 232 public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
Chris@0 233
Chris@0 234 }