5 * Contains Drupal\Console\Command\Generate\EntityBundleCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Symfony\Component\Console\Command\Command;
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\ConfirmationTrait;
15 use Drupal\Console\Command\Shared\ModuleTrait;
16 use Drupal\Console\Command\Shared\ServicesTrait;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Generator\EntityBundleGenerator;
19 use Drupal\Console\Core\Style\DrupalStyle;
20 use Drupal\Console\Extension\Manager;
21 use Drupal\Console\Utils\Validator;
23 class EntityBundleCommand extends Command
28 use ConfirmationTrait;
36 * @var EntityBundleGenerator
43 protected $extensionManager;
46 * EntityBundleCommand constructor.
48 * @param Validator $validator
49 * @param EntityBundleGenerator $generator
50 * @param Manager $extensionManager
52 public function __construct(
54 EntityBundleGenerator $generator,
55 Manager $extensionManager
57 $this->validator = $validator;
58 $this->generator = $generator;
59 $this->extensionManager = $extensionManager;
60 parent::__construct();
64 protected function configure()
67 ->setName('generate:entity:bundle')
68 ->setDescription($this->trans('commands.generate.entity.bundle.description'))
69 ->setHelp($this->trans('commands.generate.entity.bundle.help'))
70 ->addOption('module', null, InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
74 InputOption::VALUE_OPTIONAL,
75 $this->trans('commands.generate.entity.bundle.options.bundle-name')
80 InputOption::VALUE_OPTIONAL,
81 $this->trans('commands.generate.entity.bundle.options.bundle-title')
88 protected function execute(InputInterface $input, OutputInterface $output)
90 $io = new DrupalStyle($input, $output);
92 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
93 if (!$this->confirmGeneration($io)) {
97 $module = $input->getOption('module');
98 $bundleName = $input->getOption('bundle-name');
99 $bundleTitle = $input->getOption('bundle-title');
101 $generator = $this->generator;
103 // $generator->setLearning($learning);
104 $generator->generate($module, $bundleName, $bundleTitle);
112 protected function interact(InputInterface $input, OutputInterface $output)
114 $io = new DrupalStyle($input, $output);
117 $module = $input->getOption('module');
119 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
120 $module = $this->moduleQuestion($io);
121 $input->setOption('module', $module);
124 // --bundle-name option
125 $bundleName = $input->getOption('bundle-name');
127 $bundleName = $io->ask(
128 $this->trans('commands.generate.entity.bundle.questions.bundle-name'),
130 function ($bundleName) {
131 return $this->validator->validateClassName($bundleName);
134 $input->setOption('bundle-name', $bundleName);
137 // --bundle-title option
138 $bundleTitle = $input->getOption('bundle-title');
140 $bundleTitle = $io->ask(
141 $this->trans('commands.generate.entity.bundle.questions.bundle-title'),
143 function ($bundle_title) {
144 return $this->validator->validateBundleTitle($bundle_title);
147 $input->setOption('bundle-title', $bundleTitle);