3 namespace Drupal\metatag\Command;
5 use Symfony\Component\Console\Input\InputInterface;
6 use Symfony\Component\Console\Input\InputOption;
7 use Symfony\Component\Console\Output\OutputInterface;
8 use Symfony\Component\Console\Command\Command;
9 use Drupal\Console\Core\Command\Shared\CommandTrait;
10 use Drupal\Console\Command\Shared\ModuleTrait;
11 use Drupal\Console\Command\Shared\FormTrait;
12 use Drupal\Console\Command\Shared\ConfirmationTrait;
13 use Drupal\Console\Core\Style\DrupalStyle;
14 use Drupal\metatag\Generator\MetatagGroupGenerator;
15 use Drupal\Console\Extension\Manager;
16 use Drupal\Console\Core\Utils\ChainQueue;
19 * Class GenerateGroupCommand.
21 * Generate a Metatag group plugin.
23 * @package Drupal\metatag
25 class GenerateGroupCommand extends Command {
30 use ConfirmationTrait;
33 * The metatag group generator.
35 * @var \Drupal\metatag\Generator\MetatagGroupGenerator
40 * The console extension manager.
42 * @var \Drupal\Console\Extension\Manager
44 protected $extensionManager;
47 * The console chain queue.
49 * @var \Drupal\Console\Core\Utils\ChainQueue
51 protected $chainQueue;
54 * The GenerateTagCommand constructor.
56 * @param \Drupal\metatag\Generator\MetatagGroupGenerator $generator
57 * The generator object.
58 * @param \Drupal\Console\Extension\Manager $extensionManager
59 * The extension manager object.
60 * @param \Drupal\Console\Core\Utils\ChainQueue $chainQueue
61 * The chain queue object.
63 public function __construct(
64 MetatagGroupGenerator $generator,
65 Manager $extensionManager,
66 ChainQueue $chainQueue
68 $this->generator = $generator;
69 $this->extensionManager = $extensionManager;
70 $this->chainQueue = $chainQueue;
72 parent::__construct();
78 protected function configure() {
80 ->setName('generate:plugin:metatag:group')
81 ->setDescription($this->trans('commands.generate.metatag.group.description'))
82 ->setHelp($this->trans('commands.generate.metatag.group.help'))
83 ->addOption('base_class', '', InputOption::VALUE_REQUIRED,
84 $this->trans('commands.common.options.base_class'))
85 ->addOption('module', '', InputOption::VALUE_REQUIRED,
86 $this->trans('commands.common.options.module'))
87 ->addOption('label', '', InputOption::VALUE_REQUIRED,
88 $this->trans('commands.generate.metatag.group.options.label'))
89 ->addOption('description', '', InputOption::VALUE_OPTIONAL,
90 $this->trans('commands.generate.metatag.group.options.description'))
91 ->addOption('plugin-id', '', InputOption::VALUE_REQUIRED,
92 $this->trans('commands.generate.metatag.group.options.plugin_id'))
93 ->addOption('class-name', '', InputOption::VALUE_REQUIRED,
94 $this->trans('commands.generate.metatag.group.options.class_name'))
95 ->addOption('weight', '', InputOption::VALUE_REQUIRED,
96 $this->trans('commands.generate.metatag.group.options.weight'));
102 protected function execute(InputInterface $input, OutputInterface $output) {
103 $io = new DrupalStyle($input, $output);
105 // @see Drupal\Console\Command\ConfirmationTrait::confirmGeneration
106 if (!$this->confirmGeneration($io)) {
110 $base_class = $input->getOption('base_class');
111 $module = $input->getOption('module');
112 $label = $input->getOption('label');
113 $description = $input->getOption('description');
114 $plugin_id = $input->getOption('plugin-id');
115 $class_name = $input->getOption('class-name');
116 $weight = $input->getOption('weight');
119 ->generate($base_class, $module, $label, $description, $plugin_id, $class_name, $weight);
121 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
127 protected function interact(InputInterface $input, OutputInterface $output) {
128 $io = new DrupalStyle($input, $output);
130 // --base_class option.
131 // @todo Turn this into a choice() option.
132 $base_class = $input->getOption('base_class');
133 if (empty($base_class)) {
134 $base_class = $io->ask(
135 $this->trans('commands.generate.metatag.group.questions.base_class'),
139 $input->setOption('base_class', $base_class);
142 $module = $input->getOption('module');
143 if (empty($module)) {
144 // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
145 $module = $this->moduleQuestion($io);
147 $input->setOption('module', $module);
150 $label = $input->getOption('label');
153 $this->trans('commands.generate.metatag.group.questions.label')
156 $input->setOption('label', $label);
158 // --description option.
159 $description = $input->getOption('description');
160 if (empty($description)) {
161 $description = $io->ask(
162 $this->trans('commands.generate.metatag.group.questions.description')
165 $input->setOption('description', $description);
167 // --plugin-id option.
168 $plugin_id = $input->getOption('plugin-id');
169 if (empty($plugin_id)) {
170 $plugin_id = $io->ask(
171 $this->trans('commands.generate.metatag.group.questions.plugin_id')
174 $input->setOption('plugin-id', $plugin_id);
176 // --class-name option.
177 $class_name = $input->getOption('class-name');
178 if (empty($class_name)) {
179 $class_name = $io->ask(
180 $this->trans('commands.generate.metatag.group.questions.class_name')
183 $input->setOption('class-name', $class_name);
186 // @todo Automatically get the next int value based upon the current group.
187 $weight = $input->getOption('weight');
188 if (is_null($weight)) {
190 $this->trans('commands.generate.metatag.group.questions.weight'),
194 $input->setOption('weight', $weight);