Skip to content

Commit

Permalink
カスタムエントリー新規追加時のプレビューが動作していなかっため修正
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuring committed Mar 3, 2024
1 parent b9413e7 commit 0d616a5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
?>

<?php echo $this->BcAdminForm->create($entity, ['type' => 'file', 'novalidate' => true]) ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
}

Expand All @@ -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
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
] : '',
];
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0d616a5

Please sign in to comment.