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\ContentTypeGenerator;
19 use Drupal\Console\Generator\EntityBundleGenerator;
20 use Drupal\Console\Core\Style\DrupalStyle;
21 use Drupal\Console\Extension\Manager;
22 use Drupal\Console\Utils\Validator;
24 class EntityBundleCommand extends Command
29 use ConfirmationTrait;
38 * @var EntityBundleGenerator
45 protected $extensionManager;
48 * EntityBundleCommand constructor.
50 * @param Validator $validator
51 * @param EntityBundleGenerator $generator
52 * @param Manager $extensionManager
54 public function __construct(
56 EntityBundleGenerator $generator,
57 Manager $extensionManager
59 $this->validator = $validator;
60 $this->generator = $generator;
61 $this->extensionManager = $extensionManager;
62 parent::__construct();
66 protected function configure()
69 ->setName('generate:entity:bundle')
70 ->setDescription($this->trans('commands.generate.entity.bundle.description'))
71 ->setHelp($this->trans('commands.generate.entity.bundle.help'))
72 ->addOption('module', '', InputOption::VALUE_REQUIRED, $this->trans('commands.common.options.module'))
76 InputOption::VALUE_OPTIONAL,
77 $this->trans('commands.generate.entity.bundle.options.bundle-name')
82 InputOption::VALUE_OPTIONAL,
83 $this->trans('commands.generate.entity.bundle.options.bundle-title')
90 protected function execute(InputInterface $input, OutputInterface $output)
92 $io = new DrupalStyle($input, $output);
94 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmGeneration
95 if (!$this->confirmGeneration($io)) {
99 $module = $input->getOption('module');
100 $bundleName = $input->getOption('bundle-name');
101 $bundleTitle = $input->getOption('bundle-title');
102 $learning = $input->hasOption('learning')?$input->getOption('learning'):false;
104 $generator = $this->generator;
106 //$generator->setLearning($learning);
107 $generator->generate($module, $bundleName, $bundleTitle);
113 protected function interact(InputInterface $input, OutputInterface $output)
115 $io = new DrupalStyle($input, $output);
118 $module = $input->getOption('module');
120 // @see Drupal\Console\Command\Shared\ModuleTrait::moduleQuestion
121 $module = $this->moduleQuestion($io);
122 $input->setOption('module', $module);
125 // --bundle-name option
126 $bundleName = $input->getOption('bundle-name');
128 $bundleName = $io->ask(
129 $this->trans('commands.generate.entity.bundle.questions.bundle-name'),
131 function ($bundleName) {
132 return $this->validator->validateClassName($bundleName);
135 $input->setOption('bundle-name', $bundleName);
138 // --bundle-title option
139 $bundleTitle = $input->getOption('bundle-title');
141 $bundleTitle = $io->ask(
142 $this->trans('commands.generate.entity.bundle.questions.bundle-title'),
144 function ($bundle_title) {
145 return $this->validator->validateBundleTitle($bundle_title);
148 $input->setOption('bundle-title', $bundleTitle);