From 08c0b98a44d187dda886013153689e02408b070e Mon Sep 17 00:00:00 2001 From: Johannes Haseitl Date: Mon, 3 Jul 2017 10:14:43 +0200 Subject: [PATCH 1/2] Fix base-path option --- src/Command/Generate/EntityCommand.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Command/Generate/EntityCommand.php b/src/Command/Generate/EntityCommand.php index d5869edc7..7b6802362 100644 --- a/src/Command/Generate/EntityCommand.php +++ b/src/Command/Generate/EntityCommand.php @@ -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; From 303a8a5cc4933006d5253102681c7cafaca32c19 Mon Sep 17 00:00:00 2001 From: Johannes Haseitl Date: Mon, 3 Jul 2017 10:15:24 +0200 Subject: [PATCH 2/2] Let is-translatable, has-bundles and revisionable be disabled via cli --- src/Command/Generate/EntityContentCommand.php | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/Command/Generate/EntityContentCommand.php b/src/Command/Generate/EntityContentCommand.php index 187cd3737..02f6553bb 100644 --- a/src/Command/Generate/EntityContentCommand.php +++ b/src/Command/Generate/EntityContentCommand.php @@ -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') ); } @@ -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); } /**