diff --git a/src/Controller/Admin/Asset/AssetController.php b/src/Controller/Admin/Asset/AssetController.php index ac0fc8244e..3c6181a4c3 100644 --- a/src/Controller/Admin/Asset/AssetController.php +++ b/src/Controller/Admin/Asset/AssetController.php @@ -37,6 +37,7 @@ use Pimcore\Messenger\AssetUpdateTasksMessage; use Pimcore\Model; use Pimcore\Model\Asset; +use Pimcore\Model\Asset\Enum\PdfScanStatus; use Pimcore\Model\DataObject\ClassDefinition\Data\ManyToManyRelation; use Pimcore\Model\DataObject\Concrete; use Pimcore\Model\Element; @@ -950,10 +951,12 @@ public function showVersionAction(Request $request, Environment $twig): Response } if ($asset instanceof Asset\Document && $asset->getMimeType() === self::PDF_MIMETYPE) { - $scanResponse = $this->getResponseByScanStatus($asset, false); - if ($scanResponse) { - return $scanResponse; - } + $previewData = ['thumbnailPath' => '']; + $previewData['assetPath'] = $asset->getRealFullPath(); + return $this->render( + '@PimcoreAdmin/admin/asset/get_preview_pdf_open_in_new_tab.html.twig', + $previewData + ); } Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone')); @@ -1450,8 +1453,23 @@ public function getPreviewDocumentAction( if ($asset->isAllowed('view')) { if ($asset instanceof Asset\Document && $asset->getMimeType() === self::PDF_MIMETYPE) { $scanResponse = $this->getResponseByScanStatus($asset); - if ($scanResponse) { - return $scanResponse; + $openPdfConfig = Config::getSystemConfiguration('assets')['document']['open_pdf_in_new_tab']; + + if ($openPdfConfig === 'all-pdfs' || + ($openPdfConfig === 'only-unsafe' && $scanResponse === PdfScanStatus::UNSAFE)) { + $thumbnail = $asset->getImageThumbnail(Asset\Image\Thumbnail\Config::getPreviewConfig()); + $previewData = ['thumbnailPath' => $thumbnail->getPath()]; + $previewData['assetPath'] = $asset->getRealFullPath(); + return $this->render( + '@PimcoreAdmin/admin/asset/get_preview_pdf_open_in_new_tab.html.twig', + $previewData + ); + } + + if ($scanResponse === PdfScanStatus::IN_PROGRESS) { + return $this->render('@PimcoreAdmin/admin/asset/get_preview_pdf_in_progress.html.twig'); + } elseif ($scanResponse === PdfScanStatus::UNSAFE) { + return $this->render('@PimcoreAdmin/admin/asset/get_preview_pdf_unsafe.html.twig'); } } @@ -1470,7 +1488,7 @@ public function getPreviewDocumentAction( } } - private function getResponseByScanStatus(Asset\Document $asset, bool $processBackground = true): ?Response + private function getResponseByScanStatus(Asset\Document $asset, bool $processBackground = true): ?PdfScanStatus { if (!Config::getSystemConfiguration('assets')['document']['scan_pdf']) { return null; @@ -1486,11 +1504,7 @@ private function getResponseByScanStatus(Asset\Document $asset, bool $processBac } } - return match($scanStatus) { - Asset\Enum\PdfScanStatus::IN_PROGRESS => $this->render('@PimcoreAdmin/admin/asset/get_preview_pdf_in_progress.html.twig'), - Asset\Enum\PdfScanStatus::UNSAFE => $this->render('@PimcoreAdmin/admin/asset/get_preview_pdf_unsafe.html.twig'), - default => null, - }; + return $scanStatus; } /** diff --git a/templates/admin/asset/get_preview_pdf_open_in_new_tab.html.twig b/templates/admin/asset/get_preview_pdf_open_in_new_tab.html.twig new file mode 100644 index 0000000000..64163c3222 --- /dev/null +++ b/templates/admin/asset/get_preview_pdf_open_in_new_tab.html.twig @@ -0,0 +1,58 @@ + + + + + + + + + + +
+ {% if thumbnailPath %} + + preview + + {% else %} + {{ 'no_preview_available'|trans([], 'admin') }} + {% endif %} +
+ {{ 'open_in_new_window'|trans([], 'admin') }} +
+
+ + + + diff --git a/templates/admin/asset/show_version_unknown.html.twig b/templates/admin/asset/show_version_unknown.html.twig index 480003db13..981eb0b3d1 100644 --- a/templates/admin/asset/show_version_unknown.html.twig +++ b/templates/admin/asset/show_version_unknown.html.twig @@ -26,7 +26,7 @@
- Sorry, no preview available
+ {{ 'no_preview_available'|trans([], 'admin') }}
{% set tempFile = asset.getTemporaryFile() %} {% set dataUri = pimcore_asset_version_preview(tempFile) %} diff --git a/translations/admin.en.yaml b/translations/admin.en.yaml index aa6f04a7cf..a1ee668fc1 100644 --- a/translations/admin.en.yaml +++ b/translations/admin.en.yaml @@ -1026,4 +1026,5 @@ zip_upload_want_to_overwrite_yes_option: 'Yes' zip_upload_want_to_overwrite_no_option: 'No' invalid_option: 'Invalid Option field [ {field} ]: Please choose a valid option for select / multiselect field [ {field} ]. Current value: "{option}"' respect_timezone: 'Respect timezone' -delete_quantity_value_unit_confirmation: 'Deleting this unit will impact all related elements that reference it. Are you sure you want to proceed?' \ No newline at end of file +delete_quantity_value_unit_confirmation: 'Deleting this unit will impact all related elements that reference it. Are you sure you want to proceed?' +no_preview_available: 'Sorry, no preview available' \ No newline at end of file