namespace Drupal\Console\Command\Generate;
+use Drupal\Console\Utils\Validator;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Generator\PluginCKEditorButtonGenerator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Console\Extension\Manager;
use Drupal\Console\Core\Utils\StringConverter;
class PluginCKEditorButtonCommand extends Command
{
- use CommandTrait;
use ModuleTrait;
use ConfirmationTrait;
-
/**
* @var ChainQueue
*/
*/
protected $stringConverter;
+ /**
+ * @var Validator
+ */
+ protected $validator;
+
/**
* PluginCKEditorButtonCommand constructor.
* @param PluginCKEditorButtonGenerator $generator
* @param Manager $extensionManager
* @param StringConverter $stringConverter
+ * @param Validator $validator
*/
public function __construct(
ChainQueue $chainQueue,
PluginCKEditorButtonGenerator $generator,
Manager $extensionManager,
- StringConverter $stringConverter
+ StringConverter $stringConverter,
+ Validator $validator
) {
$this->chainQueue = $chainQueue;
$this->generator = $generator;
$this->extensionManager = $extensionManager;
$this->stringConverter = $stringConverter;
+ $this->validator = $validator;
parent::__construct();
}
null,
InputOption::VALUE_REQUIRED,
$this->trans('commands.generate.plugin.ckeditorbutton.options.button-icon-path')
- );
+ )->setAliases(['gpc']);
}
/**
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $io = new DrupalStyle($input, $output);
-
- // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
- if (!$this->confirmGeneration($io)) {
+ // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
+ if (!$this->confirmOperation()) {
return 1;
}
$module = $input->getOption('module');
- $class_name = $input->getOption('class');
+ $class_name = $this->validator->validateClassName($input->getOption('class'));
$label = $input->getOption('label');
$plugin_id = $input->getOption('plugin-id');
$button_name = $input->getOption('button-name');
$button_icon_path = $input->getOption('button-icon-path');
- $this
- ->generator
- ->generate($module, $class_name, $label, $plugin_id, $button_name, $button_icon_path);
+ $this->generator->generate([
+ 'module' => $module,
+ 'class_name' => $class_name,
+ 'label' => $label,
+ 'plugin_id' => $plugin_id,
+ 'button_name' => $button_name,
+ 'button_icon_path' => $button_icon_path,
+ ]);
$this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);
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);
- }
+ $module = $this->getModuleOption();
// --class option
$class_name = $input->getOption('class');
if (!$class_name) {
- $class_name = $io->ask(
+ $class_name = $this->getIo()->ask(
$this->trans('commands.generate.plugin.ckeditorbutton.questions.class'),
- 'DefaultCKEditorButton'
+ 'DefaultCKEditorButton',
+ function ($class_name) {
+ return $this->validator->validateClassName($class_name);
+ }
);
$input->setOption('class', $class_name);
}
// --label option
$label = $input->getOption('label');
if (!$label) {
- $label = $io->ask(
+ $label = $this->getIo()->ask(
$this->trans('commands.generate.plugin.ckeditorbutton.questions.label'),
$this->stringConverter->camelCaseToHuman($class_name)
);
// --plugin-id option
$plugin_id = $input->getOption('plugin-id');
if (!$plugin_id) {
- $plugin_id = $io->ask(
+ $plugin_id = $this->getIo()->ask(
$this->trans('commands.generate.plugin.ckeditorbutton.questions.plugin-id'),
$this->stringConverter->camelCaseToLowerCase($label)
);
// --button-name option
$button_name = $input->getOption('button-name');
if (!$button_name) {
- $button_name = $io->ask(
+ $button_name = $this->getIo()->ask(
$this->trans('commands.generate.plugin.ckeditorbutton.questions.button-name'),
$this->stringConverter->anyCaseToUcFirst($plugin_id)
);
// --button-icon-path option
$button_icon_path = $input->getOption('button-icon-path');
if (!$button_icon_path) {
- $button_icon_path = $io->ask(
+ $button_icon_path = $this->getIo()->ask(
$this->trans('commands.generate.plugin.ckeditorbutton.questions.button-icon-path'),
drupal_get_path('module', $module) . '/js/plugins/' . $plugin_id . '/images/icon.png'
);