extensionManager = $extensionManager; $this->generator = $generator; $this->stringConverter = $stringConverter; $this->validator = $validator; $this->chainQueue = $chainQueue; parent::__construct(); } protected function configure() { $this ->setName('generate:plugin:imageformatter') ->setDescription($this->trans('commands.generate.plugin.imageformatter.description')) ->setHelp($this->trans('commands.generate.plugin.imageformatter.help')) ->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module')) ->addOption( 'class', '', InputOption::VALUE_REQUIRED, $this->trans('commands.generate.plugin.imageformatter.options.class') ) ->addOption( 'label', '', InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.imageformatter.options.label') ) ->addOption( 'plugin-id', '', InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.plugin.imageformatter.options.plugin-id') ); } /** * {@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; } $module = $input->getOption('module'); $class_name = $input->getOption('class'); $label = $input->getOption('label'); $plugin_id = $input->getOption('plugin-id'); $this->generator->generate($module, $class_name, $label, $plugin_id); $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']); } 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); // --class option $class_name = $input->getOption('class'); if (!$class_name) { $class_name = $io->ask( $this->trans('commands.generate.plugin.imageformatter.questions.class'), 'ExampleImageFormatter' ); $input->setOption('class', $class_name); } // --label option $label = $input->getOption('label'); if (!$label) { $label = $io->ask( $this->trans('commands.generate.plugin.imageformatter.questions.label'), $this->stringConverter->camelCaseToHuman($class_name) ); $input->setOption('label', $label); } // --plugin-id option $plugin_id = $input->getOption('plugin-id'); if (!$plugin_id) { $plugin_id = $io->ask( $this->trans('commands.generate.plugin.imageformatter.questions.plugin-id'), $this->stringConverter->camelCaseToUnderscore($class_name) ); $input->setOption('plugin-id', $plugin_id); } } }