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@0
|
112 * Installs a new entity type definition.
|
Chris@0
|
113 *
|
Chris@0
|
114 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
Chris@0
|
115 * The entity type definition.
|
Chris@0
|
116 */
|
Chris@0
|
117 public function installEntityType(EntityTypeInterface $entity_type);
|
Chris@0
|
118
|
Chris@0
|
119 /**
|
Chris@0
|
120 * Applies any change performed to the passed entity type definition.
|
Chris@0
|
121 *
|
Chris@0
|
122 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
Chris@0
|
123 * The entity type definition.
|
Chris@0
|
124 */
|
Chris@0
|
125 public function updateEntityType(EntityTypeInterface $entity_type);
|
Chris@0
|
126
|
Chris@0
|
127 /**
|
Chris@0
|
128 * Uninstalls an entity type definition.
|
Chris@0
|
129 *
|
Chris@0
|
130 * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
|
Chris@0
|
131 * The entity type definition.
|
Chris@0
|
132 */
|
Chris@0
|
133 public function uninstallEntityType(EntityTypeInterface $entity_type);
|
Chris@0
|
134
|
Chris@0
|
135 /**
|
Chris@0
|
136 * Returns a field storage definition ready to be manipulated.
|
Chris@0
|
137 *
|
Chris@0
|
138 * When needing to apply updates to existing field storage definitions, this
|
Chris@0
|
139 * method should always be used to retrieve a storage definition ready to be
|
Chris@0
|
140 * manipulated.
|
Chris@0
|
141 *
|
Chris@0
|
142 * @param string $name
|
Chris@0
|
143 * The field name.
|
Chris@0
|
144 * @param string $entity_type_id
|
Chris@0
|
145 * The entity type identifier.
|
Chris@0
|
146 *
|
Chris@0
|
147 * @return \Drupal\Core\Field\FieldStorageDefinitionInterface
|
Chris@0
|
148 * The field storage definition.
|
Chris@0
|
149 *
|
Chris@0
|
150 * @todo Make this return a mutable storage definition interface when we have
|
Chris@0
|
151 * one. See https://www.drupal.org/node/2346329.
|
Chris@0
|
152 */
|
Chris@0
|
153 public function getFieldStorageDefinition($name, $entity_type_id);
|
Chris@0
|
154
|
Chris@0
|
155 /**
|
Chris@0
|
156 * Installs a new field storage definition.
|
Chris@0
|
157 *
|
Chris@0
|
158 * @param string $name
|
Chris@0
|
159 * The field storage definition name.
|
Chris@0
|
160 * @param string $entity_type_id
|
Chris@0
|
161 * The target entity type identifier.
|
Chris@0
|
162 * @param string $provider
|
Chris@0
|
163 * The name of the definition provider.
|
Chris@0
|
164 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
|
Chris@0
|
165 * The field storage definition.
|
Chris@0
|
166 */
|
Chris@0
|
167 public function installFieldStorageDefinition($name, $entity_type_id, $provider, FieldStorageDefinitionInterface $storage_definition);
|
Chris@0
|
168
|
Chris@0
|
169 /**
|
Chris@0
|
170 * Applies any change performed to the passed field storage definition.
|
Chris@0
|
171 *
|
Chris@0
|
172 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
|
Chris@0
|
173 * The field storage definition.
|
Chris@0
|
174 */
|
Chris@0
|
175 public function updateFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
|
Chris@0
|
176
|
Chris@0
|
177 /**
|
Chris@0
|
178 * Uninstalls a field storage definition.
|
Chris@0
|
179 *
|
Chris@0
|
180 * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
|
Chris@0
|
181 * The field storage definition.
|
Chris@0
|
182 */
|
Chris@0
|
183 public function uninstallFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition);
|
Chris@0
|
184
|
Chris@0
|
185 }
|