Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module machine names to autocomplete for Module label #2802

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
"chi-teck/drupal-code-generator": "dev-add-normalizer",
"consolidation/annotated-command": "^2.4",
"consolidation/output-formatters": "^3.1.10",
"symfony/yaml": "~2.3|^3",
Expand Down
16 changes: 14 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,21 @@ 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;
}
}