5 * Contains \Drupal\Console\Command\Generate\PluginViewsFieldCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Utils\Validator;
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\Generator\PluginViewsFieldGenerator;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Command\Command;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Core\Utils\ChainQueue;
20 use Drupal\Console\Utils\Site;
21 use Drupal\Console\Core\Utils\StringConverter;
24 * Class PluginViewsFieldCommand
26 * @package Drupal\Console\Command\Generate
28 class PluginViewsFieldCommand extends Command
31 use ConfirmationTrait;
36 protected $extensionManager;
39 * @var PluginViewsFieldGenerator
49 * @var StringConverter
51 protected $stringConverter;
61 protected $chainQueue;
64 * PluginViewsFieldCommand constructor.
66 * @param Manager $extensionManager
67 * @param PluginViewsFieldGenerator $generator
69 * @param StringConverter $stringConverter
70 * @param Validator $validator
71 * @param ChainQueue $chainQueue
73 public function __construct(
74 Manager $extensionManager,
75 PluginViewsFieldGenerator $generator,
77 StringConverter $stringConverter,
79 ChainQueue $chainQueue
81 $this->extensionManager = $extensionManager;
82 $this->generator = $generator;
84 $this->stringConverter = $stringConverter;
85 $this->validator = $validator;
86 $this->chainQueue = $chainQueue;
87 parent::__construct();
90 protected function configure()
93 ->setName('generate:plugin:views:field')
94 ->setDescription($this->trans('commands.generate.plugin.views.field.description'))
95 ->setHelp($this->trans('commands.generate.plugin.views.field.help'))
99 InputOption::VALUE_REQUIRED,
100 $this->trans('commands.common.options.module')
105 InputOption::VALUE_REQUIRED,
106 $this->trans('commands.generate.plugin.views.field.options.class')
111 InputOption::VALUE_OPTIONAL,
112 $this->trans('commands.generate.plugin.views.field.options.title')
117 InputOption::VALUE_OPTIONAL,
118 $this->trans('commands.generate.plugin.views.field.options.description')
120 ->setAliases(['gpvf']);
126 protected function execute(InputInterface $input, OutputInterface $output)
128 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
129 if (!$this->confirmOperation()) {
133 $module = $input->getOption('module');
134 $class_name = $this->validator->validateClassName($input->getOption('class'));
135 $class_machine_name = $this->stringConverter->camelCaseToUnderscore($class_name);
136 $title = $input->getOption('title');
137 $description = $input->getOption('description');
139 $this->generator->generate([
141 'class_machine_name' => $class_machine_name,
142 'class_name' => $class_name,
144 'description' => $description,
147 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'discovery']);
152 protected function interact(InputInterface $input, OutputInterface $output)
155 $this->getModuleOption();
158 $class_name = $input->getOption('class');
160 $class_name = $this->getIo()->ask(
161 $this->trans('commands.generate.plugin.views.field.questions.class'),
163 function ($class_name) {
164 return $this->validator->validateClassName($class_name);
168 $input->setOption('class', $class_name);
171 $title = $input->getOption('title');
173 $title = $this->getIo()->ask(
174 $this->trans('commands.generate.plugin.views.field.questions.title'),
175 $this->stringConverter->camelCaseToHuman($class_name)
177 $input->setOption('title', $title);
180 // --description option
181 $description = $input->getOption('description');
183 $description = $this->getIo()->ask(
184 $this->trans('commands.generate.plugin.views.field.questions.description'),
185 $this->trans('commands.generate.plugin.views.field.questions.description_default')
187 $input->setOption('description', $description);