Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     //$stringUtils = $this->getStringHelper();
     $validators = $this->validator;
     try {
         // A profile is technically also a module, so we can use the same
         // validator to check the name.
         $profile = $input->getOption('profile') ? $this->validateModuleName($input->getOption('profile')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$profile) {
         $profile = $io->ask($this->trans('commands.generate.profile.questions.profile'), '', function ($profile) use($validators) {
             return $validators->validateModuleName($profile);
         });
         $input->setOption('profile', $profile);
     }
     try {
         $machine_name = $input->getOption('machine-name') ? $this->validateModule($input->getOption('machine-name')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$machine_name) {
         $machine_name = $io->ask($this->trans('commands.generate.profile.questions.machine-name'), $this->stringConverter->createMachineName($profile), function ($machine_name) use($validators) {
             return $validators->validateMachineName($machine_name);
         });
         $input->setOption('machine-name', $machine_name);
     }
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.profile.questions.description'), 'My Useful Profile');
         $input->setOption('description', $description);
     }
     $core = $input->getOption('core');
     if (!$core) {
         $core = $io->ask($this->trans('commands.generate.profile.questions.core'), '8.x');
         $input->setOption('core', $core);
     }
     $dependencies = $input->getOption('dependencies');
     if (!$dependencies) {
         if ($io->confirm($this->trans('commands.generate.profile.questions.dependencies'), true)) {
             $dependencies = $io->ask($this->trans('commands.generate.profile.options.dependencies'), '');
         }
         $input->setOption('dependencies', $dependencies);
     }
     $distribution = $input->getOption('distribution');
     if (!$distribution) {
         if ($io->confirm($this->trans('commands.generate.profile.questions.distribution'), false)) {
             $distribution = $io->ask($this->trans('commands.generate.profile.options.distribution'), 'My Kick-ass Distribution');
             $input->setOption('distribution', $distribution);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 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());
         return;
     }
     if (!$theme) {
         $validators = $this->validator;
         $theme = $io->ask($this->trans('commands.generate.theme.questions.theme'), '', function ($theme) use($validators) {
             return $validators->validateModuleName($theme);
         });
         $input->setOption('theme', $theme);
     }
     try {
         $machine_name = $input->getOption('machine-name') ? $this->validator->validateModule($input->getOption('machine-name')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$machine_name) {
         $machine_name = $io->ask($this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($theme), function ($machine_name) use($validators) {
             return $validators->validateMachineName($machine_name);
         });
         $input->setOption('machine-name', $machine_name);
     }
     $theme_path = $input->getOption('theme-path');
     if (!$theme_path) {
         $drupalRoot = $this->appRoot;
         $theme_path = $io->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)) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.theme.errors.directory-exists'), $full_path));
             } else {
                 return $theme_path;
             }
         });
         $input->setOption('theme-path', $theme_path);
     }
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.theme.questions.description'), 'My Awesome theme');
         $input->setOption('description', $description);
     }
     $package = $input->getOption('package');
     if (!$package) {
         $package = $io->ask($this->trans('commands.generate.theme.questions.package'), 'Other');
         $input->setOption('package', $package);
     }
     $core = $input->getOption('core');
     if (!$core) {
         $core = $io->ask($this->trans('commands.generate.theme.questions.core'), '8.x');
         $input->setOption('core', $core);
     }
     $base_theme = $input->getOption('base-theme');
     if (!$base_theme) {
         $themes = $this->themeHandler->rebuildThemeData();
         $themes['false'] = '';
         uasort($themes, 'system_sort_modules_by_info_name');
         $base_theme = $io->choiceNoList($this->trans('commands.generate.theme.options.base-theme'), array_keys($themes));
         $input->setOption('base-theme', $base_theme);
     }
     $global_library = $input->getOption('global-library');
     if (!$global_library) {
         $global_library = $io->ask($this->trans('commands.generate.theme.questions.global-library'), 'global-styling');
         $input->setOption('global-library', $global_library);
     }
     // --regions option.
     $regions = $input->getOption('regions');
     if (!$regions) {
         if ($io->confirm($this->trans('commands.generate.theme.questions.regions'), true)) {
             // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
             $regions = $this->regionQuestion($io);
             $input->setOption('regions', $regions);
         }
     }
     // --breakpoints option.
     $breakpoints = $input->getOption('breakpoints');
     if (!$breakpoints) {
         if ($io->confirm($this->trans('commands.generate.theme.questions.breakpoints'), true)) {
             // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
             $breakpoints = $this->breakpointQuestion($io);
             $input->setOption('breakpoints', $breakpoints);
         }
     }
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function interact(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $validator = $this->validator;
     try {
         $module = $input->getOption('module') ? $this->validateModuleName($input->getOption('module')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
         return;
     }
     if (!$module) {
         $module = $io->ask($this->trans('commands.generate.module.questions.module'), null, function ($module) use($validator) {
             return $validator->validateModuleName($module);
         });
         $input->setOption('module', $module);
     }
     try {
         $machineName = $input->getOption('machine-name') ? $this->validateModule($input->getOption('machine-name')) : null;
     } catch (\Exception $error) {
         $io->error($error->getMessage());
     }
     if (!$machineName) {
         $machineName = $io->ask($this->trans('commands.generate.module.questions.machine-name'), $this->stringConverter->createMachineName($module), function ($machine_name) use($validator) {
             return $validator->validateMachineName($machine_name);
         });
         $input->setOption('machine-name', $machineName);
     }
     $modulePath = $input->getOption('module-path');
     if (!$modulePath) {
         $drupalRoot = $this->appRoot;
         $modulePath = $io->ask($this->trans('commands.generate.module.questions.module-path'), '/modules/custom', function ($modulePath) use($drupalRoot, $machineName) {
             $modulePath = ($modulePath[0] != '/' ? '/' : '') . $modulePath;
             $fullPath = $drupalRoot . $modulePath . '/' . $machineName;
             if (file_exists($fullPath)) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.module.errors.directory-exists'), $fullPath));
             }
             return $modulePath;
         });
     }
     $input->setOption('module-path', $modulePath);
     $description = $input->getOption('description');
     if (!$description) {
         $description = $io->ask($this->trans('commands.generate.module.questions.description'), 'My Awesome Module');
     }
     $input->setOption('description', $description);
     $package = $input->getOption('package');
     if (!$package) {
         $package = $io->ask($this->trans('commands.generate.module.questions.package'), 'Custom');
     }
     $input->setOption('package', $package);
     $core = $input->getOption('core');
     if (!$core) {
         $core = $io->ask($this->trans('commands.generate.module.questions.core'), '8.x', function ($core) {
             // Only allow 8.x and higher as core version.
             if (!preg_match('/^([0-9]+)\\.x$/', $core, $matches) || $matches[1] < 8) {
                 throw new \InvalidArgumentException(sprintf($this->trans('commands.generate.module.errors.invalid-core'), $core));
             }
             return $core;
         });
         $input->setOption('core', $core);
     }
     $moduleFile = $input->getOption('module-file');
     if (!$moduleFile) {
         $moduleFile = $io->confirm($this->trans('commands.generate.module.questions.module-file'), true);
         $input->setOption('module-file', $moduleFile);
     }
     $featuresBundle = $input->getOption('features-bundle');
     if (!$featuresBundle) {
         $featuresSupport = $io->confirm($this->trans('commands.generate.module.questions.features-support'), false);
         if ($featuresSupport) {
             $featuresBundle = $io->ask($this->trans('commands.generate.module.questions.features-bundle'), 'default');
         }
         $input->setOption('features-bundle', $featuresBundle);
     }
     $composer = $input->getOption('composer');
     if (!$composer) {
         $composer = $io->confirm($this->trans('commands.generate.module.questions.composer'), true);
         $input->setOption('composer', $composer);
     }
     $dependencies = $input->getOption('dependencies');
     if (!$dependencies) {
         $addDependencies = $io->confirm($this->trans('commands.generate.module.questions.dependencies'), false);
         if ($addDependencies) {
             $dependencies = $io->ask($this->trans('commands.generate.module.options.dependencies'));
         }
         $input->setOption('dependencies', $dependencies);
     }
 }