diff --git a/src/Command/Generate/FormCommand.php b/src/Command/Generate/FormCommand.php index 8da506648..e5f17febc 100644 --- a/src/Command/Generate/FormCommand.php +++ b/src/Command/Generate/FormCommand.php @@ -231,12 +231,7 @@ protected function interact(InputInterface $input, OutputInterface $output) $io = new DrupalStyle($input, $output); // --module option - $module = $input->getOption('module'); - if (!$module) { - // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion - $module = $this->moduleQuestion($io); - $input->setOption('module', $module); - } + $this->moduleFromInput($io, $input); // --class option $className = $input->getOption('class'); diff --git a/src/Command/Shared/ModuleTrait.php b/src/Command/Shared/ModuleTrait.php index 88b52c1ab..a8b784896 100644 --- a/src/Command/Shared/ModuleTrait.php +++ b/src/Command/Shared/ModuleTrait.php @@ -86,4 +86,36 @@ public function moduleRequirement(array $module, DrupalStyle $io) throw new \Exception("Some module install requirements are not met."); } } + + /** + * Get module name from user. + * + * @param \Drupal\Console\Core\Style\DrupalStyle $io + * Console interface. + * @param \Drupal\Console\Command\Shared\InputInterface $input + * Input interface. + * @throws \Exception + * When module is not found. + */ + public function moduleFromInput( DrupalStyle $io, InputInterface $input) { + $module = $input->getOption('module'); + if (!$module) { + // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion + $module = $this->moduleQuestion($io); + $input->setOption('module', $module); + } + else { + $missing_modules = $this->validator->getMissingModules([$module]); + if ($missing_modules) { + throw new \Exception( + sprintf( + $this->trans( + 'commands.module.download.messages.no-releases' + ), + $module + ) + ); + } + } + } }