Security update for Core, with self-updated composer
[yaffs-website] / vendor / drupal / console / src / Command / Generate / ThemeCommand.php
index 4ec9a75094aef9c0bb47b19228ca44c8babe12c1..e6fc77b4034ac1d7df12acabce8f44abae83b1f3 100644 (file)
@@ -7,6 +7,7 @@
 
 namespace Drupal\Console\Command\Generate;
 
+use Drupal\Console\Command\Shared\ArrayInputTrait;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
@@ -14,14 +15,13 @@ use Drupal\Console\Command\Shared\ThemeRegionTrait;
 use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
 use Drupal\Console\Generator\ThemeGenerator;
 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\Utils\Site;
 use Drupal\Console\Core\Utils\StringConverter;
-use Drupal\Console\Core\Command\Shared\CommandTrait;
 use Drupal\Console\Utils\Validator;
 use Drupal\Core\Extension\ThemeHandler;
+use Webmozart\PathUtil\Path;
 
 /**
  * Class ThemeCommand
@@ -33,7 +33,7 @@ class ThemeCommand extends Command
     use ConfirmationTrait;
     use ThemeRegionTrait;
     use ThemeBreakpointTrait;
-    use CommandTrait;
+    use ArrayInputTrait;
 
     /**
  * @var Manager
@@ -114,7 +114,7 @@ class ThemeCommand extends Command
                 'theme',
                 null,
                 InputOption::VALUE_REQUIRED,
-                $this->trans('commands.generate.theme.options.module')
+                $this->trans('commands.generate.theme.options.theme')
             )
             ->addOption(
                 'machine-name',
@@ -126,7 +126,7 @@ class ThemeCommand extends Command
                 'theme-path',
                 null,
                 InputOption::VALUE_REQUIRED,
-                $this->trans('commands.generate.theme.options.module-path')
+                $this->trans('commands.generate.theme.options.theme-path')
             )
             ->addOption(
                 'description',
@@ -150,7 +150,7 @@ class ThemeCommand extends Command
             ->addOption(
                 'libraries',
                 null,
-                InputOption::VALUE_OPTIONAL,
+                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.generate.theme.options.libraries')
             )
             ->addOption(
@@ -162,15 +162,16 @@ class ThemeCommand extends Command
             ->addOption(
                 'regions',
                 null,
-                InputOption::VALUE_OPTIONAL,
+                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.generate.theme.options.regions')
             )
             ->addOption(
                 'breakpoints',
                 null,
-                InputOption::VALUE_OPTIONAL,
+                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
                 $this->trans('commands.generate.theme.options.breakpoints')
-            );
+            )
+            ->setAliases(['gt']);
     }
 
     /**
@@ -178,15 +179,17 @@ class ThemeCommand 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;
         }
 
         $theme = $this->validator->validateModuleName($input->getOption('theme'));
-        $theme_path = $this->appRoot . $input->getOption('theme-path');
+        // Get the profile path and define a profile path if it is null
+        // Check that it is an absolute path or otherwise create an absolute path using appRoot
+        $theme_path = $input->getOption('theme-path');
+        $theme_path = $theme_path == null ? 'themes/custom' : $theme_path;
+        $theme_path = Path::isAbsolute($theme_path) ? $theme_path : Path::makeAbsolute($theme_path, $this->appRoot);
         $theme_path = $this->validator->validateModulePath($theme_path, true);
 
         $machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
@@ -198,20 +201,29 @@ class ThemeCommand extends Command
         $libraries = $input->getOption('libraries');
         $regions = $input->getOption('regions');
         $breakpoints = $input->getOption('breakpoints');
+        $noInteraction = $input->getOption('no-interaction');
+
+        // Parse nested data.
+        if ($noInteraction) {
+            $libraries = $this->explodeInlineArray($libraries);
+            $regions = $this->explodeInlineArray($regions);
+            $breakpoints = $this->explodeInlineArray($breakpoints);
+        }
+
+        $this->generator->generate([
+            'theme' => $theme,
+            'machine_name' => $machine_name,
+            'dir' => $theme_path,
+            'core' => $core,
+            'description' => $description,
+            'package' => $package,
+            'base_theme' => $base_theme,
+            'global_library' => $global_library,
+            'libraries' => $libraries,
+            'regions' => $regions,
+            'breakpoints' => $breakpoints,
+        ]);
 
-        $this->generator->generate(
-            $theme,
-            $machine_name,
-            $theme_path,
-            $description,
-            $core,
-            $package,
-            $base_theme,
-            $global_library,
-            $libraries,
-            $regions,
-            $breakpoints
-        );
 
         return 0;
     }
@@ -221,19 +233,17 @@ class ThemeCommand extends Command
      */
     protected function interact(InputInterface $input, OutputInterface $output)
     {
-        $io = new DrupalStyle($input, $output);
-
         try {
             $theme = $input->getOption('theme') ? $this->validator->validateModuleName($input->getOption('theme')) : null;
         } catch (\Exception $error) {
-            $io->error($error->getMessage());
+            $this->getIo()->error($error->getMessage());
 
             return 1;
         }
 
         if (!$theme) {
             $validators = $this->validator;
-            $theme = $io->ask(
+            $theme = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.theme'),
                 '',
                 function ($theme) use ($validators) {
@@ -244,16 +254,16 @@ class ThemeCommand extends Command
         }
 
         try {
-            $machine_name = $input->getOption('machine-name') ? $this->validator->validateModule($input->getOption('machine-name')) : null;
+            $machine_name = $input->getOption('machine-name') ? $this->validator->validateModuleName($input->getOption('machine-name')) : null;
         } catch (\Exception $error) {
-            $io->error($error->getMessage());
+            $this->getIo()->error($error->getMessage());
 
             return 1;
         }
 
         if (!$machine_name) {
-            $machine_name = $io->ask(
-                $this->trans('commands.generate.module.questions.machine-name'),
+            $machine_name = $this->getIo()->ask(
+                $this->trans('commands.generate.theme.questions.machine-name'),
                 $this->stringConverter->createMachineName($theme),
                 function ($machine_name) use ($validators) {
                     return $validators->validateMachineName($machine_name);
@@ -264,18 +274,17 @@ class ThemeCommand extends Command
 
         $theme_path = $input->getOption('theme-path');
         if (!$theme_path) {
-            $drupalRoot = $this->appRoot;
-            $theme_path = $io->ask(
+            $theme_path = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.theme-path'),
-                '/themes/custom',
-                function ($theme_path) use ($drupalRoot, $machine_name) {
-                    $theme_path = ($theme_path[0] != '/' ? '/' : '') . $theme_path;
-                    $full_path = $drupalRoot . $theme_path . '/' . $machine_name;
-                    if (file_exists($full_path)) {
+                'themes/custom',
+                function ($theme_path) use ($machine_name) {
+                    $fullPath = Path::isAbsolute($theme_path) ? $theme_path : Path::makeAbsolute($theme_path, $this->appRoot);
+                    $fullPath = $fullPath.'/'.$machine_name;
+                    if (file_exists($fullPath)) {
                         throw new \InvalidArgumentException(
                             sprintf(
                                 $this->trans('commands.generate.theme.errors.directory-exists'),
-                                $full_path
+                                $fullPath
                             )
                         );
                     } else {
@@ -288,25 +297,25 @@ class ThemeCommand extends Command
 
         $description = $input->getOption('description');
         if (!$description) {
-            $description = $io->ask(
+            $description = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.description'),
-                'My Awesome theme'
+                $this->trans('commands.generate.theme.suggestions.my-awesome-theme')
             );
             $input->setOption('description', $description);
         }
 
         $package = $input->getOption('package');
         if (!$package) {
-            $package = $io->ask(
+            $package = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.package'),
-                'Other'
+                $this->trans('commands.generate.theme.suggestions.other')
             );
             $input->setOption('package', $package);
         }
 
         $core = $input->getOption('core');
         if (!$core) {
-            $core = $io->ask(
+            $core = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.core'),
                 '8.x'
             );
@@ -320,7 +329,7 @@ class ThemeCommand extends Command
 
             uasort($themes, 'system_sort_modules_by_info_name');
 
-            $base_theme = $io->choiceNoList(
+            $base_theme = $this->getIo()->choiceNoList(
                 $this->trans('commands.generate.theme.options.base-theme'),
                 array_keys($themes)
             );
@@ -329,7 +338,7 @@ class ThemeCommand extends Command
 
         $global_library = $input->getOption('global-library');
         if (!$global_library) {
-            $global_library = $io->ask(
+            $global_library = $this->getIo()->ask(
                 $this->trans('commands.generate.theme.questions.global-library'),
                 'global-styling'
             );
@@ -340,43 +349,49 @@ class ThemeCommand extends Command
         // --libraries option.
         $libraries = $input->getOption('libraries');
         if (!$libraries) {
-            if ($io->confirm(
+            if ($this->getIo()->confirm(
                 $this->trans('commands.generate.theme.questions.library-add'),
                 true
             )
             ) {
                 // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::libraryQuestion
-                $libraries = $this->libraryQuestion($io);
-                $input->setOption('libraries', $libraries);
+                $libraries = $this->libraryQuestion();
             }
+        } else {
+            $libraries = $this->explodeInlineArray($libraries);
         }
+        $input->setOption('libraries', $libraries);
 
         // --regions option.
         $regions = $input->getOption('regions');
         if (!$regions) {
-            if ($io->confirm(
+            if ($this->getIo()->confirm(
                 $this->trans('commands.generate.theme.questions.regions'),
                 true
             )
             ) {
                 // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
-                $regions = $this->regionQuestion($io);
-                $input->setOption('regions', $regions);
+                $regions = $this->regionQuestion();
             }
+        } else {
+            $regions = $this->explodeInlineArray($regions);
         }
+        $input->setOption('regions', $regions);
 
         // --breakpoints option.
         $breakpoints = $input->getOption('breakpoints');
         if (!$breakpoints) {
-            if ($io->confirm(
+            if ($this->getIo()->confirm(
                 $this->trans('commands.generate.theme.questions.breakpoints'),
                 true
             )
             ) {
                 // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
-                $breakpoints = $this->breakpointQuestion($io);
-                $input->setOption('breakpoints', $breakpoints);
+                $breakpoints = $this->breakpointQuestion();
             }
+        } else {
+            $breakpoints = $this->explodeInlineArray($breakpoints);
         }
+        $input->setOption('breakpoints', $breakpoints);
     }
 }