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:entity:content] Improve command options #3371

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
10 changes: 5 additions & 5 deletions src/Command/Generate/EntityCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ function ($entityName) {
// --base-path option
$base_path = $input->getOption('base-path');
if (!$base_path) {
$base_path = $this->getDefaultBasePath();
$base_path = $io->ask(
$this->trans('commands.'.$commandKey.'.questions.base-path'),
$this->getDefaultBasePath()
);
}
$base_path = $io->ask(
$this->trans('commands.'.$commandKey.'.questions.base-path'),
$base_path
);

if (substr($base_path, 0, 1) !== '/') {
// Base path must start with a leading '/'.
$base_path = '/' . $base_path;
Expand Down
58 changes: 37 additions & 21 deletions src/Command/Generate/EntityContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ protected function configure()
$this->addOption(
'has-bundles',
null,
InputOption::VALUE_NONE,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.entity.content.options.has-bundles')
);

$this->addOption(
'is-translatable',
null,
InputOption::VALUE_NONE,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.entity.content.options.is-translatable')
);

$this->addOption(
'revisionable',
null,
InputOption::VALUE_NONE,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.entity.content.options.revisionable')
);
}
Expand All @@ -108,29 +108,45 @@ protected function interact(InputInterface $input, OutputInterface $output)
parent::interact($input, $output);
$io = new DrupalStyle($input, $output);

// --bundle-of option
$bundle_of = $input->getOption('has-bundles');
if (!$bundle_of) {
$bundle_of = $io->confirm(
$this->trans('commands.generate.entity.content.questions.has-bundles'),
false
);
$input->setOption('has-bundles', $bundle_of);
}
// --has-bundles option.
$this->interactBooleanQuestion($input, $io, 'has-bundles', false);

// --is-translatable option
$is_translatable = $io->confirm(
$this->trans('commands.generate.entity.content.questions.is-translatable'),
true
);
$input->setOption('is-translatable', $is_translatable);
$this->interactBooleanQuestion($input, $io, 'is-translatable', true);

// --revisionable option
$revisionable = $io->confirm(
$this->trans('commands.generate.entity.content.questions.revisionable'),
true
$this->interactBooleanQuestion($input, $io, 'revisionable', true);
}

/**
* Helper to ask for boolean option.
*
* @param InputInterface $input
* @param DrupalStyle $io
* @param string $option
* @param bool $default
*/
protected function interactBooleanQuestion(InputInterface $input, DrupalStyle $io, $option, $default = true) {
// If no option flag has been set, we ask for manual input.
if (!$input->hasOption($option)) {
$set_value = $io->confirm(
$this->trans('commands.generate.entity.content.questions.' . $option),
(bool) $default
);
$input->setOption('revisionable', $revisionable);
}
else {
$value = $input->getOption($option);
// When the value of the option is "0" or "false" the option is disabled.
if (isset($value) && $value === "0" || strtolower($value) === "false") {
$set_value = FALSE;
}
// ... otherwise the option is enabled.
else {
$set_value = TRUE;
}
}

$input->setOption($option, $set_value);
}

/**
Expand Down