Skip to content

Commit

Permalink
Merge pull request #307 from jmolivas/add-translation-to-rest-resourc…
Browse files Browse the repository at this point in the history
…e-command

Add translation to rest resource command
  • Loading branch information
jmolivas committed Jan 15, 2015
2 parents bb55dee + 1999b64 commit 374afff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
application:
name: Drupal Console
version: 0.6.2
version: 0.6.3
environment: prod
language: en
21 changes: 21 additions & 0 deletions config/translations/console.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,27 @@ commands:
label: Enter the plugin label
plugin-id: Enter the plugin id
description: Enter the plugin Description
rest:
resource:
description: Generate plugin rest resource
help: The <info>generate:plugin:rest:resource</info> command helps you generate a new rest resource.
welcome: Welcome to the Drupal Plugin Rest Resource generator
options:
module: common.options.module
class-name: Plugin Rest Resource class
plugin-id: Plugin Rest Resource id
plugin-label: Plugin Rest Resource Label
plugin-url: Plugin Rest Resource URL
plugin-states: Plugin Rest Resource States
questions:
module: common.questions.module
class-name: Enter the plugin rest resource name
plugin-id: Enter the plugin rest resource id
plugin-label: Enter the plugin rest resource label
plugin-url: Enter the plugin rest resource url
plugin-states: Please select what REST States implement in your resource (GET is selected by default)
messages:
selected-states: States selected
service:
description: Generate service
help: The <info>generate:service</info> command helps you generate a new service.
Expand Down
43 changes: 21 additions & 22 deletions src/Command/GeneratorPluginRestResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,33 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\AppConsole\Generator\PluginBlockGenerator;
use Drupal\AppConsole\Command\Helper\ServicesTrait;
use Drupal\AppConsole\Command\Helper\ModuleTrait;
use Drupal\AppConsole\Command\Helper\FormTrait;
use Symfony\Component\Console\Question\ChoiceQuestion;
use Drupal\AppConsole\Generator\PluginRestResourceGenerator;
use Drupal\AppConsole\Command\Helper\ConfirmationTrait;

class GeneratorPluginRestResourceCommand extends GeneratorCommand
{
use ServicesTrait;
use ModuleTrait;
use FormTrait;
use ConfirmationTrait;

protected function configure()
{
$this
->setDefinition(array(
new InputOption('module','',InputOption::VALUE_REQUIRED, 'The name of the module'),
new InputOption('class-name','',InputOption::VALUE_OPTIONAL, 'Plugin Rest Resource class'),
new InputOption('plugin-id','',InputOption::VALUE_OPTIONAL, 'Plugin Rest Resource id'),
new InputOption('plugin-label','',InputOption::VALUE_OPTIONAL, 'Plugin Rest Resource Label'),
new InputOption('plugin-url','',InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Plugin Rest Resource URL'),
new InputOption('plugin-states','',InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Plugin Rest Resource States')
))
->setDescription('Generate plugin rest resource')
->setHelp('The <info>generate:plugin:rest:resource</info> command helps you generate a new rest resource.')
->setDefinition([
new InputOption('module','',InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')),
new InputOption('class-name','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.rest.resource.options.class-name')),
new InputOption('plugin-id','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.rest.resource.options.plugin-id')),
new InputOption('plugin-label','',InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.rest.resource.options.plugin-label')),
new InputOption('plugin-url','',InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.generate.plugin.rest.resource.options.plugin-url')),
new InputOption('plugin-states','',InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, $this->trans('commands.generate.plugin.rest.resource.options.plugin-states'))
])
->setDescription($this->trans('commands.generate.plugin.rest.resource.description'))
->setHelp($this->trans('commands.generate.plugin.rest.resource.help'))
->setName('generate:plugin:rest:resource');
}

Expand All @@ -45,11 +46,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$dialog = $this->getDialogHelper();

if ($input->isInteractive()) {
if (!$dialog->askConfirmation($output, $dialog->getQuestion('Do you confirm generation', 'yes', '?'), true)) {
$output->writeln('<error>Command aborted</error>');
return 1;
}
// @see use Drupal\AppConsole\Command\Helper\ConfirmationTrait::confirmationQuestion
if ($this->confirmationQuestion($input, $output, $dialog)) {
return;
}

$module = $input->getOption('module');
Expand Down Expand Up @@ -81,7 +80,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
if (!$class_name) {
$class_name = $dialog->ask(
$output,
$dialog->getQuestion('Enter the plugin rest resource name', 'DefaultRestResource'),
$dialog->getQuestion($this->trans('commands.generate.plugin.rest.resource.questions.class-name'), 'DefaultRestResource'),
'DefaultRestResource'
);
}
Expand All @@ -94,7 +93,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
if (!$plugin_id) {
$plugin_id = $dialog->ask(
$output,
$dialog->getQuestion('Enter the plugin rest resource id', $machine_name),
$dialog->getQuestion($this->trans('commands.generate.plugin.rest.resource.questions.plugin-id'), $machine_name),
$machine_name
);
}
Expand All @@ -105,7 +104,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
if (!$plugin_label) {
$plugin_label = $dialog->ask(
$output,
$dialog->getQuestion('Enter the plugin rest resource label',$machine_name),
$dialog->getQuestion($this->trans('commands.generate.plugin.rest.resource.questions.plugin-label'),$machine_name),
$machine_name
);
}
Expand All @@ -116,7 +115,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
if (!$plugin_url) {
$plugin_url = $dialog->ask(
$output,
$dialog->getQuestion('Enter the plugin rest resource url',$machine_name),
$dialog->getQuestion($this->trans('commands.generate.plugin.rest.resource.questions.plugin-url'),$machine_name),
$machine_name
);
}
Expand All @@ -129,14 +128,14 @@ protected function interact(InputInterface $input, OutputInterface $output)
$questionHelper = $this->getQuestionHelper();

$question = new ChoiceQuestion(
'Please select what REST States implement in your resource (GET is selected by default)',
$this->trans('commands.generate.plugin.rest.resource.questions.plugin-states'),
array('GET', 'PUT', 'POST', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'),
'0'
);

$question->setMultiselect(true);
$plugin_states = $questionHelper->ask($input, $output, $question);
$output->writeln('States selected: ' . implode(', ', $plugin_states));
$output->writeln($this->trans('commands.generate.plugin.rest.resource.messages.selected-states') . ' ' . implode(', ', $plugin_states));

$input->setOption('plugin-states', $plugin_states);
}
Expand Down

0 comments on commit 374afff

Please sign in to comment.