5 * Contains \Drupal\Console\Command\Generate\PluginTypeYamlCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Generator\PluginTypeYamlGenerator;
11 use Drupal\Console\Utils\Validator;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Input\InputOption;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Drupal\Console\Command\Shared\ServicesTrait;
16 use Drupal\Console\Command\Shared\ModuleTrait;
17 use Drupal\Console\Core\Command\Command;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\StringConverter;
22 * Class PluginTypeYamlCommand
24 * @package Drupal\Console\Command\Generate
26 class PluginTypeYamlCommand extends Command
34 protected $extensionManager;
37 * @var PluginTypeYamlGenerator
42 * @var StringConverter
44 protected $stringConverter;
52 * PluginTypeYamlCommand constructor.
54 * @param Manager $extensionManager
55 * @param PluginTypeYamlGenerator $generator
56 * @param StringConverter $stringConverter
57 * @param Validator $validator
59 public function __construct(
60 Manager $extensionManager,
61 PluginTypeYamlGenerator $generator,
62 StringConverter $stringConverter,
65 $this->extensionManager = $extensionManager;
66 $this->generator = $generator;
67 $this->stringConverter = $stringConverter;
68 $this->validator = $validator;
69 parent::__construct();
72 protected function configure()
75 ->setName('generate:plugin:type:yaml')
76 ->setDescription($this->trans('commands.generate.plugin.type.yaml.description'))
77 ->setHelp($this->trans('commands.generate.plugin.type.yaml.help'))
81 InputOption::VALUE_REQUIRED,
82 $this->trans('commands.common.options.module')
87 InputOption::VALUE_OPTIONAL,
88 $this->trans('commands.generate.plugin.type.yaml.options.class')
93 InputOption::VALUE_OPTIONAL,
94 $this->trans('commands.generate.plugin.type.yaml.options.plugin-name')
99 InputOption::VALUE_OPTIONAL,
100 $this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name')
102 ->setAliases(['gpty']);
108 protected function execute(InputInterface $input, OutputInterface $output)
110 $module = $input->getOption('module');
111 $class_name = $this->validator->validateClassName($input->getOption('class'));
112 $plugin_name = $input->getOption('plugin-name');
113 $plugin_file_name = $input->getOption('plugin-file-name');
115 $this->generator->generate([
117 'class_name' => $class_name,
118 'plugin_name' => $plugin_name,
119 'plugin_file_name' => $plugin_file_name,
123 protected function interact(InputInterface $input, OutputInterface $output)
126 $this->getModuleOption();
129 $class_name = $input->getOption('class');
131 $class_name = $this->getIo()->ask(
132 $this->trans('commands.generate.plugin.type.yaml.options.class'),
135 return $this->validator->validateClassName($class);
138 $input->setOption('class', $class_name);
141 // --plugin-name option
142 $plugin_name = $input->getOption('plugin-name');
144 $plugin_name = $this->getIo()->ask(
145 $this->trans('commands.generate.plugin.type.yaml.options.plugin-name'),
146 $this->stringConverter->camelCaseToUnderscore($class_name)
148 $input->setOption('plugin-name', $plugin_name);
151 // --plugin-file-name option
152 $plugin_file_name = $input->getOption('plugin-file-name');
153 if (!$plugin_file_name) {
154 $plugin_file_name = $this->getIo()->ask(
155 $this->trans('commands.generate.plugin.type.yaml.options.plugin-file-name'),
156 strtr($plugin_name, '_-', '..')
158 $input->setOption('plugin-file-name', $plugin_file_name);