5 * Contains \Drupal\Console\Command\Generate\PluginCKEditorButtonCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Utils\Validator;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Console\Core\Command\Command;
15 use Drupal\Console\Generator\PluginCKEditorButtonGenerator;
16 use Drupal\Console\Command\Shared\ModuleTrait;
17 use Drupal\Console\Command\Shared\ConfirmationTrait;
18 use Drupal\Console\Core\Utils\ChainQueue;
19 use Drupal\Console\Extension\Manager;
20 use Drupal\Console\Core\Utils\StringConverter;
22 class PluginCKEditorButtonCommand extends Command
25 use ConfirmationTrait;
30 protected $chainQueue;
34 * @var PluginCKEditorButtonGenerator
41 protected $extensionManager;
44 * @var StringConverter
46 protected $stringConverter;
55 * PluginCKEditorButtonCommand constructor.
57 * @param ChainQueue $chainQueue
58 * @param PluginCKEditorButtonGenerator $generator
59 * @param Manager $extensionManager
60 * @param StringConverter $stringConverter
61 * @param Validator $validator
63 public function __construct(
64 ChainQueue $chainQueue,
65 PluginCKEditorButtonGenerator $generator,
66 Manager $extensionManager,
67 StringConverter $stringConverter,
70 $this->chainQueue = $chainQueue;
71 $this->generator = $generator;
72 $this->extensionManager = $extensionManager;
73 $this->stringConverter = $stringConverter;
74 $this->validator = $validator;
75 parent::__construct();
78 protected function configure()
81 ->setName('generate:plugin:ckeditorbutton')
82 ->setDescription($this->trans('commands.generate.plugin.ckeditorbutton.description'))
83 ->setHelp($this->trans('commands.generate.plugin.ckeditorbutton.help'))
87 InputOption::VALUE_REQUIRED,
88 $this->trans('commands.common.options.module')
93 InputOption::VALUE_REQUIRED,
94 $this->trans('commands.generate.plugin.ckeditorbutton.options.class')
99 InputOption::VALUE_REQUIRED,
100 $this->trans('commands.generate.plugin.ckeditorbutton.options.label')
105 InputOption::VALUE_REQUIRED,
106 $this->trans('commands.generate.plugin.ckeditorbutton.options.plugin-id')
111 InputOption::VALUE_REQUIRED,
112 $this->trans('commands.generate.plugin.ckeditorbutton.options.button-name')
117 InputOption::VALUE_REQUIRED,
118 $this->trans('commands.generate.plugin.ckeditorbutton.options.button-icon-path')
119 )->setAliases(['gpc']);
125 protected function execute(InputInterface $input, OutputInterface $output)
127 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
128 if (!$this->confirmOperation()) {
132 $module = $input->getOption('module');
133 $class_name = $this->validator->validateClassName($input->getOption('class'));
134 $label = $input->getOption('label');
135 $plugin_id = $input->getOption('plugin-id');
136 $button_name = $input->getOption('button-name');
137 $button_icon_path = $input->getOption('button-icon-path');
139 $this->generator->generate([
141 'class_name' => $class_name,
143 'plugin_id' => $plugin_id,
144 'button_name' => $button_name,
145 'button_icon_path' => $button_icon_path,
148 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);
153 protected function interact(InputInterface $input, OutputInterface $output)
156 $module = $this->getModuleOption();
159 $class_name = $input->getOption('class');
161 $class_name = $this->getIo()->ask(
162 $this->trans('commands.generate.plugin.ckeditorbutton.questions.class'),
163 'DefaultCKEditorButton',
164 function ($class_name) {
165 return $this->validator->validateClassName($class_name);
168 $input->setOption('class', $class_name);
172 $label = $input->getOption('label');
174 $label = $this->getIo()->ask(
175 $this->trans('commands.generate.plugin.ckeditorbutton.questions.label'),
176 $this->stringConverter->camelCaseToHuman($class_name)
178 $input->setOption('label', $label);
181 // --plugin-id option
182 $plugin_id = $input->getOption('plugin-id');
184 $plugin_id = $this->getIo()->ask(
185 $this->trans('commands.generate.plugin.ckeditorbutton.questions.plugin-id'),
186 $this->stringConverter->camelCaseToLowerCase($label)
188 $input->setOption('plugin-id', $plugin_id);
191 // --button-name option
192 $button_name = $input->getOption('button-name');
194 $button_name = $this->getIo()->ask(
195 $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'),
196 $this->stringConverter->anyCaseToUcFirst($plugin_id)
198 $input->setOption('button-name', $button_name);
201 // --button-icon-path option
202 $button_icon_path = $input->getOption('button-icon-path');
203 if (!$button_icon_path) {
204 $button_icon_path = $this->getIo()->ask(
205 $this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'),
206 drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png'
208 $input->setOption('button-icon-path', $button_icon_path);