Square only third-level category uploads
CI / PHP lint (7.4) (push) Successful in 1m0s
CI / PHP lint (8.1) (push) Successful in 1m0s
CI / Coding standards (push) Successful in 1m5s

This commit is contained in:
tiamak
2026-04-14 12:09:46 +00:00
parent 2b52518d3f
commit 6acb48fe22
2 changed files with 21 additions and 6 deletions
+9 -3
View File
@@ -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);
}