diff --git a/core/modules/views/views.install b/core/modules/views/views.install index d3c0dee..55acb96 100644 --- a/core/modules/views/views.install +++ b/core/modules/views/views.install @@ -27,3 +27,36 @@ function views_schema_0() { $schema['cache_views_results'] = $cache_schema; return $schema; } + +/** + * Implements hook_modules_uninstalled(). + */ +function views_modules_uninstalled($modules) { + // Tables that are to be removed, or their hook_views_data() + // info is going away. + $removed_tables = array(); + foreach ($modules as $module) { + $schema = drupal_get_schema_unprocessed($module); + _drupal_schema_initialize($schema, $module, FALSE); + foreach ($schema as $table) { + $removed_tables[] = $table['name']; + } + } + + $data = Drupal::service('views.views_data')->get(); + foreach ($data as $table => $info) { + if (in_array($info['module'], $modules) && isset($info['table']['base'])) { + $removed_tables[] = $table; + } + } + + if ($removed_tables) { + $query = Drupal::entityQuery('view') + ->condition('base_table', $removed_tables) + ->execute(); + $view_storage = $entity_manager->getStorageController('view'); + $views = $view_storage->loadMultiple($query); + $view_storage->delete($views); + } +} +