5 * Contains \Drupal\Console\Command\Generate\PluginTypeAnnotationCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Generator\PluginTypeAnnotationGenerator;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Drupal\Console\Command\Shared\ServicesTrait;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\FormTrait;
17 use Drupal\Console\Command\Shared\ConfirmationTrait;
18 use Symfony\Component\Console\Command\Command;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Core\Command\Shared\CommandTrait;
21 use Drupal\Console\Extension\Manager;
22 use Drupal\Console\Core\Utils\StringConverter;
25 * Class PluginTypeAnnotationCommand
27 * @package Drupal\Console\Command\Generate
29 class PluginTypeAnnotationCommand extends Command
34 use ConfirmationTrait;
40 protected $extensionManager;
43 * @var PluginTypeAnnotationGenerator
48 * @var StringConverter
50 protected $stringConverter;
53 * PluginTypeAnnotationCommand constructor.
55 * @param Manager $extensionManager
56 * @param PluginTypeAnnotationGenerator $generator
57 * @param StringConverter $stringConverter
59 public function __construct(
60 Manager $extensionManager,
61 PluginTypeAnnotationGenerator $generator,
62 StringConverter $stringConverter
64 $this->extensionManager = $extensionManager;
65 $this->generator = $generator;
66 $this->stringConverter = $stringConverter;
67 parent::__construct();
70 protected function configure()
73 ->setName('generate:plugin:type:annotation')
74 ->setDescription($this->trans('commands.generate.plugin.type.annotation.description'))
75 ->setHelp($this->trans('commands.generate.plugin.type.annotation.help'))
76 ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
80 InputOption::VALUE_OPTIONAL,
81 $this->trans('commands.generate.plugin.type.annotation.options.class')
86 InputOption::VALUE_OPTIONAL,
87 $this->trans('commands.generate.plugin.type.annotation.options.plugin-id')
92 InputOption::VALUE_OPTIONAL,
93 $this->trans('commands.generate.plugin.type.annotation.options.label')
100 protected function execute(InputInterface $input, OutputInterface $output)
102 $module = $input->getOption('module');
103 $class_name = $input->getOption('class');
104 $machine_name = $input->getOption('machine-name');
105 $label = $input->getOption('label');
107 $this->generator->generate($module, $class_name, $machine_name, $label);
110 protected function interact(InputInterface $input, OutputInterface $output)
112 $io = new DrupalStyle($input, $output);
115 $module = $input->getOption('module');
117 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
118 $module = $this->moduleQuestion($io);
119 $input->setOption('module', $module);
123 $class_name = $input->getOption('class');
125 $class_name = $io->ask(
126 $this->trans('commands.generate.plugin.type.annotation.options.class'),
129 $input->setOption('class', $class_name);
132 // --machine-name option
133 $machine_name = $input->getOption('machine-name');
134 if (!$machine_name) {
135 $machine_name = $io->ask(
136 $this->trans('commands.generate.plugin.type.annotation.options.machine-name'),
137 $this->stringConverter->camelCaseToUnderscore($class_name)
139 $input->setOption('machine-name', $machine_name);
143 $label = $input->getOption('label');
146 $this->trans('commands.generate.plugin.type.annotation.options.label'),
147 $this->stringConverter->camelCaseToHuman($class_name)
149 $input->setOption('label', $label);