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