@@ -113,7 +113,7 @@ public function store($data, string $id = NULL) : string {
113
113
]);
114
114
}
115
115
$ entity ->save ();
116
- return $ entity ->get ($ this -> primaryKey () )->getString ();
116
+ return $ entity ->get (' data_uuid ' )->getString ();
117
117
}
118
118
119
119
/**
@@ -150,7 +150,9 @@ public function remove(string $id) {
150
150
->execute ()
151
151
) {
152
152
$ entity_id = reset ($ ids );
153
- $ this ->entityStorage ->delete ([$ this ->loadEntity ($ entity_id )]);
153
+ $ this ->entityStorage ->delete ([
154
+ $ this ->entityStorage ->load ($ entity_id ),
155
+ ]);
154
156
}
155
157
return $ id ;
156
158
}
@@ -159,16 +161,23 @@ public function remove(string $id) {
159
161
* {@inheritDoc}
160
162
*/
161
163
public function retrieveAll (): array {
162
- // Some calling code is very particular about the output being an array,
163
- // both as a return value here and after json_encode(). Since the entity
164
- // query returns a keyed array, json_encode() will think it's an object. We
165
- // don't want that, so we use array_values() to yield an indexed array.
166
- return array_values (
164
+ $ data_uuids = [];
165
+ $ entities = $ this ->entityStorage ->loadMultiple (
167
166
$ this ->entityStorage ->getQuery ()
168
167
->condition ('harvest_plan_id ' , $ this ->planId )
169
168
->accessCheck (FALSE )
170
169
->execute ()
171
170
);
171
+ /** @var \Drupal\harvest\HarvestHashInterface $entity*/
172
+ foreach ($ entities as $ entity ) {
173
+ $ uuid = $ entity ->get ('data_uuid ' )->getString ();
174
+ $ data_uuids [$ uuid ] = $ uuid ;
175
+ }
176
+ // Some calling code is very particular about the output being an array,
177
+ // both as a return value here and after json_encode(). Since we're using a
178
+ // keyed array, json_encode() will think it's an object. We don't want that,
179
+ // so we use array_values() to yield an indexed array.
180
+ return array_values ($ data_uuids );
172
181
}
173
182
174
183
/**
@@ -205,9 +214,10 @@ public function count(): int {
205
214
* {@inheritDoc}
206
215
*/
207
216
public function primaryKey () {
208
- // Use the primary key defined in the entity definition.
209
- $ definition = $ this ->entityTypeManager ->getDefinition (static ::ENTITY_TYPE );
210
- return ($ definition ->getKeys ())['id ' ];
217
+ // The primary key for entity API is 'id'. But the primary key for the
218
+ // database table interface is 'data_uuid'. This is mostly arbitrary for our
219
+ // purposes because we're not actually subclassing AbstractDatabaseTable.
220
+ return 'data_uuid ' ;
211
221
}
212
222
213
223
/**
@@ -241,18 +251,18 @@ public function getSchema(): array {
241
251
/**
242
252
* Helper method to load an entity given an ID.
243
253
*
244
- * @param string $id
254
+ * @param string $data_uuid
245
255
* Entity ID.
246
256
*
247
257
* @return \Drupal\harvest\HarvestHashInterface|null
248
258
* The loaded entity or NULL if none could be loaded.
249
259
*/
250
- protected function loadEntity (string $ id ): ?HarvestHashInterface {
251
- if (!$ id ) {
260
+ protected function loadEntity (string $ data_uuid ): ?HarvestHashInterface {
261
+ if (!$ data_uuid ) {
252
262
return NULL ;
253
263
}
254
264
if ($ ids = $ this ->entityStorage ->getQuery ()
255
- ->condition ($ this -> primaryKey () , $ id )
265
+ ->condition (' data_uuid ' , $ data_uuid )
256
266
->condition ('harvest_plan_id ' , $ this ->planId )
257
267
->range (0 , 1 )
258
268
->accessCheck (FALSE )
0 commit comments