5 * Contains \Drupal\Console\Command\Generate\PluginViewsFieldCommand.
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\Generator\PluginViewsFieldGenerator;
14 use Drupal\Console\Command\Shared\ModuleTrait;
15 use Drupal\Console\Command\Shared\ConfirmationTrait;
16 use Symfony\Component\Console\Command\Command;
17 use Drupal\Console\Core\Style\DrupalStyle;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\ChainQueue;
20 use Drupal\Console\Core\Command\Shared\CommandTrait;
21 use Drupal\Console\Utils\Site;
22 use Drupal\Console\Core\Utils\StringConverter;
25 * Class PluginViewsFieldCommand
27 * @package Drupal\Console\Command\Generate
29 class PluginViewsFieldCommand extends Command
32 use ConfirmationTrait;
39 protected $extensionManager;
42 * @var PluginViewsFieldGenerator
52 * @var StringConverter
54 protected $stringConverter;
59 protected $chainQueue;
62 * PluginViewsFieldCommand constructor.
64 * @param Manager $extensionManager
65 * @param PluginViewsFieldGenerator $generator
67 * @param StringConverter $stringConverter
68 * @param ChainQueue $chainQueue
70 public function __construct(
71 Manager $extensionManager,
72 PluginViewsFieldGenerator $generator,
74 StringConverter $stringConverter,
75 ChainQueue $chainQueue
77 $this->extensionManager = $extensionManager;
78 $this->generator = $generator;
80 $this->stringConverter = $stringConverter;
81 $this->chainQueue = $chainQueue;
82 parent::__construct();
85 protected function configure()
88 ->setName('generate:plugin:views:field')
89 ->setDescription($this->trans('commands.generate.plugin.views.field.description'))
90 ->setHelp($this->trans('commands.generate.plugin.views.field.help'))
91 ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
95 InputOption::VALUE_REQUIRED,
96 $this->trans('commands.generate.plugin.views.field.options.class')
101 InputOption::VALUE_OPTIONAL,
102 $this->trans('commands.generate.plugin.views.field.options.title')
107 InputOption::VALUE_OPTIONAL,
108 $this->trans('commands.generate.plugin.views.field.options.description')
115 protected function execute(InputInterface $input, OutputInterface $output)
117 $io = new DrupalStyle($input, $output);
119 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
120 if (!$this->confirmGeneration($io)) {
124 $module = $input->getOption('module');
125 $class_name = $input->getOption('class');
126 $class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name);
127 $title = $input->getOption('title');
128 $description = $input->getOption('description');
130 $this->generator->generate($module, $class_machine_name, $class_name, $title, $description);
132 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
137 protected function interact(InputInterface $input, OutputInterface $output)
139 $io = new DrupalStyle($input, $output);
142 $module = $input->getOption('module');
144 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
145 $module = $this->moduleQuestion($io);
146 $input->setOption('module', $module);
150 $class_name = $input->getOption('class');
152 $class_name = $io->ask(
153 $this->trans('commands.generate.plugin.views.field.questions.class'),
157 $input->setOption('class', $class_name);
160 $title = $input->getOption('title');
163 $this->trans('commands.generate.plugin.views.field.questions.title'),
164 $this->stringConverter->camelCaseToHuman($class_name)
166 $input->setOption('title', $title);
169 // --description option
170 $description = $input->getOption('description');
172 $description = $io->ask(
173 $this->trans('commands.generate.plugin.views.field.questions.description'),
174 $this->trans('commands.generate.plugin.views.field.questions.description_default')
176 $input->setOption('description', $description);
180 protected function createGenerator()
182 return new PluginViewsFieldGenerator();