Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginViewsFieldCommand.php
index 0dab88a7ad15ba59d58ed98f6693f7221052ef6a..7fdadeb60edd6a1c8d9cab965c84e36af9ccd287 100644 (file)
@@ -7,17 +7,16 @@
 
 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\PluginViewsFieldGenerator;
 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\Utils\ChainQueue;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
 use Drupal\Console\Utils\Site;
 use Drupal\Console\Core\Utils\StringConverter;
 
@@ -30,17 +29,15 @@ class PluginViewsFieldCommand extends Command
 {
     use ModuleTrait;
     use ConfirmationTrait;
-    use CommandTrait;
-
 
     /**
- * @var Manager
-*/
    * @var Manager
+     */
     protected $extensionManager;
 
     /**
- * @var PluginViewsFieldGenerator
-*/
    * @var PluginViewsFieldGenerator
+     */
     protected $generator;
 
     /**
@@ -53,6 +50,11 @@ class PluginViewsFieldCommand extends Command
      */
     protected $stringConverter;
 
+    /**
+     * @var Validator
+     */
+    protected $validator;
+
     /**
      * @var ChainQueue
      */
@@ -65,6 +67,7 @@ class PluginViewsFieldCommand extends Command
      * @param PluginViewsFieldGenerator $generator
      * @param Site                      $site
      * @param StringConverter           $stringConverter
+     * @param Validator                 $validator
      * @param ChainQueue                $chainQueue
      */
     public function __construct(
@@ -72,12 +75,14 @@ class PluginViewsFieldCommand extends Command
         PluginViewsFieldGenerator $generator,
         Site $site,
         StringConverter $stringConverter,
+        Validator $validator,
         ChainQueue $chainQueue
     ) {
         $this->extensionManager = $extensionManager;
         $this->generator = $generator;
         $this->site = $site;
         $this->stringConverter = $stringConverter;
+        $this->validator = $validator;
         $this->chainQueue = $chainQueue;
         parent::__construct();
     }
@@ -88,7 +93,12 @@ class PluginViewsFieldCommand extends Command
             ->setName('generate:plugin:views:field')
             ->setDescription($this->trans('commands.generate.plugin.views.field.description'))
             ->setHelp($this->trans('commands.generate.plugin.views.field.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,
@@ -106,7 +116,8 @@ class PluginViewsFieldCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.plugin.views.field.options.description')
-            );
+            )
+            ->setAliases(['gpvf']);
     }
 
     /**
@@ -114,20 +125,24 @@ class PluginViewsFieldCommand 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'));
         $class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name);
         $title = $input->getOption('title');
         $description = $input->getOption('description');
 
-        $this->generator->generate($module, $class_machine_name, $class_name, $title, $description);
+        $this->generator->generate([
+            'module' => $module,
+            'class_machine_name' => $class_machine_name,
+            'class_name' => $class_name,
+            'title' => $title,
+            'description' => $description,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
 
@@ -136,22 +151,18 @@ class PluginViewsFieldCommand 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.views.field.questions.class'),
-                'CustomViewsField'
+                'CustomViewsField',
+                function ($class_name) {
+                    return $this->validator->validateClassName($class_name);
+                }
             );
         }
         $input->setOption('class', $class_name);
@@ -159,7 +170,7 @@ class PluginViewsFieldCommand extends Command
         // --title option
         $title = $input->getOption('title');
         if (!$title) {
-            $title = $io->ask(
+            $title = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.views.field.questions.title'),
                 $this->stringConverter->camelCaseToHuman($class_name)
             );
@@ -169,16 +180,11 @@ class PluginViewsFieldCommand extends Command
         // --description option
         $description = $input->getOption('description');
         if (!$description) {
-            $description = $io->ask(
+            $description = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.views.field.questions.description'),
                 $this->trans('commands.generate.plugin.views.field.questions.description_default')
             );
             $input->setOption('description', $description);
         }
     }
-
-    protected function createGenerator()
-    {
-        return new PluginViewsFieldGenerator();
-    }
 }