Skip to content

Commit fb12331

Browse files
committed
Add code to ask class of the new Entity
1 parent fc2f6cd commit fb12331

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

src/Command/GeneratorEntityCommand.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ protected function configure()
2424
$this
2525
->setDefinition(array(
2626
new InputOption('module','',InputOption::VALUE_REQUIRED, 'The name of the module'),
27-
new InputOption('entity','',InputOption::VALUE_REQUIRED, 'The name of the entity')
27+
new InputOption('entity','',InputOption::VALUE_REQUIRED, 'The name of the entity'),
28+
new InputOption('class','',InputOption::VALUE_REQUIRED, 'The class of the entity')
2829
))
2930
->setName('generate:entity')
3031
->setDescription('Generate entity')
@@ -37,10 +38,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
3738

3839
$module = $input->getOption('module');
3940
$entity = $input->getOption('entity');
40-
41+
$class = $input->getOption('class');
42+
4143
$this
4244
->getGenerator()
43-
->generate($module, $entity);
45+
->generate($module, $entity, $class);
4446

4547
$errors = [];
4648
$dialog->writeGeneratorSummary($output, $errors);
@@ -73,6 +75,26 @@ protected function interact(InputInterface $input, OutputInterface $output)
7375
}
7476
$input->setOption('entity', $entity);
7577

78+
// --entity option
79+
$entity = $input->getOption('entity');
80+
if (!$entity) {
81+
$entity = $dialog->ask(
82+
$output,
83+
$dialog->getQuestion('Enter the entity name', '')
84+
);
85+
}
86+
$input->setOption('entity', $entity);
87+
88+
// --class option
89+
$class = $input->getOption('class');
90+
if (!$class) {
91+
$class = $dialog->askConfirmation(
92+
$output,
93+
$dialog->getQuestion('Enter the class of the entity', 'ConfigEntityType', '?'),
94+
true
95+
);
96+
}
97+
$input->setOption('class', $class);
7698
}
7799

78100

src/Generator/EntityGenerator.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ class EntityGenerator extends Generator
1515
* @param string $class_name Class name
1616
* @param array $services List of services
1717
*/
18-
public function generate($module, $entity)
18+
public function generate($module, $entity, $class)
1919
{
2020

2121
$parameters = [
2222
'module' => $module,
23-
'entity' => $entity
23+
'entity' => $entity,
24+
'class' => $class,
2425
];
2526

27+
//switch ConfigEntityType or ContentEntityType
28+
2629
$this->renderFile(
2730
'module/config/schema/entity.schema.yml.twig',
2831
$this->getModulePath($module). '/config/schema/' . $entity . '.schema.yml',

0 commit comments

Comments
 (0)