function DevelCommands::hookInteract

Same name in this branch
  1. 5.x src/Drush/Commands/DevelCommands.php \Drupal\devel\Drush\Commands\DevelCommands::hookInteract()
Same name in other branches
  1. 4.x src/Commands/DevelCommands.php \Drupal\devel\Commands\DevelCommands::hookInteract()

Asks the user to select a hook implementation.

@hook interact hook

File

src/Commands/DevelCommands.php, line 146

Class

DevelCommands
Class DevelCommands.

Namespace

Drupal\devel\Commands

Code

public function hookInteract(Input $input, Output $output) {
    $hook_implementations = [];
    if (!$input->getArgument('implementation')) {
        foreach ($this->getModuleHandler()
            ->getModuleList() as $key => $extension) {
            if ($this->getModuleHandler()
                ->hasImplementations($input->getArgument('hook'), [
                $key,
            ])) {
                $hook_implementations[] = $key;
            }
        }
        if ($hook_implementations) {
            if (!($choice = $this->io()
                ->choice('Enter the number of the hook implementation you wish to view.', array_combine($hook_implementations, $hook_implementations)))) {
                throw new UserAbortException();
            }
            $input->setArgument('implementation', $choice);
        }
        else {
            throw new \Exception(dt('No implementations'));
        }
    }
}