4 * Contains Drupal\metatag\Command\GenerateGroupCommand.
7 namespace Drupal\metatag\Command;
9 use Symfony\Component\Console\Input\InputInterface;
10 use Symfony\Component\Console\Input\InputOption;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Console\Core\Command\Shared\CommandTrait;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Command\Shared\FormTrait;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\metatag\Generator\MetatagGroupGenerator;
19 use Drupal\Console\Extension\Manager;
20 use Drupal\Console\Core\Utils\ChainQueue;
23 * Class GenerateGroupCommand.
25 * Generate a Metatag group plugin.
27 * @package Drupal\metatag
29 class GenerateGroupCommand extends Command {
34 use ConfirmationTrait;
37 * @var MetatagGroupGenerator
42 protected $extensionManager;
47 protected $chainQueue;
50 * GenerateTagCommand constructor.
52 * @param MetatagTagGenerator $generator
53 * @param Manager $extensionManager
54 * @param ChainQueue $chainQueue
56 public function __construct(
57 MetatagGroupGenerator $generator,
58 Manager $extensionManager,
59 ChainQueue $chainQueue
61 $this->generator = $generator;
62 $this->extensionManager = $extensionManager;
63 $this->chainQueue = $chainQueue;
65 parent::__construct();
71 protected function configure() {
73 ->setName('generate:plugin:metatag:group')
74 ->setDescription($this->trans('commands.generate.metatag.group.description'))
75 ->setHelp($this->trans('commands.generate.metatag.group.help'))
76 ->addOption('base_class', '', InputOption::VALUE_REQUIRED,
77 $this->trans('commands.common.options.base_class'))
78 ->addOption('module', '', InputOption::VALUE_REQUIRED,
79 $this->trans('commands.common.options.module'))
80 ->addOption('label', '', InputOption::VALUE_REQUIRED,
81 $this->trans('commands.generate.metatag.group.options.label'))
82 ->addOption('description', '', InputOption::VALUE_OPTIONAL,
83 $this->trans('commands.generate.metatag.group.options.description'))
84 ->addOption('plugin-id', '', InputOption::VALUE_REQUIRED,
85 $this->trans('commands.generate.metatag.group.options.plugin_id'))
86 ->addOption('class-name', '', InputOption::VALUE_REQUIRED,
87 $this->trans('commands.generate.metatag.group.options.class_name'))
88 ->addOption('weight', '', InputOption::VALUE_REQUIRED,
89 $this->trans('commands.generate.metatag.group.options.weight'));
95 protected function execute(InputInterface $input, OutputInterface $output) {
96 $io = new DrupalStyle($input, $output);
98 // @see use Drupal\Console\Command\ConfirmationTrait::confirmGeneration
99 if (!$this->confirmGeneration($io)) {
103 $base_class = $input->getOption('base_class');
104 $module = $input->getOption('module');
105 $label = $input->getOption('label');
106 $description = $input->getOption('description');
107 $plugin_id = $input->getOption('plugin-id');
108 $class_name = $input->getOption('class-name');
109 $weight = $input->getOption('weight');
112 ->generate($base_class, $module, $label, $description, $plugin_id, $class_name, $weight);
114 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
120 protected function interact(InputInterface $input, OutputInterface $output) {
121 $io = new DrupalStyle($input, $output);
123 // --base_class option.
124 // @todo Turn this into a choice() option.
125 $base_class = $input->getOption('base_class');
126 if (empty($base_class)) {
127 $base_class = $io->ask(
128 $this->trans('commands.generate.metatag.group.questions.base_class'),
132 $input->setOption('base_class', $base_class);
135 $module = $input->getOption('module');
136 if (empty($module)) {
137 // @see Drupal\AppConsole\Command\Helper\ModuleTrait::moduleQuestion
138 $module = $this->moduleQuestion($io);
140 $input->setOption('module', $module);
143 $label = $input->getOption('label');
146 $this->trans('commands.generate.metatag.group.questions.label')
149 $input->setOption('label', $label);
151 // --description option.
152 $description = $input->getOption('description');
153 if (empty($description)) {
154 $description = $io->ask(
155 $this->trans('commands.generate.metatag.group.questions.description')
158 $input->setOption('description', $description);
160 // --plugin-id option.
161 $plugin_id = $input->getOption('plugin-id');
162 if (empty($plugin_id)) {
163 $plugin_id = $io->ask(
164 $this->trans('commands.generate.metatag.group.questions.plugin_id')
167 $input->setOption('plugin-id', $plugin_id);
169 // --class-name option.
170 $class_name = $input->getOption('class-name');
171 if (empty($class_name)) {
172 $class_name = $io->ask(
173 $this->trans('commands.generate.metatag.group.questions.class_name')
176 $input->setOption('class-name', $class_name);
179 // @todo Automatically get the next integer value based upon the current
181 $weight = $input->getOption('weight');
182 if (is_null($weight)) {
184 $this->trans('commands.generate.metatag.group.questions.weight'),
188 $input->setOption('weight', $weight);