Skip to content

Commit

Permalink
Add module machine names to autocomplete for Module label.
Browse files Browse the repository at this point in the history
  • Loading branch information
weitzman committed Jun 9, 2017
1 parent 8b0b22b commit b716bd5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"repositories": [
{
"type": "vcs",
"url": "https://github.com/Chi-teck/drupal-code-generator"
"url": "https://github.com/weitzman/drupal-code-generator"
}
],
"require": {
Expand All @@ -36,7 +36,7 @@
"league/container": "~2",
"consolidation/robo": "~1",
"symfony/config": "~2.2|^3",
"chi-teck/drupal-code-generator": "dev-master",
"weitzman/drupal-code-generator": "dev-add-normalizer",
"consolidation/annotated-command": "^2.4",
"consolidation/output-formatters": "^3.1.10",
"symfony/yaml": "~2.3|^3",
Expand Down
15 changes: 13 additions & 2 deletions src/Commands/generate/Helper/InputPreprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function preprocess(array &$questions)
// Module related generators.
if ($destination == 'modules/%') {
$modules = [];
// @todo - For better UX, match on both labels and machine names.
$moduleHandler = \Drupal::moduleHandler();
foreach ($moduleHandler->getModuleList() as $machine_name => $module) {
$modules[$machine_name] = $moduleHandler->getName($machine_name);
Expand All @@ -55,7 +54,10 @@ public function preprocess(array &$questions)
$questions['machine_name'][3] = array_keys($modules);

if (isset($questions['name'])) {
$questions['name'][3] = array_values($modules);
// Set autocomplete values and a normalizer to change from machine_name to label.
$questions['name'][3] = $modules;
$questions['name'][5] = [$this, 'machineToLabel'];

$questions['machine_name'][1] = function ($vars) use ($modules) {
$machine_name = array_search($vars['name'], $modules);
return $machine_name ?: Utils::human2machine($vars['name']);
Expand All @@ -71,11 +73,20 @@ public function preprocess(array &$questions)
$themes[$machine_name] = $theme->info['name'];
}
$questions['name'][3] = array_values($themes);

$questions['machine_name'][1] = function ($vars) use ($themes) {
$machine_name = array_search($vars['name'], $themes);
return $machine_name ?: Utils::human2machine($vars['name']);
};
$questions['machine_name'][3] = array_keys($themes);
}
}

public function machineToLabel($choice) {
$handler = \Drupal::moduleHandler();
if ($handler->moduleExists($choice)) {
return $handler->getName($choice);
}
return $choice;
}
}

0 comments on commit b716bd5

Please sign in to comment.