5 * Contains \Drupal\Console\Command\Generate\PluginBlockCommand.
8 namespace Drupal\Console\Command\Generate;
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\Core\Command\ContainerAwareCommand;
14 use Drupal\Console\Generator\PluginMigrateSourceGenerator;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Extension\Manager;
18 use Drupal\Console\Utils\Validator;
19 use Drupal\Console\Core\Utils\StringConverter;
20 use Drupal\Console\Core\Utils\ChainQueue;
21 use Drupal\Core\Config\ConfigFactory;
22 use Drupal\Core\Entity\EntityTypeManagerInterface;
23 use Drupal\Core\Render\ElementInfoManagerInterface;
25 class PluginMigrateSourceCommand extends ContainerAwareCommand
28 use ConfirmationTrait;
33 protected $configFactory;
38 protected $chainQueue;
41 * @var PluginMigrateSourceGenerator
46 * @var EntityTypeManagerInterface
48 protected $entityTypeManager;
53 protected $extensionManager;
61 * @var StringConverter
63 protected $stringConverter;
66 * @var ElementInfoManagerInterface
68 protected $elementInfoManager;
71 * PluginBlockCommand constructor.
73 * @param ConfigFactory $configFactory
74 * @param ChainQueue $chainQueue
75 * @param PluginBlockGenerator $generator
76 * @param EntityTypeManagerInterface $entityTypeManager
77 * @param Manager $extensionManager
78 * @param Validator $validator
79 * @param StringConverter $stringConverter
80 * @param ElementInfoManagerInterface $elementInfoManager
82 public function __construct(
83 ConfigFactory $configFactory,
84 ChainQueue $chainQueue,
85 PluginMigrateSourceGenerator $generator,
86 EntityTypeManagerInterface $entityTypeManager,
87 Manager $extensionManager,
89 StringConverter $stringConverter,
90 ElementInfoManagerInterface $elementInfoManager
92 $this->configFactory = $configFactory;
93 $this->chainQueue = $chainQueue;
94 $this->generator = $generator;
95 $this->entityTypeManager = $entityTypeManager;
96 $this->extensionManager = $extensionManager;
97 $this->validator = $validator;
98 $this->stringConverter = $stringConverter;
99 $this->elementInfoManager = $elementInfoManager;
100 parent::__construct();
103 protected function configure()
106 ->setName('generate:plugin:migrate:source')
107 ->setDescription($this->trans('commands.generate.plugin.migrate.source.description'))
108 ->setHelp($this->trans('commands.generate.plugin.migrate.source.help'))
112 InputOption::VALUE_REQUIRED,
113 $this->trans('commands.common.options.module')
118 InputOption::VALUE_OPTIONAL,
119 $this->trans('commands.generate.plugin.migrate.source.options.class')
124 InputOption::VALUE_OPTIONAL,
125 $this->trans('commands.generate.plugin.migrate.source.options.plugin-id')
130 InputOption::VALUE_OPTIONAL,
131 $this->trans('commands.generate.plugin.migrate.source.options.table')
136 InputOption::VALUE_OPTIONAL,
137 $this->trans('commands.generate.plugin.migrate.source.options.alias')
142 InputOption::VALUE_OPTIONAL,
143 $this->trans('commands.generate.plugin.migrate.source.options.group-by')
148 InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
149 $this->trans('commands.generate.plugin.migrate.source.options.fields')
150 )->setAliases(['gpms']);
156 protected function execute(InputInterface $input, OutputInterface $output)
158 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
159 if (!$this->confirmOperation()) {
163 $module = $input->getOption('module');
164 $class_name = $this->validator->validateClassName($input->getOption('class'));
165 $plugin_id = $input->getOption('plugin-id');
166 $table = $input->getOption('table');
167 $alias = $input->getOption('alias');
168 $group_by = $input->getOption('group-by');
169 $fields = $input->getOption('fields');
171 $this->generator->generate([
173 'class_name' => $class_name,
174 'plugin_id' => $plugin_id,
177 'group_by' => $group_by,
181 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
184 protected function interact(InputInterface $input, OutputInterface $output)
186 // 'module-name' option.
187 $module = $this->getModuleOption();
189 $class = $input->getOption('class');
191 $class = $this->getIo()->ask(
192 $this->trans('commands.generate.plugin.migrate.source.questions.class'),
193 ucfirst($this->stringConverter->underscoreToCamelCase($module)),
195 return $this->validator->validateClassName($class);
198 $input->setOption('class', $class);
201 $pluginId = $input->getOption('plugin-id');
203 $pluginId = $this->getIo()->ask(
204 $this->trans('commands.generate.plugin.migrate.source.questions.plugin-id'),
205 $this->stringConverter->camelCaseToUnderscore($class)
207 $input->setOption('plugin-id', $pluginId);
210 $table = $input->getOption('table');
212 $table = $this->getIo()->ask(
213 $this->trans('commands.generate.plugin.migrate.source.questions.table'),
216 $input->setOption('table', $table);
219 $alias = $input->getOption('alias');
221 $alias = $this->getIo()->ask(
222 $this->trans('commands.generate.plugin.migrate.source.questions.alias'),
225 $input->setOption('alias', $alias);
228 $groupBy = $input->getOption('group-by');
229 if ($groupBy == '') {
230 $groupBy = $this->getIo()->ask(
231 $this->trans('commands.generate.plugin.migrate.source.questions.group-by'),
234 $input->setOption('group-by', $groupBy);
237 $fields = $input->getOption('fields');
241 $id = $this->getIo()->ask(
242 $this->trans('commands.generate.plugin.migrate.source.questions.id'),
248 $description = $this->getIo()->ask(
249 $this->trans('commands.generate.plugin.migrate.source.questions.description'),
254 'description' => $description,
257 $input->setOption('fields', $fields);