5 * Contains \Drupal\Console\Command\Generate\ThemeCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Console\Command\Shared\ThemeRegionTrait;
14 use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
15 use Drupal\Console\Generator\ThemeGenerator;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Symfony\Component\Console\Command\Command;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Extension\Manager;
20 use Drupal\Console\Utils\Site;
21 use Drupal\Console\Core\Utils\StringConverter;
22 use Drupal\Console\Core\Command\Shared\CommandTrait;
23 use Drupal\Console\Utils\Validator;
24 use Drupal\Core\Extension\ThemeHandler;
29 * @package Drupal\Console\Command\Generate
31 class ThemeCommand extends Command
33 use ConfirmationTrait;
35 use ThemeBreakpointTrait;
41 protected $extensionManager;
61 protected $themeHandler;
69 * @var StringConverter
71 protected $stringConverter;
74 * ThemeCommand constructor.
76 * @param Manager $extensionManager
77 * @param ThemeGenerator $generator
78 * @param Validator $validator
80 * @param ThemeHandler $themeHandler
82 * @param StringConverter $stringConverter
84 public function __construct(
85 Manager $extensionManager,
86 ThemeGenerator $generator,
89 ThemeHandler $themeHandler,
91 StringConverter $stringConverter
93 $this->extensionManager = $extensionManager;
94 $this->generator = $generator;
95 $this->validator = $validator;
96 $this->appRoot = $appRoot;
97 $this->themeHandler = $themeHandler;
99 $this->stringConverter = $stringConverter;
100 parent::__construct();
107 protected function configure()
110 ->setName('generate:theme')
111 ->setDescription($this->trans('commands.generate.theme.description'))
112 ->setHelp($this->trans('commands.generate.theme.help'))
116 InputOption::VALUE_REQUIRED,
117 $this->trans('commands.generate.theme.options.module')
122 InputOption::VALUE_REQUIRED,
123 $this->trans('commands.generate.theme.options.machine-name')
128 InputOption::VALUE_REQUIRED,
129 $this->trans('commands.generate.theme.options.module-path')
134 InputOption::VALUE_OPTIONAL,
135 $this->trans('commands.generate.theme.options.description')
137 ->addOption('core', '', InputOption::VALUE_OPTIONAL, $this->trans('commands.generate.theme.options.core'))
141 InputOption::VALUE_OPTIONAL,
142 $this->trans('commands.generate.theme.options.package')
147 InputOption::VALUE_OPTIONAL,
148 $this->trans('commands.generate.theme.options.global-library')
153 InputOption::VALUE_OPTIONAL,
154 $this->trans('commands.generate.theme.options.base-theme')
159 InputOption::VALUE_OPTIONAL,
160 $this->trans('commands.generate.theme.options.regions')
165 InputOption::VALUE_OPTIONAL,
166 $this->trans('commands.generate.theme.options.breakpoints')
173 protected function execute(InputInterface $input, OutputInterface $output)
175 $io = new DrupalStyle($input, $output);
177 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
178 if (!$this->confirmGeneration($io)) {
182 $theme = $this->validator->validateModuleName($input->getOption('theme'));
183 $theme_path = $this->appRoot . $input->getOption('theme-path');
184 $theme_path = $this->validator->validateModulePath($theme_path, true);
186 $machine_name = $this->validator->validateMachineName($input->getOption('machine-name'));
187 $description = $input->getOption('description');
188 $core = $input->getOption('core');
189 $package = $input->getOption('package');
190 $base_theme = $input->getOption('base-theme');
191 $global_library = $input->getOption('global-library');
192 $regions = $input->getOption('regions');
193 $breakpoints = $input->getOption('breakpoints');
195 $this->generator->generate(
212 protected function interact(InputInterface $input, OutputInterface $output)
214 $io = new DrupalStyle($input, $output);
217 $theme = $input->getOption('theme') ? $this->validator->validateModuleName($input->getOption('theme')) : null;
218 } catch (\Exception $error) {
219 $io->error($error->getMessage());
225 $validators = $this->validator;
227 $this->trans('commands.generate.theme.questions.theme'),
229 function ($theme) use ($validators) {
230 return $validators->validateModuleName($theme);
233 $input->setOption('theme', $theme);
237 $machine_name = $input->getOption('machine-name') ? $this->validator->validateModule($input->getOption('machine-name')) : null;
238 } catch (\Exception $error) {
239 $io->error($error->getMessage());
244 if (!$machine_name) {
245 $machine_name = $io->ask(
246 $this->trans('commands.generate.module.questions.machine-name'),
247 $this->stringConverter->createMachineName($theme),
248 function ($machine_name) use ($validators) {
249 return $validators->validateMachineName($machine_name);
252 $input->setOption('machine-name', $machine_name);
255 $theme_path = $input->getOption('theme-path');
257 $drupalRoot = $this->appRoot;
258 $theme_path = $io->ask(
259 $this->trans('commands.generate.theme.questions.theme-path'),
261 function ($theme_path) use ($drupalRoot, $machine_name) {
262 $theme_path = ($theme_path[0] != '/' ? '/' : '') . $theme_path;
263 $full_path = $drupalRoot . $theme_path . '/' . $machine_name;
264 if (file_exists($full_path)) {
265 throw new \InvalidArgumentException(
267 $this->trans('commands.generate.theme.errors.directory-exists'),
276 $input->setOption('theme-path', $theme_path);
279 $description = $input->getOption('description');
281 $description = $io->ask(
282 $this->trans('commands.generate.theme.questions.description'),
285 $input->setOption('description', $description);
288 $package = $input->getOption('package');
291 $this->trans('commands.generate.theme.questions.package'),
294 $input->setOption('package', $package);
297 $core = $input->getOption('core');
300 $this->trans('commands.generate.theme.questions.core'),
303 $input->setOption('core', $core);
306 $base_theme = $input->getOption('base-theme');
308 $themes = $this->themeHandler->rebuildThemeData();
309 $themes['false'] ='';
311 uasort($themes, 'system_sort_modules_by_info_name');
313 $base_theme = $io->choiceNoList(
314 $this->trans('commands.generate.theme.options.base-theme'),
317 $input->setOption('base-theme', $base_theme);
320 $global_library = $input->getOption('global-library');
321 if (!$global_library) {
322 $global_library = $io->ask(
323 $this->trans('commands.generate.theme.questions.global-library'),
326 $input->setOption('global-library', $global_library);
330 $regions = $input->getOption('regions');
333 $this->trans('commands.generate.theme.questions.regions'),
337 // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
338 $regions = $this->regionQuestion($io);
339 $input->setOption('regions', $regions);
343 // --breakpoints option.
344 $breakpoints = $input->getOption('breakpoints');
347 $this->trans('commands.generate.theme.questions.breakpoints'),
351 // @see \Drupal\Console\Command\Shared\ThemeRegionTrait::regionQuestion
352 $breakpoints = $this->breakpointQuestion($io);
353 $input->setOption('breakpoints', $breakpoints);