Drupal - How do I disable modules via admin interface or via Drush?

Like the admin interface in Drupal 8 states in the message area, the paradigm and concept of how modules get installed and disabled has changed in Drupal 8, since there were many problems involved in the way how it was before, because of Database left-overs and data inconsistencies while disabling and enabling modules, etc.

Therefore users are encouraged to rather uninstall modules than disabling them now in D8. This doesn't mean the modules are gone or removed from the Drupal root, but they are completely removed from the database including their configuration.

Try drush pm-uninstall module-name instead and you will see the desired effect you are after.

The checkboxes are greyed out to be still able to enable and install inactive modules the way known from D7. But you can't disable them this way no more. And uninstalling should not be provided by checkboxes, since this would be to dangerous.

Look twice in the admin interface: You will find a new tab for uninstalling modules too.


As the question asks for programmatically and that's why I came here in the first place I'll add a working code snippet to be placed inside MYMODULE.install:

/**
 * Uninstall Field UI.
 */
function MYMODULE_update_8001(&$sandbox) {

  \Drupal::service('module_installer')->uninstall(['field_ui']);

}

You can also use drupal console https://drupalconsole.com/ and simply use the command

drupal module:uninstall token

And for install

drupal module:install token

Tags:

Drush

8