Newer
Older
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
<?php
/**
* @file
* Install, update and uninstall functions.
*/
/**
* Implements hook_install().
*/
function entity_bundle_field_test_install() {
$manager = \Drupal::entityManager();
// Notify the entity storage of our custom field.
$definition = $manager->getFieldStorageDefinitions('entity_test')['custom_field'];
$manager->getStorage('entity_test')->onFieldStorageDefinitionCreate($definition);
// Create the custom bundle and put our bundle field on it.
entity_test_create_bundle('custom');
$definition = $manager->getFieldDefinitions('entity_test', 'custom')['custom_field'];
$manager->getStorage('entity_test')->onFieldDefinitionCreate($definition);
}
/**
* Implements hook_uninstall().
*/
function entity_bundle_field_test_uninstall() {
entity_bundle_field_test_is_uninstalling(TRUE);
$manager = \Drupal::entityManager();
// Notify the entity storage that our field is gone.
$definition = $manager->getFieldDefinitions('entity_test', 'custom')['custom_field'];
$manager->getStorage('entity_test')->onFieldDefinitionDelete($definition);
$storage_definition = $manager->getFieldStorageDefinitions('entity_test')['custom_field'];
$manager->getStorage('entity_test')->onFieldStorageDefinitionDelete($storage_definition);
$manager->clearCachedFieldDefinitions();
do {
$count = $manager->getStorage('entity_test')->purgeFieldData($definition, 500);
}
while ($count != 0);
$manager->getStorage('entity_test')->finalizePurge($definition);
}