From dbf0fccf26b696e793b27495f151ea3364bc99e4 Mon Sep 17 00:00:00 2001 From: Peter Philipp Date: Wed, 15 May 2024 15:06:02 +0200 Subject: [PATCH 1/2] fix: https://github.com/pimcore/pimcore/issues/16814 WYSIWYG not respecting frontend_prefixes configuration. --- .../Admin/Asset/AssetController.php | 60 +++++++++++++++++++ .../js/pimcore/document/editables/wysiwyg.js | 27 +++++++++ 2 files changed, 87 insertions(+) diff --git a/bundles/AdminBundle/Controller/Admin/Asset/AssetController.php b/bundles/AdminBundle/Controller/Admin/Asset/AssetController.php index b65e1e5e471..65c207f10b9 100644 --- a/bundles/AdminBundle/Controller/Admin/Asset/AssetController.php +++ b/bundles/AdminBundle/Controller/Admin/Asset/AssetController.php @@ -1346,6 +1346,66 @@ public function getAssetAction(Request $request) return $response; } + /** + * @Route("/get-asset-frontend-path", name="pimcore_admin_asset_getfrontendpath", methods={"GET"}) + * + * @param Request $request + * + * @return StreamedResponse|JsonResponse|BinaryFileResponse + */ + public function getAssetFrontendPathAction(Request $request) + { + $pathType = $request->get('pathType', 'source'); + $thumbnailConfig = $request->get('thumbnailConfig'); + $asset = Asset::getById((int)$request->get('id')); + + if ($pathType != 'source' && !$thumbnailConfig) { + throw $this->createNotFoundException('No thumbnail config found. Check the thumbnailConfig parameter in the request.'); + } + + if (!$asset) { + throw $this->createNotFoundException('Asset not found'); + } + + if (!$asset->isAllowed('view')) { + throw $this->createAccessDeniedException('not allowed to view asset'); + } + + switch (true) { + case $asset instanceof Asset\Video && $pathType != 'source': + $asset = new Asset\Video\ImageThumbnail($asset, $thumbnailConfig); + break; + case $asset instanceof Asset\Document && $pathType != 'source': + $asset = new Asset\Document\ImageThumbnail($asset, $thumbnailConfig); + break; + case $asset instanceof Asset\Image && $pathType != 'source': + $asset = new Asset\Image\Thumbnail($asset, $thumbnailConfig); + break; + } + + switch ($pathType) { + case 'deferred': + $path = $asset->getPath([ + 'frontend' => true, + 'deferredAllowed' => true + ]); + break; + case 'thumbnail': + $path = $asset->getPath([ + 'frontend' => true, + 'deferredAllowed' => false + ]); + break; + case 'source': + default: + $path = $asset->getFrontendFullPath(); + } + + return $this->adminJson([ + 'path' => $path, + ]); + } + /** * @Route("/get-image-thumbnail", name="pimcore_admin_asset_getimagethumbnail", methods={"GET"}) * diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/document/editables/wysiwyg.js b/bundles/AdminBundle/Resources/public/js/pimcore/document/editables/wysiwyg.js index 87ee79efcee..6c6c5f52863 100644 --- a/bundles/AdminBundle/Resources/public/js/pimcore/document/editables/wysiwyg.js +++ b/bundles/AdminBundle/Resources/public/js/pimcore/document/editables/wysiwyg.js @@ -228,6 +228,8 @@ pimcore.document.editables.wysiwyg = Class.create(pimcore.document.editable, { } additionalAttributes += ' style="width:' + defaultWidth + 'px;"'; + } else { + uri = this.getAssetFrontendPath(data); } insertEl = CKEDITOR.dom.element.createFromHtml('' + wrappedText + ''); this.ckeditor.insertElement(insertEl); @@ -260,6 +264,29 @@ pimcore.document.editables.wysiwyg = Class.create(pimcore.document.editable, { }, + getAssetFrontendPath: function (data, options) { + // Would have been great to be able to re-use the asset API to fetch + // these data, but it's such a JS dependency hell that it's easier to + // just create a new endpoint to fetch the info... + try { + var response = Ext.Ajax.request({ + url: Routing.generate('pimcore_admin_asset_getfrontendpath'), + async: false, + params: { + id: data.id, + type: "source", + }, + }); + var res = Ext.decode(response.responseText); + if (typeof res.path != "undefined" && res.path) { + return res.path; + } + } catch (e) { + console.error('Unable to load asset data - fallback to unprocessed path. ' + e); + } + return data.path; + }, + checkValue: function (mark) { var value = this.getValue(); var textarea = Ext.get(this.textarea); From 4dbf329611056fa0e7045b5ae677822195483295 Mon Sep 17 00:00:00 2001 From: Peter Philipp Date: Mon, 10 Jun 2024 15:06:51 +0200 Subject: [PATCH 2/2] fix: WYSIWYG processing not using proper frontend paths when generating output. --- lib/Tool/Text.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Tool/Text.php b/lib/Tool/Text.php index d72671fe4cf..fb88eac8813 100644 --- a/lib/Tool/Text.php +++ b/lib/Tool/Text.php @@ -102,7 +102,7 @@ public static function wysiwygText($text, $params = []) continue; } - $path = $element->getFullPath(); + $path = $element->getFrontendFullPath(); // resize image to the given attributes $config = null; @@ -139,6 +139,8 @@ public static function wysiwygText($text, $params = []) // only create a thumbnail if it is not disabled if (!preg_match('/pimcore_disable_thumbnail="([^"]+)*"/', $oldTag)) { if (!empty($config)) { + // Ensure full frontend path is returned. + $config['frontend'] = true; $path = $element->getThumbnail($config); $pathHdpi = $element->getThumbnail(array_merge($config, ['highResolution' => 2])); $additionalAttributes = [ @@ -149,10 +151,12 @@ public static function wysiwygText($text, $params = []) // for those big images we don't generate a hdpi version $path = $element->getThumbnail([ 'width' => 2000, + 'frontend' => true, ]); } else { - // return the original - $path = $element->getFullPath(); + // return the original with _FULL_ path. This + // respects the frontend_prefixes setting. + $path = $element->getFrontendFullPath(); } } }