5 * Contains \Drupal\Console\Command\Generate\PluginCKEditorButtonCommand.
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 Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Generator\PluginCKEditorButtonGenerator;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Core\Utils\ChainQueue;
20 use Drupal\Console\Extension\Manager;
21 use Drupal\Console\Core\Utils\StringConverter;
23 class PluginCKEditorButtonCommand extends Command
27 use ConfirmationTrait;
33 protected $chainQueue;
37 * @var PluginCKEditorButtonGenerator
44 protected $extensionManager;
47 * @var StringConverter
49 protected $stringConverter;
53 * PluginCKEditorButtonCommand constructor.
55 * @param ChainQueue $chainQueue
56 * @param PluginCKEditorButtonGenerator $generator
57 * @param Manager $extensionManager
58 * @param StringConverter $stringConverter
60 public function __construct(
61 ChainQueue $chainQueue,
62 PluginCKEditorButtonGenerator $generator,
63 Manager $extensionManager,
64 StringConverter $stringConverter
66 $this->chainQueue = $chainQueue;
67 $this->generator = $generator;
68 $this->extensionManager = $extensionManager;
69 $this->stringConverter = $stringConverter;
70 parent::__construct();
73 protected function configure()
76 ->setName('generate:plugin:ckeditorbutton')
77 ->setDescription($this->trans('commands.generate.plugin.ckeditorbutton.description'))
78 ->setHelp($this->trans('commands.generate.plugin.ckeditorbutton.help'))
82 InputOption::VALUE_REQUIRED,
83 $this->trans('commands.common.options.module')
88 InputOption::VALUE_REQUIRED,
89 $this->trans('commands.generate.plugin.ckeditorbutton.options.class')
94 InputOption::VALUE_REQUIRED,
95 $this->trans('commands.generate.plugin.ckeditorbutton.options.label')
100 InputOption::VALUE_REQUIRED,
101 $this->trans('commands.generate.plugin.ckeditorbutton.options.plugin-id')
106 InputOption::VALUE_REQUIRED,
107 $this->trans('commands.generate.plugin.ckeditorbutton.options.button-name')
112 InputOption::VALUE_REQUIRED,
113 $this->trans('commands.generate.plugin.ckeditorbutton.options.button-icon-path')
120 protected function execute(InputInterface $input, OutputInterface $output)
122 $io = new DrupalStyle($input, $output);
124 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
125 if (!$this->confirmGeneration($io)) {
129 $module = $input->getOption('module');
130 $class_name = $input->getOption('class');
131 $label = $input->getOption('label');
132 $plugin_id = $input->getOption('plugin-id');
133 $button_name = $input->getOption('button-name');
134 $button_icon_path = $input->getOption('button-icon-path');
138 ->generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path);
140 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);
145 protected function interact(InputInterface $input, OutputInterface $output)
147 $io = new DrupalStyle($input, $output);
150 $module = $input->getOption('module');
152 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
153 $module = $this->moduleQuestion($io);
154 $input->setOption('module', $module);
158 $class_name = $input->getOption('class');
160 $class_name = $io->ask(
161 $this->trans('commands.generate.plugin.ckeditorbutton.questions.class'),
162 'DefaultCKEditorButton'
164 $input->setOption('class', $class_name);
168 $label = $input->getOption('label');
171 $this->trans('commands.generate.plugin.ckeditorbutton.questions.label'),
172 $this->stringConverter->camelCaseToHuman($class_name)
174 $input->setOption('label', $label);
177 // --plugin-id option
178 $plugin_id = $input->getOption('plugin-id');
180 $plugin_id = $io->ask(
181 $this->trans('commands.generate.plugin.ckeditorbutton.questions.plugin-id'),
182 $this->stringConverter->camelCaseToLowerCase($label)
184 $input->setOption('plugin-id', $plugin_id);
187 // --button-name option
188 $button_name = $input->getOption('button-name');
190 $button_name = $io->ask(
191 $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'),
192 $this->stringConverter->anyCaseToUcFirst($plugin_id)
194 $input->setOption('button-name', $button_name);
197 // --button-icon-path option
198 $button_icon_path = $input->getOption('button-icon-path');
199 if (!$button_icon_path) {
200 $button_icon_path = $io->ask(
201 $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'),
202 drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png'
204 $input->setOption('button-icon-path', $button_icon_path);