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 Drupal\Console\Generator\PluginFieldWidgetGenerator;
use Drupal\Console\Command\Shared\ModuleTrait;
use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Console\Core\Command\Command;
use Drupal\Console\Extension\Manager;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
use Drupal\Console\Core\Utils\StringConverter;
use Drupal\Console\Core\Utils\ChainQueue;
use Drupal\Core\Field\FieldTypePluginManager;
{
use ModuleTrait;
use ConfirmationTrait;
- use CommandTrait;
/**
- * @var Manager
-*/
+ * @var Manager
+ */
protected $extensionManager;
/**
- * @var PluginFieldWidgetGenerator
-*/
+ * @var PluginFieldWidgetGenerator
+ */
protected $generator;
/**
protected $stringConverter;
/**
- * @var Validator
-*/
+ * @var Validator
+ */
protected $validator;
/**
- * @var FieldTypePluginManager
-*/
+ * @var FieldTypePluginManager
+ */
protected $fieldTypePluginManager;
/**
* @param Manager $extensionManager
* @param PluginFieldWidgetGenerator $generator
* @param StringConverter $stringConverter
+ * @param Validator $validator
* @param FieldTypePluginManager $fieldTypePluginManager
* @param ChainQueue $chainQueue
*/
Manager $extensionManager,
PluginFieldWidgetGenerator $generator,
StringConverter $stringConverter,
+ Validator $validator,
FieldTypePluginManager $fieldTypePluginManager,
ChainQueue $chainQueue
) {
$this->extensionManager = $extensionManager;
$this->generator = $generator;
$this->stringConverter = $stringConverter;
+ $this->validator = $validator;
$this->fieldTypePluginManager = $fieldTypePluginManager;
$this->chainQueue = $chainQueue;
parent::__construct();
->setName('generate:plugin:fieldwidget')
->setDescription($this->trans('commands.generate.plugin.fieldwidget.description'))
->setHelp($this->trans('commands.generate.plugin.fieldwidget.help'))
- ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
+ ->addOption(
+ 'module',
+ null,
+ InputOption::VALUE_REQUIRED,
+ $this->trans('commands.common.options.module')
+ )
->addOption(
'class',
null,
null,
InputOption::VALUE_OPTIONAL,
$this->trans('commands.generate.plugin.fieldwidget.options.field-type')
- );
+ )
+ ->setAliases(['gpfw']);
}
/**
*/
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');
$field_type = $input->getOption('field-type');
- $this->generator->generate($module, $class_name, $label, $plugin_id, $field_type);
+ $this->generator->generate([
+ 'module' => $module,
+ 'class_name' => $class_name,
+ 'label' => $label,
+ 'plugin_id' => $plugin_id,
+ 'field_type' => $field_type,
+ ]);
$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);
- }
+ $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.fieldwidget.questions.class'),
- 'ExampleFieldWidget'
+ 'ExampleFieldWidget',
+ function ($class_name) {
+ return $this->validator->validateClassName($class_name);
+ }
);
$input->setOption('class', $class_name);
}
// --plugin label option
$label = $input->getOption('label');
if (!$label) {
- $label = $io->ask(
+ $label = $this->getIo()->ask(
$this->trans('commands.generate.plugin.fieldwidget.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.fieldwidget.questions.plugin-id'),
$this->stringConverter->camelCaseToUnderscore($class_name)
);
}
}
- $field_type = $io->choice(
+ $field_type = $this->getIo()->choice(
$this->trans('commands.generate.plugin.fieldwidget.questions.field-type'),
$field_type_options
);