Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / BreakPointCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Generate\BreakPointCommand.
6  */
7
8 namespace Drupal\Console\Command\Generate;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputOption;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Extension\ThemeHandler;
15 use Drupal\Console\Command\Shared\ThemeRegionTrait;
16 use Drupal\Console\Command\Shared\ThemeBreakpointTrait;
17 use Drupal\Console\Command\Shared\ConfirmationTrait;
18 use Drupal\Console\Core\Command\Shared\CommandTrait;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Utils\Validator;
21 use Drupal\Console\Core\Utils\StringConverter;
22 use Drupal\Console\Generator\BreakPointGenerator;
23
24 /**
25  *
26  */
27 class BreakPointCommand extends Command
28 {
29     use CommandTrait;
30     use ConfirmationTrait;
31     use ThemeRegionTrait;
32     use ThemeBreakpointTrait;
33
34     /**
35      * @var BreakPointGenerator
36      */
37     protected $generator;
38
39     /**
40      * @var Site
41      */
42     protected $site;
43
44     /**
45      * @var string
46      */
47     protected $appRoot;
48
49     /**
50      * @var ThemeHandler
51      */
52     protected $themeHandler;
53
54
55     /**
56  * @var Validator
57 */
58     protected $validator;
59
60     /**
61      * @var StringConverter
62      */
63     protected $stringConverter;
64
65     /**
66      * BreakPointCommand constructor.
67      *
68      * @param BreakPointGenerator $generator
69      * @param $appRoot
70      * @param ThemeHandler        $themeHandler
71      * @param Validator           $validator
72      * @param StringConverter     $stringConverter
73      */
74     public function __construct(
75         BreakPointGenerator $generator,
76         $appRoot,
77         ThemeHandler $themeHandler,
78         Validator $validator,
79         StringConverter $stringConverter
80     ) {
81         $this->generator = $generator;
82         $this->appRoot = $appRoot;
83         $this->themeHandler = $themeHandler;
84         $this->validator = $validator;
85         $this->stringConverter = $stringConverter;
86         parent::__construct();
87     }
88
89     /**
90      * {@inheritdoc}
91      */
92     protected function configure()
93     {
94         $this
95             ->setName('generate:breakpoint')
96             ->setDescription($this->trans('commands.generate.breakpoint.description'))
97             ->setHelp($this->trans('commands.generate.breakpoint.help'))
98             ->addOption(
99                 'theme',
100                 null,
101                 InputOption::VALUE_REQUIRED,
102                 $this->trans('commands.generate.breakpoint.options.theme')
103             )
104             ->addOption(
105                 'breakpoints',
106                 null,
107                 InputOption::VALUE_OPTIONAL,
108                 $this->trans('commands.generate.breakpoint.options.breakpoints')
109             );
110     }
111
112     /**
113      * {@inheritdoc}
114      */
115     protected function execute(InputInterface $input, OutputInterface $output)
116     {
117         $io = new DrupalStyle($input, $output);
118
119         // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
120         if (!$this->confirmGeneration($io)) {
121             return 1;
122         }
123
124         $validators = $this->validator;
125         // we must to ensure theme exist
126         $machine_name = $validators->validateMachineName($input->getOption('theme'));
127         $theme_path = $drupal_root . $input->getOption('theme');
128         $breakpoints = $input->getOption('breakpoints');
129
130         $this->generator->generate(
131             $theme_path,
132             $breakpoints,
133             $machine_name
134         );
135
136         return 0;
137     }
138
139     /**
140      * {@inheritdoc}
141      */
142     protected function interact(InputInterface $input, OutputInterface $output)
143     {
144         $io = new DrupalStyle($input, $output);
145
146         $drupalRoot = $this->appRoot;
147
148         // --base-theme option.
149         $base_theme = $input->getOption('theme');
150
151         if (!$base_theme) {
152             $themeHandler = $this->themeHandler;
153             $themes = $themeHandler->rebuildThemeData();
154             $themes['classy'] ='';
155
156             uasort($themes, 'system_sort_modules_by_info_name');
157
158             $base_theme = $io->choiceNoList(
159                 $this->trans('commands.generate.breakpoint.questions.theme'),
160                 array_keys($themes)
161             );
162             $input->setOption('theme', $base_theme);
163         }
164
165         // --breakpoints option.
166         $breakpoints = $input->getOption('breakpoints');
167         if (!$breakpoints) {
168             $breakpoints = $this->breakpointQuestion($io);
169             $input->setOption('breakpoints', $breakpoints);
170         }
171     }
172 }