namespace Drupal\Console\Command\Shared;
-use Drupal\Console\Core\Style\DrupalStyle;
-
/**
* Class FormTrait
*
trait FormTrait
{
/**
- * @param DrupalStyle $io
- *
* @return mixed
*/
- public function formQuestion(DrupalStyle $io)
+ public function formQuestion()
{
- if ($io->confirm(
+ if ($this->getIo()->confirm(
$this->trans('commands.common.questions.inputs.confirm'),
true
)
}
sort($input_types);
+ $this->getIo()->writeln(sprintf(
+ $this->trans('commands.common.messages.available-field-types'), implode(', ', $input_types)
+ ));
+ $this->getIo()->newLine();
+
$inputs = [];
$fieldSets = [];
while (true) {
- $input_type = $io->choiceNoList(
+ $this->getIo()->comment($this->trans('commands.common.questions.inputs.new-field'));
+ $this->getIo()->newLine();
+ $input_type = $this->getIo()->choiceNoList(
$this->trans('commands.common.questions.inputs.type'),
$input_types,
- null,
+ '',
true
);
- if (empty($input_type)) {
+ if (empty($input_type) || is_numeric($input_type)) {
break;
}
// Label for input
$inputLabelMessage = $input_type == 'fieldset'?$this->trans('commands.common.questions.inputs.title'):$this->trans('commands.common.questions.inputs.label');
- $input_label = $io->ask(
+ $input_label = $this->getIo()->ask(
$inputLabelMessage,
null
);
// Machine name
$input_machine_name = $this->stringConverter->createMachineName($input_label);
- $input_name = $io->ask(
- $this->trans('commands.common.questions.inputs.machine_name'),
+ $input_name = $this->getIo()->ask(
+ $this->trans('commands.common.questions.inputs.machine-name'),
$input_machine_name
);
$inputFieldSet = '';
if ($input_type != 'fieldset' && !empty($fieldSets)) {
- $inputFieldSet = $io->choiceNoList(
+ $inputFieldSet = $this->getIo()->choiceNoList(
$this->trans('commands.common.questions.inputs.fieldset'),
$fieldSets,
- null,
+ '',
true
);
$maxlength = null;
$size = null;
if (in_array($input_type, ['textfield', 'password', 'password_confirm'])) {
- $maxlength = $io->ask(
- 'Maximum amount of characters',
+ $maxlength = $this->getIo()->ask(
+ $this->trans('commands.generate.form.questions.max-amount-characters'),
'64'
);
- $size = $io->ask(
- 'Width of the textfield (in characters)',
+ $size = $this->getIo()->ask(
+ $this->trans('commands.generate.form.questions.textfield-width-in-chars'),
'64'
);
}
if ($input_type == 'select') {
- $size = $io->ask(
- 'Size of multiselect box (in lines)',
+ $size = $this->getIo()->ask(
+ $this->trans('commands.generate.form.questions.multiselect-size-in-lines'),
'5'
);
}
$input_options = '';
if (in_array($input_type, ['checkboxes', 'radios', 'select'])) {
- $input_options = $io->ask(
- 'Input options separated by comma'
+ $input_options = $this->getIo()->ask(
+ $this->trans('commands.generate.form.questions.input-options')
);
}
}
// Description for input
- $input_description = $io->askEmpty(
+ $input_description = $this->getIo()->askEmpty(
$this->trans('commands.common.questions.inputs.description')
);
break;
}
if ($input_type != 'fieldset') {
- $default_value = $io->askEmpty(
+ $default_value = $this->getIo()->askEmpty(
$this->trans($question)
);
}
}
// Weight for input
- $weight = $io->ask(
+ $weight = $this->getIo()->ask(
$this->trans('commands.common.questions.inputs.weight'),
'0'
);
'fieldset' => $inputFieldSet,
]
);
+
+ $this->getIo()->newLine();
}
return $inputs;