5 * Contains \Drupal\Console\Command\Generate\PluginImageEffectCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Generator\PluginImageEffectGenerator;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Command\Shared\ConfirmationTrait;
16 use Symfony\Component\Console\Command\Command;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Command\Shared\CommandTrait;
20 use Drupal\Console\Core\Utils\StringConverter;
21 use Drupal\Console\Core\Utils\ChainQueue;
24 * Class PluginImageEffectCommand
26 * @package Drupal\Console\Command\Generate
28 class PluginImageEffectCommand extends Command
31 use ConfirmationTrait;
37 protected $extensionManager;
40 * @var PluginImageEffectGenerator
45 * @var StringConverter
47 protected $stringConverter;
52 protected $chainQueue;
56 * PluginImageEffectCommand constructor.
58 * @param Manager $extensionManager
59 * @param PluginImageEffectGenerator $generator
60 * @param StringConverter $stringConverter
61 * @param ChainQueue $chainQueue
63 public function __construct(
64 Manager $extensionManager,
65 PluginImageEffectGenerator $generator,
66 StringConverter $stringConverter,
67 ChainQueue $chainQueue
69 $this->extensionManager = $extensionManager;
70 $this->generator = $generator;
71 $this->stringConverter = $stringConverter;
72 $this->chainQueue = $chainQueue;
73 parent::__construct();
76 protected function configure()
79 ->setName('generate:plugin:imageeffect')
80 ->setDescription($this->trans('commands.generate.plugin.imageeffect.description'))
81 ->setHelp($this->trans('commands.generate.plugin.imageeffect.help'))
82 ->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
86 InputOption::VALUE_REQUIRED,
87 $this->trans('commands.generate.plugin.imageeffect.options.class')
92 InputOption::VALUE_OPTIONAL,
93 $this->trans('commands.generate.plugin.imageeffect.options.label')
98 InputOption::VALUE_OPTIONAL,
99 $this->trans('commands.generate.plugin.imageeffect.options.plugin-id')
104 InputOption::VALUE_OPTIONAL,
105 $this->trans('commands.generate.plugin.imageeffect.options.description')
112 protected function execute(InputInterface $input, OutputInterface $output)
114 $io = new DrupalStyle($input, $output);
116 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
117 if (!$this->confirmGeneration($io)) {
121 $module = $input->getOption('module');
122 $class_name = $input->getOption('class');
123 $label = $input->getOption('label');
124 $plugin_id = $input->getOption('plugin-id');
125 $description = $input->getOption('description');
127 $this->generator->generate($module, $class_name, $label, $plugin_id, $description);
129 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
132 protected function interact(InputInterface $input, OutputInterface $output)
134 $io = new DrupalStyle($input, $output);
137 $module = $input->getOption('module');
139 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
140 $module = $this->moduleQuestion($io);
141 $input->setOption('module', $module);
145 $class_name = $input->getOption('class');
147 $class_name = $io->ask(
148 $this->trans('commands.generate.plugin.imageeffect.questions.class'),
151 $input->setOption('class', $class_name);
155 $label = $input->getOption('label');
158 $this->trans('commands.generate.plugin.imageeffect.questions.label'),
159 $this->stringConverter->camelCaseToHuman($class_name)
161 $input->setOption('label', $label);
164 // --plugin-id option
165 $plugin_id = $input->getOption('plugin-id');
167 $plugin_id = $io->ask(
168 $this->trans('commands.generate.plugin.imageeffect.questions.plugin-id'),
169 $this->stringConverter->camelCaseToUnderscore($class_name)
171 $input->setOption('plugin-id', $plugin_id);
174 // --description option
175 $description = $input->getOption('description');
177 $description = $io->ask(
178 $this->trans('commands.generate.plugin.imageeffect.questions.description'),
181 $input->setOption('description', $description);