From 923ba31ce7418a73b256dd394ab25fc8512f1438 Mon Sep 17 00:00:00 2001 From: Harold Date: Mon, 13 May 2019 12:04:01 -0600 Subject: [PATCH 1/2] [generate:plugin:block] Use | to separate inputs --- src/Command/Shared/ArrayInputTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/Shared/ArrayInputTrait.php b/src/Command/Shared/ArrayInputTrait.php index c4615304a..2cc4ee583 100644 --- a/src/Command/Shared/ArrayInputTrait.php +++ b/src/Command/Shared/ArrayInputTrait.php @@ -26,7 +26,7 @@ public function explodeInlineArray($inlineInputs) { $inputs = []; foreach ($inlineInputs as $inlineInput) { - $explodeInput = explode(',', $inlineInput); + $explodeInput = explode('|', $inlineInput); $parameters = []; foreach ($explodeInput as $inlineParameter) { $inlineParameter = trim($inlineParameter); From 3334d25348f50335fe52619779c23edcdd387888 Mon Sep 17 00:00:00 2001 From: Harold Date: Mon, 13 May 2019 17:14:24 -0600 Subject: [PATCH 2/2] [console] Replace , by | in commands with fields as array --- src/Command/Generate/ComposerCommand.php | 6 ++ src/Command/Generate/ControllerCommand.php | 11 ++- .../Generate/PluginCKEditorButtonCommand.php | 75 ++++++++++--------- .../Generate/PluginMigrateSourceCommand.php | 4 +- src/Command/Shared/ArrayInputTrait.php | 5 ++ 5 files changed, 63 insertions(+), 38 deletions(-) diff --git a/src/Command/Generate/ComposerCommand.php b/src/Command/Generate/ComposerCommand.php index 5d21ece45..2e4180204 100644 --- a/src/Command/Generate/ComposerCommand.php +++ b/src/Command/Generate/ComposerCommand.php @@ -276,6 +276,8 @@ protected function interact(InputInterface $input, OutputInterface $output) $this->getIo()->newLine(2); $input->setOption('authors', $authorItems); } + } else { + $input->setOption('authors', $this->explodeInlineArray($authors)); } // --support option @@ -326,6 +328,8 @@ protected function interact(InputInterface $input, OutputInterface $output) $this->getIo()->newLine(2); $input->setOption('support', $supportItems); } + } else { + $input->setOption('support', $this->explodeInlineArray($support)); } // --required option @@ -363,6 +367,8 @@ protected function interact(InputInterface $input, OutputInterface $output) } $input->setOption('required', $requiredItems); } + } else { + $input->setOption('required', $this->explodeInlineArray($required)); } } diff --git a/src/Command/Generate/ControllerCommand.php b/src/Command/Generate/ControllerCommand.php index e32823357..b3463dfed 100644 --- a/src/Command/Generate/ControllerCommand.php +++ b/src/Command/Generate/ControllerCommand.php @@ -7,6 +7,7 @@ namespace Drupal\Console\Command\Generate; +use Drupal\Console\Command\Shared\ArrayInputTrait; use Drupal\Console\Command\Shared\ConfirmationTrait; use Drupal\Console\Command\Shared\ModuleTrait; use Drupal\Console\Command\Shared\ServicesTrait; @@ -24,6 +25,7 @@ class ControllerCommand extends Command { + use ArrayInputTrait; use ModuleTrait; use ServicesTrait; use ConfirmationTrait; @@ -140,9 +142,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $routes = $input->getOption('routes'); $test = $input->getOption('test'); $services = $input->getOption('services'); + $noInteraction = $input->getOption('no-interaction'); - $routes = $this->inlineValueAsArray($routes); - $input->setOption('routes', $routes); + // Parse nested data. + if ($noInteraction) { + $routes = $this->explodeInlineArray($routes); + } // @see use Drupal\Console\Command\Shared\ServicesTrait::buildServices $build_services = $this->buildServices($services); @@ -279,6 +284,8 @@ function ($path) use ($routes) { ]; } $input->setOption('routes', $routes); + } else { + $input->setOption('routes', $this->explodeInlineArray($routes)); } // --test option diff --git a/src/Command/Generate/PluginCKEditorButtonCommand.php b/src/Command/Generate/PluginCKEditorButtonCommand.php index f683fdb58..cbd56bb37 100644 --- a/src/Command/Generate/PluginCKEditorButtonCommand.php +++ b/src/Command/Generate/PluginCKEditorButtonCommand.php @@ -187,42 +187,47 @@ function ($class_name) { $input->setOption('plugin-id', $plugin_id); } - $buttons = []; - while (true) { - $this->getIo()->newLine(2); - $this->getIo()->comment($this->trans('commands.generate.plugin.ckeditorbutton.options.button-properties')); - // --button-name option - $buttonName = $this->getIo()->ask( - $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'), - $this->stringConverter->anyCaseToUcFirst($label) - ); - - $buttonLabel = $this->getIo()->ask( - $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-label'), - $label - ); - - $buttonIcon = $this->getIo()->ask( - $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'), - drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png' - ); - - array_push( - $buttons, - [ - 'name' => $buttonName, - 'label' => $buttonLabel, - 'icon' => $buttonIcon, - ] - ); - - if (!$this->getIo()->confirm( - $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-add'), - true - ) - ) { - break; + // --inputs option + $buttons = $input->getOption('buttons'); + if (!$buttons) { + while (true) { + $this->getIo()->newLine(2); + $this->getIo()->comment($this->trans('commands.generate.plugin.ckeditorbutton.options.button-properties')); + // --button-name option + $buttonName = $this->getIo()->ask( + $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'), + $this->stringConverter->anyCaseToUcFirst($label) + ); + + $buttonLabel = $this->getIo()->ask( + $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-label'), + $label + ); + + $buttonIcon = $this->getIo()->ask( + $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'), + drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png' + ); + + array_push( + $buttons, + [ + 'name' => $buttonName, + 'label' => $buttonLabel, + 'icon' => $buttonIcon, + ] + ); + + if (!$this->getIo()->confirm( + $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-add'), + true + ) + ) { + break; + } } + } else { + $buttons= $this->explodeInlineArray($buttons); } $input->setOption('buttons', $buttons); } diff --git a/src/Command/Generate/PluginMigrateSourceCommand.php b/src/Command/Generate/PluginMigrateSourceCommand.php index d8739eaae..19ed5b0e4 100644 --- a/src/Command/Generate/PluginMigrateSourceCommand.php +++ b/src/Command/Generate/PluginMigrateSourceCommand.php @@ -262,7 +262,9 @@ function ($class) { 'description' => $description, ]; } - $input->setOption('fields', $fields); + } else { + $fields = $this->explodeInlineArray($fields); } + $input->setOption('fields', $fields); } } diff --git a/src/Command/Shared/ArrayInputTrait.php b/src/Command/Shared/ArrayInputTrait.php index 2cc4ee583..563c73cd0 100644 --- a/src/Command/Shared/ArrayInputTrait.php +++ b/src/Command/Shared/ArrayInputTrait.php @@ -37,6 +37,11 @@ public function explodeInlineArray($inlineInputs) $parameters[$key] = $value; } } + + // Remove options data if type isn't in the list of allowed types + if($parameters['options'] && !in_array($parameters['type'], ['checkboxes', 'radios', 'select'])){ + $parameters['options'] = []; + } $inputs[] = $parameters; }