Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Theme / PathCommand.php
index 68ad53bd7d7ca83174d3f3763e4dd83c8d848231..05501731ebbd6ab57dcf3a7a172bf012e100eb72 100644 (file)
@@ -11,30 +11,32 @@ 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\Extension\Manager;
-use Drupal\Console\Command\Shared\ModuleTrait;
-use Drupal\Console\Core\Style\DrupalStyle;
+use Drupal\Core\Extension\ThemeHandler;
 
 class PathCommand extends Command
 {
-    use CommandTrait;
-    use ModuleTrait;
-
     /**
      * @var Manager
      */
     protected $extensionManager;
 
+    /**
+     * @var ThemeHandler
+     */
+    protected $themeHandler;
+
     /**
      * PathCommand constructor.
      *
-     * @param Manager $extensionManager
+     * @param Manager      $extensionManager
+     * @param ThemeHandler $themeHandler
      */
-    public function __construct(Manager $extensionManager)
+    public function __construct(Manager $extensionManager, ThemeHandler $themeHandler)
     {
         $this->extensionManager = $extensionManager;
+        $this->themeHandler = $themeHandler;
         parent::__construct();
     }
 
@@ -46,27 +48,34 @@ class PathCommand extends Command
             ->addArgument(
                 'theme',
                 InputArgument::REQUIRED,
-                $this->trans('commands.theme.path.arguments.module')
+                $this->trans('commands.theme.path.arguments.theme')
             )
             ->addOption(
                 'absolute',
                 null,
                 InputOption::VALUE_NONE,
                 $this->trans('commands.theme.path.options.absolute')
-            );
+            )->setAliases(['thp']);
     }
 
     protected function execute(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         $theme = $input->getArgument('theme');
 
         $fullPath = $input->getOption('absolute');
 
+        if (!in_array($theme, $this->getThemeList())) {
+            $this->getIo()->error(
+                sprintf(
+                    $this->trans('commands.theme.path.messages.invalid-theme-name'),
+                    $theme
+                )
+            );
+            return;
+        }
         $theme = $this->extensionManager->getTheme($theme);
 
-        $io->info(
+        $this->getIo()->info(
             $theme->getPath($fullPath)
         );
     }
@@ -76,14 +85,19 @@ class PathCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
-        // --module argument
+        // --theme argument
         $theme = $input->getArgument('theme');
         if (!$theme) {
-            // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
-            $module = $this->moduleQuestion($io);
-            $input->setArgument('theme', $module);
+            $theme = $this->getIo()->choiceNoList(
+                $this->trans('commands.theme.path.arguments.theme'),
+                $this->getThemeList()
+            );
+            $input->setArgument('theme', $theme);
         }
     }
+
+    protected function getThemeList()
+    {
+        return array_keys($this->themeHandler->rebuildThemeData());
+    }
 }