How to enable (install) a module programmatically in Drupal 8
How to enable (install) a module programmatically in Drupal 8

A big change in Drupal 8 is that you can no longer enable and disable modules. You can only install and uninstall. The difference is paramount.

In Drupal 7 if you disabled a module and then enabled it back, you retained the modules settings all data stored by that module. This is not longer the case with Drupal8. Unistalling means completely removing all data and settings added to the module when it was installed. So be careful :)

How to install a module programmatically:

Lets install Admin Toolbar. A nice handy module extending the Drupal default toolbar.

\Drupal::service('module_installer')->install(['admin_toolbar']);

Need a team of Drupal and PHP web development experts?

Contact us now!