class DevelHookCommand
Attributes
#[AsCommand(name: self::NAME, description: 'List implementations of a given hook and optionally edit one.', aliases: [
'fnh',
'fn-hook',
'hook',
'devel-hook',
])]
#[CLI\OptionsetGetEditor]
Hierarchy
- class \Drupal\devel\Drush\Commands\DevelHookCommand uses \Drush\Commands\AutowireTrait, \Drupal\devel\Drush\Commands\CodeTrait, \Drush\Exec\ExecTrait extends \Symfony\Component\Console\Command\Command
Expanded class hierarchy of DevelHookCommand
File
-
src/
Drush/ Commands/ DevelHookCommand.php, line 21
Namespace
Drupal\devel\Drush\CommandsView source
class DevelHookCommand extends Command {
use AutowireTrait;
use CodeTrait;
use ExecTrait;
const NAME = 'devel:hook';
public function __construct(protected readonly ProcessManager $processManager, protected readonly ModuleHandlerInterface $moduleHandler) {
parent::__construct();
}
protected function configure() : void {
$this->addArgument('hook', mode: InputArgument::REQUIRED, description: 'The name of the hook to explore.')
->addArgument(name: 'implementation', mode: InputArgument::OPTIONAL, description: 'The name of the implementation to edit. Usually omitted')
->addUsage('devel:hook cron');
}
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'));
}
}
}
protected function execute(InputInterface $input, OutputInterface $output) : int {
// Get implementations in the .install files as well.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_load_updates();
$info = $this->codeLocate($input->getArgument('implementation') . ('_' . $input->getArgument('hook')));
$exec = self::getEditor('');
$cmd = sprintf($exec, Escape::shellArg($info['file']));
$process = $this->processManager
->shell($cmd);
$process->setTty(TRUE);
$process->mustRun();
return Command::SUCCESS;
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary |
|---|---|---|---|
| CodeTrait::codeLocate | public | function | Get source code line for specified function or method. |
| DevelHookCommand::configure | protected | function | |
| DevelHookCommand::execute | protected | function | |
| DevelHookCommand::interact | protected | function | |
| DevelHookCommand::NAME | constant | ||
| DevelHookCommand::__construct | public | function |