Square only third-level category uploads
This commit is contained in:
@@ -427,7 +427,13 @@ class AdvancedMegaMenu extends Module implements WidgetInterface
|
||||
}
|
||||
|
||||
$preset = (string) Tools::getValue('preset', 'default');
|
||||
$storedPath = $this->storeUploadedImage($_FILES['image'], $preset);
|
||||
$menuDepth = (int) Tools::getValue('menu_depth', -1);
|
||||
$menuType = (string) Tools::getValue('menu_type', '');
|
||||
$storedPath = $this->storeUploadedImage(
|
||||
$_FILES['image'],
|
||||
$preset,
|
||||
$preset === 'menu_icon' && $menuDepth >= 2 && $menuType === 'category'
|
||||
);
|
||||
header('Content-Type: application/json');
|
||||
exit(json_encode([
|
||||
'error' => false,
|
||||
@@ -439,7 +445,7 @@ class AdvancedMegaMenu extends Module implements WidgetInterface
|
||||
/**
|
||||
* @param array<string, mixed> $file
|
||||
*/
|
||||
private function storeUploadedImage(array $file, string $preset = 'default'): string
|
||||
private function storeUploadedImage(array $file, string $preset = 'default', bool $forceSquare = false): string
|
||||
{
|
||||
$uploadDir = $this->getLocalPath() . 'views/img/uploads/';
|
||||
if (!is_dir($uploadDir)) {
|
||||
@@ -456,7 +462,7 @@ class AdvancedMegaMenu extends Module implements WidgetInterface
|
||||
}
|
||||
|
||||
$converted = false;
|
||||
if ($preset === 'menu_icon') {
|
||||
if ($preset === 'menu_icon' && $forceSquare) {
|
||||
$converted = $this->convertImageToSquareWebp($originalPath, $targetPath, 250);
|
||||
}
|
||||
|
||||
|
||||
+12
-3
@@ -468,12 +468,14 @@
|
||||
var uploadInput = nodeModal.querySelector('.js-node-icon-upload');
|
||||
uploadInput.value = '';
|
||||
uploadInput.onchange = function (event) {
|
||||
var preset = depth >= 2 ? 'menu_icon' : 'default';
|
||||
uploadImage(event.target.files[0], preset, function (response) {
|
||||
uploadImage(event.target.files[0], 'menu_icon', function (response) {
|
||||
node.icon_path = response.path;
|
||||
node.icon_url = response.url;
|
||||
renderImagePreview(previewWrap, response.url);
|
||||
serializeTree();
|
||||
}, {
|
||||
menuDepth: depth,
|
||||
menuType: node.type || 'link'
|
||||
});
|
||||
};
|
||||
|
||||
@@ -718,16 +720,23 @@
|
||||
return '';
|
||||
}
|
||||
|
||||
function uploadImage(file, preset, callback) {
|
||||
function uploadImage(file, preset, callback, options) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
var uploadOptions = options || {};
|
||||
var formData = new FormData();
|
||||
formData.append('ajax', '1');
|
||||
formData.append('action', 'uploadImage');
|
||||
formData.append('token', token);
|
||||
formData.append('preset', preset || 'default');
|
||||
if (typeof uploadOptions.menuDepth !== 'undefined') {
|
||||
formData.append('menu_depth', String(uploadOptions.menuDepth));
|
||||
}
|
||||
if (typeof uploadOptions.menuType !== 'undefined') {
|
||||
formData.append('menu_type', String(uploadOptions.menuType));
|
||||
}
|
||||
formData.append('image', file);
|
||||
|
||||
fetch(ajaxUrl, {
|
||||
|
||||
Reference in New Issue
Block a user