In Drupal 7, if we wanted to push code to our environments enabling modules, we would call module_enable()
in hook_update_N()
. We no longer have that in Drupal 8, so how do we programmatically enable modules? Do we use Drupal 8's Configuration Manager or hook_update_N()
?
A diff on the exported configuration yields this:
+++ b/cim/sync/core.extension.yml
@@ -10,6 +10,9 @@ module:
config: 0
contact: 0
contextual: 0
+ ctools: 0
So it seems the module is enabled via code using Configuration Manager. We're also working with the idea of this:
function mymodule_update_8003() {
$modules = array(
'ctools',
);
\Drupal::service('module_installer')->install($modules);
}
What is the correct method?