From 0d616a57417440a73d9d13e08ea880fedeb2f2d0 Mon Sep 17 00:00:00 2001 From: ryuring Date: Sun, 3 Mar 2024 15:25:12 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=82=A8?= =?UTF-8?q?=E3=83=B3=E3=83=88=E3=83=AA=E3=83=BC=E6=96=B0=E8=A6=8F=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E6=99=82=E3=81=AE=E3=83=97=E3=83=AC=E3=83=93=E3=83=A5?= =?UTF-8?q?=E3=83=BC=E3=81=8C=E5=8B=95=E4=BD=9C=E3=81=97=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=82=81=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BcCustomContent/Admin/CustomEntries/add.php | 6 ++++++ .../BcCustomContent/Admin/CustomEntries/edit.php | 5 +---- .../Service/Admin/CustomEntriesAdminService.php | 13 ++++++++++--- .../Service/Front/CustomContentFrontService.php | 16 ++++++++++------ 4 files changed, 27 insertions(+), 13 deletions(-) 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);