Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Generate / PluginImageEffectCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Generate\PluginImageEffectCommand.
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 Drupal\Console\Generator\PluginImageEffectGenerator;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Command\Shared\ConfirmationTrait;
16 use Symfony\Component\Console\Command\Command;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Command\Shared\CommandTrait;
20 use Drupal\Console\Core\Utils\StringConverter;
21 use Drupal\Console\Core\Utils\ChainQueue;
22
23 /**
24  * Class PluginImageEffectCommand
25  *
26  * @package Drupal\Console\Command\Generate
27  */
28 class PluginImageEffectCommand extends Command
29 {
30     use ModuleTrait;
31     use ConfirmationTrait;
32     use CommandTrait;
33
34     /**
35  * @var Manager
36 */
37     protected $extensionManager;
38
39     /**
40  * @var PluginImageEffectGenerator
41 */
42     protected $generator;
43
44     /**
45      * @var StringConverter
46      */
47     protected $stringConverter;
48
49     /**
50      * @var ChainQueue
51      */
52     protected $chainQueue;
53
54
55     /**
56      * PluginImageEffectCommand constructor.
57      *
58      * @param Manager                    $extensionManager
59      * @param PluginImageEffectGenerator $generator
60      * @param StringConverter            $stringConverter
61      * @param ChainQueue                 $chainQueue
62      */
63     public function __construct(
64         Manager $extensionManager,
65         PluginImageEffectGenerator $generator,
66         StringConverter $stringConverter,
67         ChainQueue $chainQueue
68     ) {
69         $this->extensionManager = $extensionManager;
70         $this->generator = $generator;
71         $this->stringConverter = $stringConverter;
72         $this->chainQueue = $chainQueue;
73         parent::__construct();
74     }
75
76     protected function configure()
77     {
78         $this
79             ->setName('generate:plugin:imageeffect')
80             ->setDescription($this->trans('commands.generate.plugin.imageeffect.description'))
81             ->setHelp($this->trans('commands.generate.plugin.imageeffect.help'))
82             ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
83             ->addOption(
84                 'class',
85                 null,
86                 InputOption::VALUE_REQUIRED,
87                 $this->trans('commands.generate.plugin.imageeffect.options.class')
88             )
89             ->addOption(
90                 'label',
91                 null,
92                 InputOption::VALUE_OPTIONAL,
93                 $this->trans('commands.generate.plugin.imageeffect.options.label')
94             )
95             ->addOption(
96                 'plugin-id',
97                 null,
98                 InputOption::VALUE_OPTIONAL,
99                 $this->trans('commands.generate.plugin.imageeffect.options.plugin-id')
100             )
101             ->addOption(
102                 'description',
103                 null,
104                 InputOption::VALUE_OPTIONAL,
105                 $this->trans('commands.generate.plugin.imageeffect.options.description')
106             );
107     }
108
109     /**
110      * {@inheritdoc}
111      */
112     protected function execute(InputInterface $input, OutputInterface $output)
113     {
114         $io = new DrupalStyle($input, $output);
115
116         // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
117         if (!$this->confirmGeneration($io)) {
118             return 1;
119         }
120
121         $module = $input->getOption('module');
122         $class_name = $input->getOption('class');
123         $label = $input->getOption('label');
124         $plugin_id = $input->getOption('plugin-id');
125         $description = $input->getOption('description');
126
127         $this->generator->generate($module, $class_name, $label, $plugin_id, $description);
128
129         $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
130     }
131
132     protected function interact(InputInterface $input, OutputInterface $output)
133     {
134         $io = new DrupalStyle($input, $output);
135
136         // --module option
137         $module = $input->getOption('module');
138         if (!$module) {
139             // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
140             $module = $this->moduleQuestion($io);
141             $input->setOption('module', $module);
142         }
143
144         // --class option
145         $class_name = $input->getOption('class');
146         if (!$class_name) {
147             $class_name = $io->ask(
148                 $this->trans('commands.generate.plugin.imageeffect.questions.class'),
149                 'DefaultImageEffect'
150             );
151             $input->setOption('class', $class_name);
152         }
153
154         // --label option
155         $label = $input->getOption('label');
156         if (!$label) {
157             $label = $io->ask(
158                 $this->trans('commands.generate.plugin.imageeffect.questions.label'),
159                 $this->stringConverter->camelCaseToHuman($class_name)
160             );
161             $input->setOption('label', $label);
162         }
163
164         // --plugin-id option
165         $plugin_id = $input->getOption('plugin-id');
166         if (!$plugin_id) {
167             $plugin_id = $io->ask(
168                 $this->trans('commands.generate.plugin.imageeffect.questions.plugin-id'),
169                 $this->stringConverter->camelCaseToUnderscore($class_name)
170             );
171             $input->setOption('plugin-id', $plugin_id);
172         }
173
174         // --description option
175         $description = $input->getOption('description');
176         if (!$description) {
177             $description = $io->ask(
178                 $this->trans('commands.generate.plugin.imageeffect.questions.description'),
179                 'My Image Effect'
180             );
181             $input->setOption('description', $description);
182         }
183     }
184 }