-
Notifications
You must be signed in to change notification settings - Fork 1
/
wmdummy_data.install
80 lines (66 loc) · 1.92 KB
/
wmdummy_data.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
use Drupal\Core\Entity\ContentEntityType;
use Drupal\wmdummy_data\Entity\DummyEntity;
/**
* Install dummy_entity entity type
*/
function wmdummy_data_update_8001(): void
{
$updateManager = \Drupal::entityDefinitionUpdateManager();
$entityType = new ContentEntityType([
'id' => 'dummy_entity',
'label' => t('Dummy entity'),
'base_table' => 'dummy_entity',
'translatable' => false,
'entity_keys' => [
'id' => 'did',
],
]);
$definitions = DummyEntity::baseFieldDefinitions($entityType);
$updateManager->installFieldableEntityType($entityType, $definitions);
}
/**
* Delete all existing dummy data
*/
function wmdummy_data_update_8002(): void
{
$state = \Drupal::state();
$entityTypeManager = \Drupal::entityTypeManager();
foreach ($state->get('wmdummy_data_keys', []) as $key) {
[, $entityTypeId] = explode('.', $key);
$storage = $entityTypeManager->getStorage($entityTypeId);
$ids = $state->get($key);
if (!$ids) {
continue;
}
$entities = $storage->loadMultiple($ids);
$storage->delete($entities);
$state->delete($key);
}
$state->delete('wmdummy_data_keys');
}
/**
* Install dummy_entity base fields
*/
function wmdummy_data_update_8003(): void
{
$updateManager = \Drupal::entityDefinitionUpdateManager();
$entityType = new ContentEntityType([
'id' => 'dummy_entity',
'label' => t('Dummy entity'),
'base_table' => 'dummy_entity',
'translatable' => false,
'entity_keys' => [
'id' => 'did',
],
]);
$definitions = DummyEntity::baseFieldDefinitions($entityType);
foreach ($definitions as $name => $definition) {
$updateManager->installFieldStorageDefinition(
$name,
$entityType->id(),
'wmdummy_data',
$definition
);
}
}