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;
19 class EntityContentCommand extends EntityCommand
24 protected $chainQueue;
27 * @var EntityContentGenerator
32 * @var StringConverter
34 protected $stringConverter;
39 protected $extensionManager;
47 * EntityContentCommand constructor.
49 * @param ChainQueue $chainQueue
50 * @param EntityContentGenerator $generator
51 * @param StringConverter $stringConverter
52 * @param Manager $extensionManager
53 * @param Validator $validator
55 public function __construct(
56 ChainQueue $chainQueue,
57 EntityContentGenerator $generator,
58 StringConverter $stringConverter,
59 Manager $extensionManager,
62 $this->chainQueue = $chainQueue;
63 $this->generator = $generator;
64 $this->stringConverter = $stringConverter;
65 $this->extensionManager = $extensionManager;
66 $this->validator = $validator;
67 parent::__construct();
74 protected function configure()
76 $this->setEntityType('EntityContent');
77 $this->setCommandName('generate:entity:content');
82 InputOption::VALUE_NONE,
83 $this->trans('commands.generate.entity.content.options.has-bundles')
89 InputOption::VALUE_NONE,
90 $this->trans('commands.generate.entity.content.options.is-translatable')
96 InputOption::VALUE_NONE,
97 $this->trans('commands.generate.entity.content.options.revisionable')
99 ->setAliases(['geco']);
105 protected function interact(InputInterface $input, OutputInterface $output)
107 parent::interact($input, $output);
109 // --bundle-of option
110 $bundle_of = $input->getOption('has-bundles');
112 $bundle_of = $this->getIo()->confirm(
113 $this->trans('commands.generate.entity.content.questions.has-bundles'),
116 $input->setOption('has-bundles', $bundle_of);
119 // --is-translatable option
120 $is_translatable = $this->getIo()->confirm(
121 $this->trans('commands.generate.entity.content.questions.is-translatable'),
124 $input->setOption('is-translatable', $is_translatable);
126 // --revisionable option
127 $revisionable = $this->getIo()->confirm(
128 $this->trans('commands.generate.entity.content.questions.revisionable'),
131 $input->setOption('revisionable', $revisionable);
137 protected function execute(InputInterface $input, OutputInterface $output)
139 $module = $input->getOption('module');
140 $entity_class = $input->getOption('entity-class');
141 $entity_name = $input->getOption('entity-name');
142 $label = $input->getOption('label');
143 $has_bundles = $input->getOption('has-bundles');
144 $base_path = $input->getOption('base-path');
145 $learning = $input->hasOption('learning')?$input->getOption('learning'):false;
146 $bundle_entity_type = $has_bundles ? $entity_name . '_type' : null;
147 $is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true;
148 $revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false;
150 $generator = $this->generator;
152 $generator->setIo($this->getIo());
154 //$generator->setLearning($learning);
156 $generator->generate([
158 'entity_name' => $entity_name,
159 'entity_class' => $entity_class,
161 'bundle_entity_type' => $bundle_entity_type,
162 'base_path' => $base_path,
163 'is_translatable' => $is_translatable,
164 'revisionable' => $revisionable,
168 $this->chainQueue->addCommand(
169 'generate:entity:config', [
170 '--module' => $module,
171 '--entity-class' => $entity_class . 'Type',
172 '--entity-name' => $entity_name . '_type',
173 '--label' => $label . ' type',
174 '--bundle-of' => $entity_name