One of the modules I maintain contains a sub-module. The sub-module doesn't do much; just provides views integration for the main module, i.e. only have implementation of hook_views_data. I would like to move this implementation to the main module.

If it was D7, I would have followed the steps below:

  1. Remove the module files.
  2. Write an update hook in the main module, to remove the entry from the system table.
  3. In the same update hook, would delete the variables (if present).

For D8, I have written an update hook for the same in the module (Reference : #2781805 : Social stats field are not available in views):

 * Implements hook_update_N().
 * Removes entry of social_stats_views module.
function social_stats_update_8001(&$sandbox) {
  // Read the configuration.
  $module_data = \Drupal::config('core.extension')->get('module');

  // Unset the modules you do not need.

  // Write the configuration.
  \Drupal::configFactory()->getEditable('core.extension')->set('module', $module_data)->save();

I did not add anything else (like removing config, etc.), as the module only implemented a single hook.

I still see the following error after executing the update hook:

User warning: The following module is missing from the file system: social_stats_views in drupal_get_filename() (line 236 of core/includes/bootstrap.inc).

Is there a bullet-proof way to remove the module?

  • 1
    Yeah, you can't properly uninstall if the files are no longer there. Someone asked this just yesterday in IRC I suggested to simply leave the empty module file there and make it hidden: true so it no longer shows up for new installations. Or keep the module file and then you should be able to safely call uninstall(). If you don't want that, you need to figure out who still tries to look it up. Enable verbose error logging and see who calls it. My guess is update functions, you probably need to delete a key_value entry or so
    – Berdir
    Jan 4 '17 at 9:38

You can use ModuleInstaller::uninstall():


In D8 there is a lot of housekeeping to do. You can see this in the code of uninstall():


  • The error still shows up. Maybe because the module is not present in the file system?
    – AjitS
    Jan 4 '17 at 9:09
  • You might need to keep a mockup of the sub-module in the updated code of the main module or produce this temporarily in the update hook before running the uninstall.
    – 4k4
    Jan 4 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.