diff --git a/src/Command/Module/InstallCommand.php b/src/Command/Module/InstallCommand.php index 4f11dccc2..04f6417e4 100644 --- a/src/Command/Module/InstallCommand.php +++ b/src/Command/Module/InstallCommand.php @@ -14,6 +14,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Command\Command; use Drupal\Console\Command\Shared\ProjectDownloadTrait; +use Drupal\Console\Command\Shared\ModuleTrait; use Drupal\Console\Style\DrupalStyle; /** @@ -24,6 +25,7 @@ class InstallCommand extends Command { use ContainerAwareCommandTrait; use ProjectDownloadTrait; + use ModuleTrait; /** * {@inheritdoc} @@ -78,6 +80,9 @@ protected function execute(InputInterface $input, OutputInterface $output) $composer = $input->getOption('composer'); $this->get('site')->loadLegacyFile('core/includes/bootstrap.inc'); + + // check module's requirements + $this->moduleRequirement($module); if ($composer) { foreach ($module as $moduleItem) { diff --git a/src/Command/Shared/ModuleTrait.php b/src/Command/Shared/ModuleTrait.php index b501f098e..c960cf51d 100644 --- a/src/Command/Shared/ModuleTrait.php +++ b/src/Command/Shared/ModuleTrait.php @@ -40,4 +40,18 @@ public function moduleQuestion(DrupalStyle $io, $showProfile = true) return $module; } + + public function moduleRequirement($module) + { + foreach ($module as $module_name) { + module_load_install($module_name); + + if ($requirements = \Drupal::moduleHandler()->invoke($module_name, 'requirements', array('install'))) { + foreach ($requirements as $requirement) { + throw new \Exception($module_name .' can not be installed: ' . $requirement['description']); + } + } + } + } + }