diff --git a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/add.php b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/add.php index 58dba14346..921c7b4afa 100644 --- a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/add.php +++ b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/add.php @@ -15,11 +15,17 @@ * @var \BcCustomContent\Model\Entity\CustomEntry $entity * @var int $tableId * @var bool $availablePreview + * @var string $entryUrl * @checked * @noTodo * @unitTest */ $this->BcAdmin->setTitle(__d('baser_core', '{0}|新規エントリー登録', $customTable->title)); +$this->BcBaser->js('BcCustomContent.admin/custom_entries/form.bundle', false, [ + 'defer' => true, + 'id' => 'AdminCustomEntriesFormScript', + 'data-fullUrl' => $entryUrl, +]); ?> BcAdminForm->create($entity, ['type' => 'file', 'novalidate' => true]) ?> diff --git a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/edit.php b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/edit.php index 0ebdc98848..e98e35f142 100644 --- a/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/edit.php +++ b/plugins/bc-admin-third/templates/plugin/BcCustomContent/Admin/CustomEntries/edit.php @@ -13,6 +13,7 @@ * @var \BcCustomContent\View\CustomContentAdminAppView $this * @var \BcCustomContent\Model\Entity\CustomTable $customTable * @var \BcCustomContent\Model\Entity\CustomEntry $entity + * @var string $entryUrl * @var int $tableId * @var bool $availablePreview * @checked @@ -24,10 +25,6 @@ 'url' => ['action' => 'add', $tableId], 'title' => __d('baser_core', '新規追加'), ]); -$entryUrl = ''; -if($customTable->isContentTable()) { - $entryUrl = $this->CustomContentAdmin->getEntryUrl($entity); -} $this->BcBaser->js('BcCustomContent.admin/custom_entries/form.bundle', false, [ 'defer' => true, 'id' => 'AdminCustomEntriesFormScript', diff --git a/plugins/bc-custom-content/src/Service/Admin/CustomEntriesAdminService.php b/plugins/bc-custom-content/src/Service/Admin/CustomEntriesAdminService.php index 1f0f166dc1..93da1338a7 100644 --- a/plugins/bc-custom-content/src/Service/Admin/CustomEntriesAdminService.php +++ b/plugins/bc-custom-content/src/Service/Admin/CustomEntriesAdminService.php @@ -94,11 +94,16 @@ public function getViewVarsForAdd(int $tableId, EntityInterface $entity): array $customTable = $customTables->getWithLinks($tableId); $availablePreview = false; } + $entryUrl = null; + if($customTable->isContentTable()) { + $entryUrl = $this->getUrl($customTable->custom_content->content, $entity); + } return [ 'entity' => $entity, 'tableId' => $tableId, 'customTable' => $customTable, - 'availablePreview' => $availablePreview + 'availablePreview' => $availablePreview, + 'entryUrl' => $entryUrl, ]; } @@ -121,18 +126,20 @@ public function getViewVarsForEdit(int $tableId, EntityInterface $entity): array } else { $customTable = $customTables->getWithLinks($tableId); } - $publishLink = null; + $publishLink = $entryUrl = null; $availablePreview = false; if($customTable->isContentTable()) { $publishLink = $this->getPublishLinkForEdit($customTable->custom_content->content, $entity); $availablePreview = true; + $entryUrl = $this->getUrl($customTable->custom_content->content, $entity); } return [ 'entity' => $entity, 'tableId' => $tableId, 'customTable' => $customTable, 'publishLink' => $publishLink, - 'availablePreview' => $availablePreview + 'availablePreview' => $availablePreview, + 'entryUrl' => $entryUrl ]; } diff --git a/plugins/bc-custom-content/src/Service/Front/CustomContentFrontService.php b/plugins/bc-custom-content/src/Service/Front/CustomContentFrontService.php index 4184f61eff..6d645c5752 100644 --- a/plugins/bc-custom-content/src/Service/Front/CustomContentFrontService.php +++ b/plugins/bc-custom-content/src/Service/Front/CustomContentFrontService.php @@ -167,11 +167,15 @@ public function getViewVarsForView(EntityInterface $customContent, mixed $entryI { $this->entriesService->setup($customContent->custom_table_id); if($preview) { - $options = []; + $entity = null; + if($entryId) { + $entity = $this->entriesService->get($entryId); + } } else { $options = ['status' => 'publish']; + $entity = $this->entriesService->get($entryId, $options); } - $entity = $this->entriesService->get($entryId, $options); + /** @var CustomContent $customContent */ return [ 'customContent' => $customContent, @@ -182,8 +186,8 @@ public function getViewVarsForView(EntityInterface $customContent, mixed $entryI 'plugin' => 'BcCustomContent', 'controller' => 'CustomEntries', 'action' => 'edit', - $entity->custom_table_id, - $entity->id + $customContent->custom_table_id, + $entity->id?? null ] : '', ]; } @@ -228,12 +232,12 @@ public function setupPreviewForView(Controller $controller): void { $request = $controller->getRequest(); $entryId = $request->getParam('pass.0'); - if(!$entryId) throw new NotFoundException(); $customContent = $this->contentsService->get($request->getParam('entityId')); $controller->set($this->getViewVarsForView($customContent, $entryId, true)); + $customEntry = $controller->viewBuilder()->getVar('customEntry'); $entity = $this->entriesService->CustomEntries->patchEntity( - $controller->viewBuilder()->getVar('customEntry'), + $customEntry?? $this->entriesService->CustomEntries->newEmptyEntity(), $request->getData() ); $entity = $this->entriesService->CustomEntries->decodeRow($entity);