Skip to content

Commit

Permalink
fix: pimcore#16814 WYSIWYG not respecting frontend_prefixes configura…
Browse files Browse the repository at this point in the history
…tion.
  • Loading branch information
das-peter committed May 15, 2024
1 parent dd81ef4 commit dbf0fcc
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
60 changes: 60 additions & 0 deletions bundles/AdminBundle/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<img src="'
Expand All @@ -236,6 +238,8 @@ pimcore.document.editables.wysiwyg = Class.create(pimcore.document.editable, {
return true;
}
else {
uri = this.getAssetFrontendPath(data);

insertEl = CKEDITOR.dom.element.createFromHtml('<a href="' + uri
+ '" target="_blank" pimcore_type="asset" pimcore_id="' + id + '">' + wrappedText + '</a>');
this.ckeditor.insertElement(insertEl);
Expand All @@ -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);
Expand Down

0 comments on commit dbf0fcc

Please sign in to comment.