Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginConditionCommand.php
index 817dff1c1be13c992b049712480c0fc749a76a11..462ef56caf1f387cc36b56f22e22225c488ec7dd 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 Symfony\Component\Console\Command\Command;
+use Drupal\Console\Core\Command\Command;
 use Drupal\Core\Entity\EntityTypeRepository;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
 use Drupal\Console\Generator\PluginConditionGenerator;
 use Drupal\Console\Command\Shared\ModuleTrait;
 use Drupal\Console\Command\Shared\ConfirmationTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
 use Drupal\Console\Extension\Manager;
 use Drupal\Console\Core\Utils\ChainQueue;
 use Drupal\Console\Core\Utils\StringConverter;
@@ -28,7 +27,6 @@ use Drupal\Console\Core\Utils\StringConverter;
  */
 class PluginConditionCommand extends Command
 {
-    use CommandTrait;
     use ModuleTrait;
     use ConfirmationTrait;
 
@@ -52,6 +50,11 @@ class PluginConditionCommand extends Command
      */
     protected $stringConverter;
 
+    /**
+     * @var Validator
+     */
+    protected $validator;
+
 
     /**
      * PluginConditionCommand constructor.
@@ -61,19 +64,22 @@ class PluginConditionCommand extends Command
      * @param ChainQueue               $chainQueue
      * @param EntityTypeRepository     $entitytyperepository
      * @param StringConverter          $stringConverter
+     * @param Validator                $validator
      */
     public function __construct(
         Manager $extensionManager,
         PluginConditionGenerator $generator,
         ChainQueue $chainQueue,
         EntityTypeRepository $entitytyperepository,
-        StringConverter $stringConverter
+        StringConverter $stringConverter,
+        Validator $validator
     ) {
         $this->extensionManager = $extensionManager;
         $this->generator = $generator;
         $this->chainQueue = $chainQueue;
         $this->entitytyperepository = $entitytyperepository;
         $this->stringConverter = $stringConverter;
+        $this->validator = $validator;
         parent::__construct();
     }
 
@@ -83,7 +89,12 @@ class PluginConditionCommand extends Command
             ->setName('generate:plugin:condition')
             ->setDescription($this->trans('commands.generate.plugin.condition.description'))
             ->setHelp($this->trans('commands.generate.plugin.condition.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,
@@ -119,7 +130,8 @@ class PluginConditionCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.generate.plugin.condition.options.context-definition-required')
-            );
+            )
+            ->setAliases(['gpco']);
     }
 
     /**
@@ -127,24 +139,28 @@ class PluginConditionCommand 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');
         $context_definition_id = $input->getOption('context-definition-id');
         $context_definition_label = $input->getOption('context-definition-label');
         $context_definition_required = $input->getOption('context-definition-required')?'TRUE':'FALSE';
 
-        $this
-            ->generator
-            ->generate($module, $class_name, $label, $plugin_id, $context_definition_id, $context_definition_label, $context_definition_required);
+        $this->generator->generate([
+            'module' => $module,
+            'class_name' => $class_name,
+            'label' => $label,
+            'plugin_id' => $plugin_id,
+            'context_definition_id' => $context_definition_id,
+            'context_definition_label' => $context_definition_label,
+            'context_definition_required' => $context_definition_required,
+        ]);
 
         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
 
@@ -153,26 +169,22 @@ class PluginConditionCommand extends Command
 
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $entityTypeRepository = $this->entitytyperepository;
 
         $entity_types = $entityTypeRepository->getEntityTypeLabels(true);
 
         // --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 = $input->getOption('class');
         if (!$class) {
-            $class = $io->ask(
+            $class = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.condition.questions.class'),
-                'ExampleCondition'
+                'ExampleCondition',
+                function ($class) {
+                    return $this->validator->validateClassName($class);
+                }
             );
             $input->setOption('class', $class);
         }
@@ -180,7 +192,7 @@ class PluginConditionCommand extends Command
         // --plugin label option
         $label = $input->getOption('label');
         if (!$label) {
-            $label = $io->ask(
+            $label = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.condition.questions.label'),
                 $this->stringConverter->camelCaseToHuman($class)
             );
@@ -190,7 +202,7 @@ class PluginConditionCommand extends Command
         // --plugin-id option
         $pluginId = $input->getOption('plugin-id');
         if (!$pluginId) {
-            $pluginId = $io->ask(
+            $pluginId = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.condition.questions.plugin-id'),
                 $this->stringConverter->camelCaseToUnderscore($class)
             );
@@ -200,7 +212,7 @@ class PluginConditionCommand extends Command
         $context_definition_id = $input->getOption('context-definition-id');
         if (!$context_definition_id) {
             $context_type = ['language' => 'Language', "entity" => "Entity"];
-            $context_type_sel = $io->choice(
+            $context_type_sel = $this->getIo()->choice(
                 $this->trans('commands.generate.plugin.condition.questions.context-type'),
                 array_values($context_type)
             );
@@ -210,13 +222,13 @@ class PluginConditionCommand extends Command
                 $context_definition_id = $context_type_sel;
                 $context_definition_id_value = ucfirst($context_type_sel);
             } else {
-                $content_entity_types_sel = $io->choice(
+                $content_entity_types_sel = $this->getIo()->choice(
                     $this->trans('commands.generate.plugin.condition.questions.context-entity-type'),
                     array_keys($entity_types)
                 );
 
                 $contextDefinitionIdList = $entity_types[$content_entity_types_sel];
-                $context_definition_id_sel = $io->choice(
+                $context_definition_id_sel = $this->getIo()->choice(
                     $this->trans('commands.generate.plugin.condition.questions.context-definition-id'),
                     array_values($contextDefinitionIdList)
                 );
@@ -233,7 +245,7 @@ class PluginConditionCommand extends Command
 
         $context_definition_label = $input->getOption('context-definition-label');
         if (!$context_definition_label) {
-            $context_definition_label = $io->ask(
+            $context_definition_label = $this->getIo()->ask(
                 $this->trans('commands.generate.plugin.condition.questions.context-definition-label'),
                 $context_definition_id_value?:null
             );
@@ -242,7 +254,7 @@ class PluginConditionCommand extends Command
 
         $context_definition_required = $input->getOption('context-definition-required');
         if (empty($context_definition_required)) {
-            $context_definition_required = $io->confirm(
+            $context_definition_required = $this->getIo()->confirm(
                 $this->trans('commands.generate.plugin.condition.questions.context-definition-required'),
                 true
             );