You are here

function tca_module_preuninstall in Token Content Access 2.0.x

Same name and namespace in other branches
  1. 8 tca.module \tca_module_preuninstall()

Implements hook_module_preuninstall().

File

./tca.module, line 159
Contains tca.module.

Code

function tca_module_preuninstall($module) {
  $plugin_manager = \Drupal::service('plugin.manager.tca_plugin');
  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
  $plugin_definitions = $plugin_manager
    ->loadDefinitionsByModuleName($module);
  foreach ($plugin_definitions as $plugin_definition) {
    $entity_type_id = $plugin_definition['entityType'];
    $plugin = $plugin_manager
      ->createInstanceByEntityType($entity_type_id);
    if ($plugin && $plugin
      ->isFieldable()) {
      $fields = _tca_extra_field_definitions();
      foreach ($fields as $name => $storage_definition) {
        $storage_definition = $definition_update_manager
          ->getFieldStorageDefinition($name, $entity_type_id);
        $definition_update_manager
          ->uninstallFieldStorageDefinition($storage_definition);
      }
    }
  }
}