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

[generate:plugin:block] Use | to separate inputs #4032

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Command/Generate/ComposerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -363,6 +367,8 @@ protected function interact(InputInterface $input, OutputInterface $output)
}
$input->setOption('required', $requiredItems);
}
} else {
$input->setOption('required', $this->explodeInlineArray($required));
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/Command/Generate/ControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,6 +25,7 @@

class ControllerCommand extends Command
{
use ArrayInputTrait;
use ModuleTrait;
use ServicesTrait;
use ConfirmationTrait;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -279,6 +284,8 @@ function ($path) use ($routes) {
];
}
$input->setOption('routes', $routes);
} else {
$input->setOption('routes', $this->explodeInlineArray($routes));
}

// --test option
Expand Down
75 changes: 40 additions & 35 deletions src/Command/Generate/PluginCKEditorButtonCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Generate/PluginMigrateSourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ function ($class) {
'description' => $description,
];
}
$input->setOption('fields', $fields);
} else {
$fields = $this->explodeInlineArray($fields);
}
$input->setOption('fields', $fields);
}
}
7 changes: 6 additions & 1 deletion src/Command/Shared/ArrayInputTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}

Expand Down