5 * Contains Drupal\Console\Command\Generate\EntityBundleCommand.
8 namespace Drupal\Console\Command\Generate;
10 use Drupal\Console\Core\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\Generator\EntityBundleGenerator;
18 use Drupal\Console\Extension\Manager;
19 use Drupal\Console\Utils\Validator;
21 class EntityBundleCommand extends Command
25 use ConfirmationTrait;
33 * @var EntityBundleGenerator
40 protected $extensionManager;
43 * EntityBundleCommand constructor.
45 * @param Validator $validator
46 * @param EntityBundleGenerator $generator
47 * @param Manager $extensionManager
49 public function __construct(
51 EntityBundleGenerator $generator,
52 Manager $extensionManager
54 $this->validator = $validator;
55 $this->generator = $generator;
56 $this->extensionManager = $extensionManager;
57 parent::__construct();
61 protected function configure()
64 ->setName('generate:entity:bundle')
65 ->setDescription($this->trans('commands.generate.entity.bundle.description'))
66 ->setHelp($this->trans('commands.generate.entity.bundle.help'))
70 InputOption::VALUE_REQUIRED,
71 $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')
85 ->setAliases(['geb']);
91 protected function execute(InputInterface $input, OutputInterface $output)
93 // @see use Drupal\Console\Command\Shared\ConfirmationTrait::confirmOperation
94 if (!$this->confirmOperation()) {
98 $module = $input->getOption('module');
99 $bundleName = $input->getOption('bundle-name');
100 $bundleTitle = $input->getOption('bundle-title');
103 // $generator->setLearning($learning);
104 $this->generator->generate([
106 'bundle_name' => $bundleName,
107 'bundle_title' => $bundleTitle,
116 protected function interact(InputInterface $input, OutputInterface $output)
119 $this->getModuleOption();
121 // --bundle-name option
122 $bundleName = $input->getOption('bundle-name');
124 $bundleName = $this->getIo()->ask(
125 $this->trans('commands.generate.entity.bundle.questions.bundle-name'),
127 function ($bundleName) {
128 return $this->validator->validateClassName($bundleName);
131 $input->setOption('bundle-name', $bundleName);
134 // --bundle-title option
135 $bundleTitle = $input->getOption('bundle-title');
137 $bundleTitle = $this->getIo()->ask(
138 $this->trans('commands.generate.entity.bundle.questions.bundle-title'),
140 function ($bundle_title) {
141 return $this->validator->validateBundleTitle($bundle_title);
144 $input->setOption('bundle-title', $bundleTitle);