Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: https://github.com/pimcore/pimcore/issues/16814 WYSIWYG not resp… #29

Open
wants to merge 2 commits into
base: 10.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 7 additions & 3 deletions lib/Tool/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 = [
Expand All @@ -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();
}
}
}
Expand Down
Loading