Skip to content

Commit

Permalink
Add new method for ModuleTrait, which get module name from input. Rep…
Browse files Browse the repository at this point in the history
…lace the code in the FormCommand (#3642)

I will merge this one and will make a small change to fix an error
  • Loading branch information
LOBsTerr authored and jmolivas committed Jan 7, 2018
1 parent f30e6e5 commit 7780d2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/Command/Generate/FormCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
32 changes: 32 additions & 0 deletions src/Command/Shared/ModuleTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
);
}
}
}
}

0 comments on commit 7780d2c

Please sign in to comment.