X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_7%2FHook.php;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FCommand%2FDrupal_7%2FHook.php;h=2739fc32d08c7be8a2fdde23359cbc33bf1bc8e1;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_7/Hook.php b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_7/Hook.php new file mode 100644 index 000000000..2739fc32d --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/src/Command/Drupal_7/Hook.php @@ -0,0 +1,86 @@ +setValidator(function ($value) { + if (!in_array($value, $this->getSupportedHooks())) { + throw new \UnexpectedValueException('The value is not correct class name.'); + } + return $value; + }); + $questions['hook_name']->setAutocompleterValues($this->getSupportedHooks()); + + $vars = $this->collectVars($input, $output, $questions); + + // Most Drupal hooks are situated in a module file but some are not. + $special_hooks = [ + 'install' => [ + 'install', + 'uninstall', + 'enable', + 'disable', + 'schema', + 'schema_alter', + 'field_schema', + 'requirements', + 'update_N', + 'update_last_removed', + ], + // See system_hook_info(). + 'tokens.inc' => [ + 'token_info', + 'token_info_alter', + 'tokens', + 'tokens_alter', + ], + ]; + + $file_type = 'module'; + foreach ($special_hooks as $group => $hooks) { + if (in_array($vars['hook_name'], $hooks)) { + $file_type = $group; + break; + } + } + + $this->addFile() + ->path("{machine_name}.$file_type") + ->headerTemplate("d7/file-docs/$file_type.twig") + ->template('d7/hook/' . $vars['hook_name'] . '.twig') + ->action('append') + ->headerSize(7); + } + + /** + * Gets list of supported hooks. + * + * @return array + * List of supported hooks. + */ + protected function getSupportedHooks() { + return array_map(function ($file) { + return pathinfo($file, PATHINFO_FILENAME); + }, array_diff(scandir($this->templatePath . '/d7/hook'), ['.', '..'])); + } + +}