From 9b5e8ac4de1a1ab2128bc4c06481e9766baea3b7 Mon Sep 17 00:00:00 2001 From: Daniel Ramirez Date: Wed, 23 Oct 2019 17:00:50 -0500 Subject: [PATCH] [generate:entity:content] permissions for no-bundle entity (#4181) validate if the entity have bundles it's on true and create permissions --- src/Command/Generate/EntityContentCommand.php | 11 ++++++++--- src/Generator/EntityContentGenerator.php | 17 +++++++++-------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/Command/Generate/EntityContentCommand.php b/src/Command/Generate/EntityContentCommand.php index 572fc628b..7605879d7 100644 --- a/src/Command/Generate/EntityContentCommand.php +++ b/src/Command/Generate/EntityContentCommand.php @@ -167,11 +167,16 @@ protected function interact(InputInterface $input, OutputInterface $output) $input->setOption('has-owner', $has_owner); // --has-bundle-permissions - $has_bundle_permissions = $this->getIo()->confirm( + if($bundle_of){ + $has_bundle_permissions = $this->getIo()->confirm( $this->trans('commands.generate.entity.content.questions.has-bundle-permissions'), true - ); - $input->setOption('has-bundle-permissions', $has_bundle_permissions); + ); + $input->setOption('has-bundle-permissions', $has_bundle_permissions); + } + else { + $input->setOption('has-bundle-permissions', false); + } } /** diff --git a/src/Generator/EntityContentGenerator.php b/src/Generator/EntityContentGenerator.php index 72d68b6db..0862c8a0b 100644 --- a/src/Generator/EntityContentGenerator.php +++ b/src/Generator/EntityContentGenerator.php @@ -83,14 +83,6 @@ public function generate(array $parameters) FILE_APPEND ); - if ($has_bundle_permissions) { - $this->renderFile( - 'module/src/entity-content-bundle-permissions.php.twig', - $moduleSourcePath . 'Permissions.php', - $parameters - ); - } - $this->renderFile( 'module/src/accesscontrolhandler-entity-content.php.twig', $moduleSourcePath . 'AccessControlHandler.php', @@ -232,12 +224,21 @@ public function generate(array $parameters) } if ($bundle_entity_type) { + $this->renderFile( 'module/templates/entity-with-bundle-content-add-list-html.twig', $moduleTemplatePath . '/' . str_replace('_', '-', $entity_name) . '-content-add-list.html.twig', $parameters ); + if ($has_bundle_permissions) { + $this->renderFile( + 'module/src/entity-content-bundle-permissions.php.twig', + $moduleSourcePath . 'Permissions.php', + $parameters + ); + } + // Check for hook_theme() in module file and warn ... // Check if the module file exists. if (!file_exists($moduleFileName)) {