Skip to content
entity_bundle_field_test.install 1.46 KiB
Newer Older
<?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);
}