Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginFieldTypeCommand.php
index 5f33c3d7a89d0bfe972c6c36fa53f862524704fb..6cd79bc45b032384d996157e22dcbb70225b0c24 100644 (file)
@@ -7,16 +7,15 @@
 
 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\PluginFieldTypeGenerator;
 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;
@@ -30,7 +29,6 @@ class PluginFieldTypeCommand extends Command
 {
     use ModuleTrait;
     use ConfirmationTrait;
-    use CommandTrait;
 
     /**
  * @var Manager
@@ -47,6 +45,11 @@ class PluginFieldTypeCommand extends Command
      */
     protected $stringConverter;
 
+    /**
+     * @var Validator
+     */
+    protected $validator;
+
     /**
      * @var ChainQueue
      */
@@ -59,17 +62,20 @@ class PluginFieldTypeCommand extends Command
      * @param Manager                  $extensionManager
      * @param PluginFieldTypeGenerator $generator
      * @param StringConverter          $stringConverter
+     * @param Validator                $validator
      * @param ChainQueue               $chainQueue
      */
     public function __construct(
         Manager $extensionManager,
         PluginFieldTypeGenerator $generator,
         StringConverter $stringConverter,
+        Validator $validator,
         ChainQueue $chainQueue
     ) {
         $this->extensionManager = $extensionManager;
         $this->generator = $generator;
         $this->stringConverter = $stringConverter;
+        $this->validator = $validator;
         $this->chainQueue = $chainQueue;
         parent::__construct();
     }
@@ -80,7 +86,12 @@ class PluginFieldTypeCommand extends Command
             ->setName('generate:plugin:fieldtype')
             ->setDescription($this->trans('commands.generate.plugin.fieldtype.description'))
             ->setHelp($this->trans('commands.generate.plugin.fieldtype.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,
@@ -116,7 +127,8 @@ class PluginFieldTypeCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.plugin.fieldtype.options.default-formatter')
-            );
+            )
+            ->setAliases(['gpft']);
     }
 
     /**
@@ -124,23 +136,28 @@ class PluginFieldTypeCommand extends Command
      */
     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');
         $description = $input->getOption('description');
         $default_widget = $input->getOption('default-widget');
         $default_formatter = $input->getOption('default-formatter');
 
-        $this->generator
-            ->generate($module, $class_name, $label, $plugin_id, $description, $default_widget, $default_formatter);
+        $this->generator->generate([
+            'module' => $module,
+            'class_name' => $class_name,
+            'label' => $label,
+            'plugin_id' => $plugin_id,
+            'description' => $description,
+            'default_widget' => $default_widget,
+            'default_formatter' => $default_formatter,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery'], false);
 
@@ -149,22 +166,18 @@ class PluginFieldTypeCommand extends Command
 
     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.fieldtype.questions.class'),
-                'ExampleFieldType'
+                'ExampleFieldType',
+                function ($class_name) {
+                    return $this->validator->validateClassName($class_name);
+                }
             );
             $input->setOption('class', $class_name);
         }
@@ -172,7 +185,7 @@ class PluginFieldTypeCommand extends Command
         // --label option
         $label = $input->getOption('label');
         if (!$label) {
-            $label = $io->ask(
+            $label = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.fieldtype.questions.label'),
                 $this->stringConverter->camelCaseToHuman($class_name)
             );
@@ -182,7 +195,7 @@ class PluginFieldTypeCommand extends Command
         // --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.fieldtype.questions.plugin-id'),
                 $this->stringConverter->camelCaseToUnderscore($class_name)
             );
@@ -192,9 +205,9 @@ class PluginFieldTypeCommand extends Command
         // --description option
         $description = $input->getOption('description');
         if (!$description) {
-            $description = $io->ask(
+            $description = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.fieldtype.questions.description'),
-                'My Field Type'
+                $this->trans('commands.generate.plugin.fieldtype.suggestions.my-field-type')
             );
             $input->setOption('description', $description);
         }
@@ -202,7 +215,7 @@ class PluginFieldTypeCommand extends Command
         // --default-widget option
         $default_widget = $input->getOption('default-widget');
         if (!$default_widget) {
-            $default_widget = $io->askEmpty(
+            $default_widget = $this->getIo()->askEmpty(
                 $this->trans('commands.generate.plugin.fieldtype.questions.default-widget')
             );
             $input->setOption('default-widget', $default_widget);
@@ -211,7 +224,7 @@ class PluginFieldTypeCommand extends Command
         // --default-formatter option
         $default_formatter = $input->getOption('default-formatter');
         if (!$default_formatter) {
-            $default_formatter = $io->askEmpty(
+            $default_formatter = $this->getIo()->askEmpty(
                 $this->trans('commands.generate.plugin.fieldtype.questions.default-formatter')
             );
             $input->setOption('default-formatter', $default_formatter);