5 * Contains \Drupal\Console\Command\Generate\BreakPointCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Command\Shared\ArrayInputTrait;
11 use Drupal\Console\Command\Shared\ConfirmationTrait;
12 use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
13 use Drupal\Console\Core\Command\Command;
14 use Drupal\Console\Core\Utils\StringConverter;
15 use Drupal\Console\Generator\BreakPointGenerator;
16 use Drupal\Console\Utils\Validator;
17 use Drupal\Core\Extension\ThemeHandler;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Input\InputOption;
20 use Symfony\Component\Console\Output\OutputInterface;
23 * Class BreakPointCommand
25 * @package Drupal\Console\Command\Generate
27 class BreakPointCommand extends Command
30 use ConfirmationTrait;
31 use ThemeBreakpointTrait;
34 * @var BreakPointGenerator
51 protected $themeHandler;
59 * @var StringConverter
61 protected $stringConverter;
64 * BreakPointCommand constructor.
66 * @param BreakPointGenerator $generator
67 * @param string $appRoot
68 * @param ThemeHandler $themeHandler
69 * @param Validator $validator
70 * @param StringConverter $stringConverter
72 public function __construct(
73 BreakPointGenerator $generator,
75 ThemeHandler $themeHandler,
77 StringConverter $stringConverter
79 $this->generator = $generator;
80 $this->appRoot = $appRoot;
81 $this->themeHandler = $themeHandler;
82 $this->validator = $validator;
83 $this->stringConverter = $stringConverter;
84 parent::__construct();
90 protected function configure()
93 ->setName('generate:breakpoint')
94 ->setDescription($this->trans('commands.generate.breakpoint.description'))
95 ->setHelp($this->trans('commands.generate.breakpoint.help'))
99 InputOption::VALUE_REQUIRED,
100 $this->trans('commands.generate.breakpoint.options.theme')
105 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
106 $this->trans('commands.generate.breakpoint.options.breakpoints')
107 )->setAliases(['gb']);
113 protected function execute(InputInterface $input, OutputInterface $output)
115 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
116 if (!$this->confirmOperation()) {
120 $validators = $this->validator;
121 // we must to ensure theme exist
122 $machine_name = $validators->validateMachineName($input->getOption('theme'));
123 $theme = $input->getOption('theme');
124 $breakpoints = $input->getOption('breakpoints');
125 $noInteraction = $input->getOption('no-interaction');
126 // Parse nested data.
127 if ($noInteraction) {
128 $breakpoints = $this->explodeInlineArray($breakpoints);
131 $this->generator->generate([
133 'breakpoints' => $breakpoints,
134 'machine_name' => $machine_name,
143 protected function interact(InputInterface $input, OutputInterface $output)
146 $theme = $input->getOption('theme');
149 $themeHandler = $this->themeHandler;
150 $themes = $themeHandler->rebuildThemeData();
151 $themes['classy'] = '';
153 uasort($themes, 'system_sort_modules_by_info_name');
155 $theme = $this->getIo()->choiceNoList(
156 $this->trans('commands.generate.breakpoint.questions.theme'),
159 $input->setOption('theme', $theme);
162 // --breakpoints option.
163 $breakpoints = $input->getOption('breakpoints');
165 $breakpoints = $this->breakpointQuestion();
166 $input->setOption('breakpoints', $breakpoints);
168 $breakpoints = $this->explodeInlineArray($breakpoints);
170 $input->setOption('breakpoints', $breakpoints);