function DevelHookCommand::interact
File
-
src/Drush/Commands/DevelHookCommand.php, line 49
Class
- DevelHookCommand
- #[AsCommand(name: self::NAME, description: 'List implementations of a given hook and optionally edit one.', aliases: [
'fnh',
'fn-hook',
'hook',
'devel-hook',
])]
#[CLI\OptionsetGetEditor]
Namespace
Drupal\devel\Drush\Commands
Code
protected function interact(InputInterface $input, OutputInterface $output) {
if (!$hook = $input->getArgument('hook')) {
throw new \InvalidArgumentException(dt('No hook specified.'));
}
$hook_implementations = [];
if (!$input->getArgument('implementation')) {
foreach (array_keys($this->moduleHandler
->getModuleList()) as $key) {
if ($this->moduleHandler
->hasImplementations($hook, [
$key,
])) {
$hook_implementations[] = $key;
}
}
if ($hook_implementations !== []) {
if (!$choice = (new DrushStyle($input, $output))->select('Select the hook implementation you wish to view.', array_combine($hook_implementations, $hook_implementations))) {
throw new UserAbortException();
}
$input->setArgument('implementation', $choice);
}
else {
throw new \InvalidArgumentException(dt('No implementations'));
}
}
}