validator = $validator; $this->generator = $generator; $this->extensionManager = $extensionManager; parent::__construct(); } protected function configure() { $this ->setName('generate:entity:bundle') ->setDescription($this->trans('commands.generate.entity.bundle.description')) ->setHelp($this->trans('commands.generate.entity.bundle.help')) ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) ->addOption( 'bundle-name', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.entity.bundle.options.bundle-name') ) ->addOption( 'bundle-title', null, InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.entity.bundle.options.bundle-title') ); } /** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration if (!$this->confirmGeneration($io)) { return 1; } $module = $input->getOption('module'); $bundleName = $input->getOption('bundle-name'); $bundleTitle = $input->getOption('bundle-title'); $generator = $this->generator; //TODO: // $generator->setLearning($learning); $generator->generate($module, $bundleName, $bundleTitle); return 0; } /** * {@inheritdoc} */ protected function interact(InputInterface $input, OutputInterface $output) { $io = new DrupalStyle($input, $output); // --module option $module = $input->getOption('module'); if (!$module) { // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion $module = $this->moduleQuestion($io); $input->setOption('module', $module); } // --bundle-name option $bundleName = $input->getOption('bundle-name'); if (!$bundleName) { $bundleName = $io->ask( $this->trans('commands.generate.entity.bundle.questions.bundle-name'), 'default', function ($bundleName) { return $this->validator->validateClassName($bundleName); } ); $input->setOption('bundle-name', $bundleName); } // --bundle-title option $bundleTitle = $input->getOption('bundle-title'); if (!$bundleTitle) { $bundleTitle = $io->ask( $this->trans('commands.generate.entity.bundle.questions.bundle-title'), 'default', function ($bundle_title) { return $this->validator->validateBundleTitle($bundle_title); } ); $input->setOption('bundle-title', $bundleTitle); } } }