Chris@0: setValidator(function ($value) { Chris@0: if (!in_array($value, $this->getSupportedHooks())) { Chris@0: throw new \UnexpectedValueException('The value is not correct class name.'); Chris@0: } Chris@0: return $value; Chris@0: }); Chris@0: $questions['hook_name']->setAutocompleterValues($this->getSupportedHooks()); Chris@0: Chris@0: $vars = $this->collectVars($input, $output, $questions); Chris@0: Chris@0: // Most Drupal hooks are situated in a module file but some are not. Chris@0: $special_hooks = [ Chris@0: 'install' => [ Chris@0: 'install', Chris@0: 'uninstall', Chris@0: 'enable', Chris@0: 'disable', Chris@0: 'schema', Chris@0: 'schema_alter', Chris@0: 'field_schema', Chris@0: 'requirements', Chris@0: 'update_N', Chris@0: 'update_last_removed', Chris@0: ], Chris@0: // See system_hook_info(). Chris@0: 'tokens.inc' => [ Chris@0: 'token_info', Chris@0: 'token_info_alter', Chris@0: 'tokens', Chris@0: 'tokens_alter', Chris@0: ], Chris@0: ]; Chris@0: Chris@0: $file_type = 'module'; Chris@0: foreach ($special_hooks as $group => $hooks) { Chris@0: if (in_array($vars['hook_name'], $hooks)) { Chris@0: $file_type = $group; Chris@0: break; Chris@0: } Chris@0: } Chris@0: Chris@0: $this->addFile() Chris@0: ->path("{machine_name}.$file_type") Chris@0: ->headerTemplate("d7/file-docs/$file_type.twig") Chris@0: ->template('d7/hook/' . $vars['hook_name'] . '.twig') Chris@0: ->action('append') Chris@0: ->headerSize(7); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Gets list of supported hooks. Chris@0: * Chris@0: * @return array Chris@0: * List of supported hooks. Chris@0: */ Chris@0: protected function getSupportedHooks() { Chris@0: return array_map(function ($file) { Chris@0: return pathinfo($file, PATHINFO_FILENAME); Chris@0: }, array_diff(scandir($this->templatePath . '/d7/hook'), ['.', '..'])); Chris@0: } Chris@0: Chris@0: }