5 * Contains \Drupal\Console\Command\Generate\EntityContentCommand.
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\EntityContentGenerator;
14 use Drupal\Console\Extension\Manager;
15 use Drupal\Console\Core\Utils\StringConverter;
16 use Drupal\Console\Core\Utils\ChainQueue;
17 use Drupal\Console\Utils\Validator;
18 use Drupal\Console\Core\Style\DrupalStyle;
20 class EntityContentCommand extends EntityCommand
25 protected $chainQueue;
28 * @var EntityContentGenerator
33 * @var StringConverter
35 protected $stringConverter;
40 protected $extensionManager;
48 * EntityContentCommand constructor.
50 * @param ChainQueue $chainQueue
51 * @param EntityContentGenerator $generator
52 * @param StringConverter $stringConverter
53 * @param Manager $extensionManager
54 * @param Validator $validator
56 public function __construct(
57 ChainQueue $chainQueue,
58 EntityContentGenerator $generator,
59 StringConverter $stringConverter,
60 Manager $extensionManager,
63 $this->chainQueue = $chainQueue;
64 $this->generator = $generator;
65 $this->stringConverter = $stringConverter;
66 $this->extensionManager = $extensionManager;
67 $this->validator = $validator;
68 parent::__construct();
75 protected function configure()
77 $this->setEntityType('EntityContent');
78 $this->setCommandName('generate:entity:content');
84 InputOption::VALUE_NONE,
85 $this->trans('commands.generate.entity.content.options.has-bundles')
91 InputOption::VALUE_NONE,
92 $this->trans('commands.generate.entity.content.options.is-translatable')
98 InputOption::VALUE_NONE,
99 $this->trans('commands.generate.entity.content.options.revisionable')
106 protected function interact(InputInterface $input, OutputInterface $output)
108 parent::interact($input, $output);
109 $io = new DrupalStyle($input, $output);
111 // --bundle-of option
112 $bundle_of = $input->getOption('has-bundles');
114 $bundle_of = $io->confirm(
115 $this->trans('commands.generate.entity.content.questions.has-bundles'),
118 $input->setOption('has-bundles', $bundle_of);
121 // --is-translatable option
122 $is_translatable = $io->confirm(
123 $this->trans('commands.generate.entity.content.questions.is-translatable'),
126 $input->setOption('is-translatable', $is_translatable);
128 // --revisionable option
129 $revisionable = $io->confirm(
130 $this->trans('commands.generate.entity.content.questions.revisionable'),
133 $input->setOption('revisionable', $revisionable);
139 protected function execute(InputInterface $input, OutputInterface $output)
141 $module = $input->getOption('module');
142 $entity_class = $input->getOption('entity-class');
143 $entity_name = $input->getOption('entity-name');
144 $label = $input->getOption('label');
145 $has_bundles = $input->getOption('has-bundles');
146 $base_path = $input->getOption('base-path');
147 $learning = $input->hasOption('learning')?$input->getOption('learning'):false;
148 $bundle_entity_name = $has_bundles ? $entity_name . '_type' : null;
149 $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true;
150 $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false;
152 $io = new DrupalStyle($input, $output);
153 $generator = $this->generator;
155 $generator->setIo($io);
157 //$generator->setLearning($learning);
159 $generator->generate($module, $entity_name, $entity_class, $label, $base_path, $is_translatable, $bundle_entity_name, $revisionable);
162 $this->chainQueue->addCommand(
163 'generate:entity:config', [
164 '--module' => $module,
165 '--entity-class' => $entity_class . 'Type',
166 '--entity-name' => $entity_name . '_type',
167 '--label' => $label . ' type',
168 '--bundle-of' => $entity_name