Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Create / TermsCommand.php
index a2bd1ab3bf361f7a3f122ab7f21ae0bfd2ceae35..2c3dbaadb98bd8ede39c06ec74655ed26fbc40ce 100644 (file)
@@ -11,12 +11,10 @@ use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\Console\Command\Command;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
+use Drupal\Console\Core\Command\Command;
 use Drupal\Console\Annotations\DrupalCommand;
 use Drupal\Console\Utils\Create\TermData;
 use Drupal\Console\Utils\DrupalApi;
-use Drupal\Console\Core\Style\DrupalStyle;
 
 /**
  * Class TermsCommand
@@ -30,8 +28,6 @@ use Drupal\Console\Core\Style\DrupalStyle;
  */
 class TermsCommand extends Command
 {
-    use CommandTrait;
-
     /**
      * @var DrupalApi
      */
@@ -80,7 +76,7 @@ class TermsCommand extends Command
                 null,
                 InputOption::VALUE_OPTIONAL,
                 $this->trans('commands.create.terms.options.name-words')
-            );
+            )->setAliases(['crt']);
     }
 
     /**
@@ -88,12 +84,10 @@ class TermsCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $vocabularies = $input->getArgument('vocabularies');
         if (!$vocabularies) {
             $vocabularies = $this->drupalApi->getVocabularies();
-            $vids = $io->choice(
+            $vids = $this->getIo()->choice(
                 $this->trans('commands.create.terms.questions.vocabularies'),
                 array_values($vocabularies),
                 null,
@@ -112,7 +106,7 @@ class TermsCommand extends Command
 
         $limit = $input->getOption('limit');
         if (!$limit) {
-            $limit = $io->ask(
+            $limit = $this->getIo()->ask(
                 $this->trans('commands.create.terms.questions.limit'),
                 25
             );
@@ -121,7 +115,7 @@ class TermsCommand extends Command
 
         $nameWords = $input->getOption('name-words');
         if (!$nameWords) {
-            $nameWords = $io->ask(
+            $nameWords = $this->getIo()->ask(
                 $this->trans('commands.create.terms.questions.name-words'),
                 5
             );
@@ -135,8 +129,6 @@ class TermsCommand extends Command
      */
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $vocabularies = $input->getArgument('vocabularies');
         $limit = $input->getOption('limit')?:25;
         $nameWords = $input->getOption('name-words')?:5;
@@ -145,7 +137,7 @@ class TermsCommand extends Command
             $vocabularies = array_keys($this->drupalApi->getVocabularies());
         }
 
-        $terms = $this->createTermData->create(
+        $result = $this->createTermData->create(
             $vocabularies,
             $limit,
             $nameWords
@@ -157,14 +149,27 @@ class TermsCommand extends Command
             $this->trans('commands.create.terms.messages.name'),
         ];
 
-        $io->table($tableHeader, $terms['success']);
+        if ($result['success']) {
+            $this->getIo()->table($tableHeader, $result['success']);
 
-        $io->success(
-            sprintf(
-                $this->trans('commands.create.terms.messages.created-terms'),
-                $limit
-            )
-        );
+            $this->getIo()->success(
+                sprintf(
+                    $this->trans('commands.create.terms.messages.created-terms'),
+                    count($result['success'])
+                )
+            );
+        }
+
+        if (isset($result['error'])) {
+            foreach ($result['error'] as $error) {
+                $this->getIo()->error(
+                    sprintf(
+                        $this->trans('commands.create.terms.messages.error'),
+                        $error
+                    )
+                );
+            }
+        }
 
         return 0;
     }