Skip to content

Commit

Permalink
[generate:entity:content] Enabled has-form option (#4058)
Browse files Browse the repository at this point in the history
* [generate:entity:content] Enabled has-form option

* [generate:entity:content] Set true value the has-forms option as default
  • Loading branch information
hjuarez20 authored and enzolutions committed May 22, 2019
1 parent a026e44 commit 5d6a21a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 80 deletions.
35 changes: 27 additions & 8 deletions src/Command/Generate/EntityContentCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ protected function configure()
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.entity.content.options.revisionable')
);

$this->addOption(
'has-forms',
null,
InputOption::VALUE_NONE,
$this->trans('commands.generate.entity.content.options.has-forms')
)
->setAliases(['geco']);
}
Expand Down Expand Up @@ -129,6 +136,13 @@ protected function interact(InputInterface $input, OutputInterface $output)
true
);
$input->setOption('revisionable', $revisionable);

// --has-forms option
$has_forms = $this->getIo()->confirm(
$this->trans('commands.generate.entity.content.questions.has-forms'),
true
);
$input->setOption('has-forms', $has_forms);
}

/**
Expand All @@ -137,16 +151,20 @@ protected function interact(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output)
{
$module = $this->validateModule($input->getOption('module'));
$entity_class = $input->getOption('entity-class');
$entity_name = $this->validator->validateMachineName($input->getOption('entity-name'));
$label = $input->getOption('label');
$has_bundles = $input->getOption('has-bundles');
$base_path = $input->getOption('base-path');
$learning = $input->hasOption('learning')?$input->getOption('learning'):false;
$entity_class = $input->getOption('entity-class')?:'DefaultEntity';
$entity_name = $this->validator->validateMachineName($input->getOption('entity-name'))?:'default_entity';
$label = $input->getOption('label')?:'Default Entity';
$has_bundles = $input->getOption('has-bundles')?:false;
$base_path = $input->getOption('base-path')?:'/admin/structure';
$learning = $input->getOption('learning')?:false;
$bundle_entity_type = $has_bundles ? $entity_name . '_type' : null;
$is_translatable = $input->hasOption('is-translatable') ? $input->getOption('is-translatable') : true;
$revisionable = $input->hasOption('revisionable') ? $input->getOption('revisionable') : false;
$is_translatable = $input->getOption('is-translatable')? : true;
$revisionable = $input->getOption('revisionable')? :false;
$has_forms = $input->getOption('has-forms')?:true;

var_dump($input->hasOption('has-forms'));
var_dump($input->getOption('has-forms'));
var_dump($has_forms);
$generator = $this->generator;

$generator->setIo($this->getIo());
Expand All @@ -162,6 +180,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'base_path' => $base_path,
'is_translatable' => $is_translatable,
'revisionable' => $revisionable,
'has_forms' => $has_forms,
]);

if ($has_bundles) {
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/EntityConfigGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function generate(array $parameters)

$this->renderFile(
'module/src/Entity/interface-entity.php.twig',
$moduleSourcePath . 'Interface.php',
$moduleEntityPath . 'Interface.php',
$parameters
);

Expand Down
149 changes: 80 additions & 69 deletions src/Generator/EntityContentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function generate(array $parameters)
$bundle_entity_type = $parameters['bundle_entity_type'];
$is_translatable = $parameters['is_translatable'];
$revisionable = $parameters['revisionable'];
$has_forms = $parameters['has_forms'];

$moduleInstance = $this->extensionManager->getModule($module);
$moduleDir = $moduleInstance->getPath();
Expand All @@ -81,27 +82,6 @@ public function generate(array $parameters)
FILE_APPEND
);

$this->renderFile(
'module/links.menu-entity-content.yml.twig',
$modulePath . '.links.menu.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/links.task-entity-content.yml.twig',
$modulePath . '.links.task.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/links.action-entity-content.yml.twig',
$modulePath . '.links.action.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/src/accesscontrolhandler-entity-content.php.twig',
$moduleSourcePath . 'AccessControlHandler.php',
Expand All @@ -118,7 +98,7 @@ public function generate(array $parameters)

$this->renderFile(
'module/src/Entity/interface-entity-content.php.twig',
$moduleSourcePath . 'Interface.php',
$moduleEntityPath . 'Interface.php',
$parameters
);

Expand All @@ -128,12 +108,6 @@ public function generate(array $parameters)
$parameters
);

$this->renderFile(
'module/src/entity-content-route-provider.php.twig',
$moduleSourcePath . 'HtmlRouteProvider.php',
$parameters
);

$this->renderFile(
'module/src/Entity/entity-content-views-data.php.twig',
$moduleEntityPath . 'ViewsData.php',
Expand All @@ -146,54 +120,96 @@ public function generate(array $parameters)
$parameters
);

$this->renderFile(
'module/src/Entity/Form/entity-settings.php.twig',
$moduleFormPath . 'SettingsForm.php',
$parameters
);
if($has_forms) {
$this->renderFile(
'module/src/entity-content-route-provider.php.twig',
$moduleSourcePath . 'HtmlRouteProvider.php',
$parameters
);

$this->renderFile(
'module/src/Entity/Form/entity-content.php.twig',
$moduleFormPath . 'Form.php',
$parameters
);
$this->renderFile(
'module/links.menu-entity-content.yml.twig',
$modulePath . '.links.menu.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/src/Entity/Form/entity-content-delete.php.twig',
$moduleFormPath . 'DeleteForm.php',
$parameters
);
$this->renderFile(
'module/links.task-entity-content.yml.twig',
$modulePath . '.links.task.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/entity-content-page.php.twig',
$moduleDir . '/' . $entity_name . '.page.inc',
$parameters
);
$this->renderFile(
'module/links.action-entity-content.yml.twig',
$modulePath . '.links.action.yml',
$parameters,
FILE_APPEND
);

$this->renderFile(
'module/src/Entity/Form/entity-settings.php.twig',
$moduleFormPath . 'SettingsForm.php',
$parameters
);

$this->renderFile(
'module/src/Entity/Form/entity-content.php.twig',
$moduleFormPath . 'Form.php',
$parameters
);

$this->renderFile(
'module/templates/entity-html.twig',
$moduleTemplatePath . $entity_name . '.html.twig',
$parameters
);

if ($revisionable) {
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-delete.php.twig',
$moduleFormPath . 'RevisionDeleteForm.php',
'module/src/Entity/Form/entity-content-delete.php.twig',
$moduleFormPath . 'DeleteForm.php',
$parameters
);
if ($is_translatable) {

$this->renderFile(
'module/templates/entity-html.twig',
$moduleTemplatePath . $entity_name . '.html.twig',
$parameters
);

$this->renderFile(
'module/entity-content-page.php.twig',
$moduleDir . '/' . $entity_name . '.page.inc',
$parameters
);
}


if ($revisionable) {
if ($has_forms) {
if ($is_translatable) {
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig',
$moduleFormPath . 'RevisionRevertTranslationForm.php',
$parameters
);
}

$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert-translation.php.twig',
$moduleFormPath . 'RevisionRevertTranslationForm.php',
'module/src/Entity/Form/entity-content-revision-delete.php.twig',
$moduleFormPath . 'RevisionDeleteForm.php',
$parameters
);

$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert.php.twig',
$moduleFormPath . 'RevisionRevertForm.php',
$parameters
);

$this->renderFile(
'module/src/Controller/entity-controller.php.twig',
$moduleInstance->getControllerPath() . '/' . $entity_class . 'Controller.php',
$parameters
);
}
$this->renderFile(
'module/src/Entity/Form/entity-content-revision-revert.php.twig',
$moduleFormPath . 'RevisionRevertForm.php',
$parameters
);

$this->renderFile(
'module/src/entity-storage.php.twig',
$moduleSourcePath . 'Storage.php',
Expand All @@ -204,11 +220,6 @@ public function generate(array $parameters)
$moduleSourcePath . 'StorageInterface.php',
$parameters
);
$this->renderFile(
'module/src/Controller/entity-controller.php.twig',
$moduleInstance->getControllerPath() . '/' . $entity_class . 'Controller.php',
$parameters
);
}

if ($bundle_entity_type) {
Expand Down
10 changes: 8 additions & 2 deletions templates/module/src/Entity/entity-content.php.twig
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ use Drupal\user\UserInterface;
* "translation" = "Drupal\{{ module }}\{{ entity_class }}TranslationHandler",
{% endif %}
*
{% if has_forms %}
* "form" = {
* "default" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "add" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "edit" = "Drupal\{{ module }}\Form\{{ entity_class }}Form",
* "delete" = "Drupal\{{ module }}\Form\{{ entity_class }}DeleteForm",
* },
* "access" = "Drupal\{{ module }}\{{ entity_class }}AccessControlHandler",
* "route_provider" = {
* "html" = "Drupal\{{ module }}\{{ entity_class }}HtmlRouteProvider",
* },
{% endif %}
* "access" = "Drupal\{{ module }}\{{ entity_class }}AccessControlHandler",
* },
* base_table = "{{ entity_name }}",
{% if is_translatable %}
Expand All @@ -81,7 +83,8 @@ use Drupal\user\UserInterface;
* "langcode" = "langcode",
* "published" = "status",
* },
* links = {
{% if has_forms %}
* links = {
* "canonical" = "{{ base_path }}/{{ entity_name }}/{{ '{'~entity_name~'}' }}",
{% if bundle_entity_type %}
* "add-page" = "{{ base_path }}/{{ entity_name }}/add",
Expand All @@ -102,11 +105,14 @@ use Drupal\user\UserInterface;
{% endif %}
* "collection" = "{{ base_path }}/{{ entity_name }}",
* },
{% endif %}
{% if bundle_entity_type %}
* bundle_entity_type = "{{ bundle_entity_type }}",
* field_ui_base_route = "entity.{{ bundle_entity_type }}.edit_form"
{% else %}
{% if has_forms %}
* field_ui_base_route = "{{ entity_name }}.settings"
{% endif %}
{% endif %}
* )
*/
Expand Down

0 comments on commit 5d6a21a

Please sign in to comment.