Skip to content

Commit

Permalink
Prevent checking nonsupported image formats
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox authored Jul 26, 2023
1 parent 21c1382 commit 7834b34
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions controllers/admin/AdminImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,17 @@ public function init()
$formFields = [];

if ($this->isMultipleImageFormatFeatureEnabled) {
/* We will disable few image formats
* Base JPG is mandatory, see https://github.com/PrestaShop/PrestaShop/issues/30944
* AVIF support depends on platform - PHP version and required libraries available
*/
$imageFormatsDisabled = [];
$imageFormatsDisabled['jpg'] = true; // jpg is mandatory, see https://github.com/PrestaShop/PrestaShop/issues/30944
if (false === $this->canGenerateAvif) {
$imageFormatsDisabled['jpg'] = true;
if (!$this->canGenerateAvif) {
$imageFormatsDisabled['avif'] = true;
}

// Load configured formats to see what to check
$configuredImageFormats = $this->imageFormatConfiguration->getGenerationFormats();

$fields = [
Expand Down Expand Up @@ -476,6 +482,19 @@ public function initModal(): void
];
}

public function beforeUpdateOptions()
{
// Unset AVIF if not supported, add JPG if missing
foreach ($_POST['PS_IMAGE_FORMAT'] as $k => $v) {
if ($v == 'avif' && !$this->canGenerateAvif) {
unset($_POST['PS_IMAGE_FORMAT'][$k]);
}
}
if (!in_array('jpg', $_POST['PS_IMAGE_FORMAT'])) {
$_POST['PS_IMAGE_FORMAT'][] = 'jpg';
}
}

public function updateOptionPsImageFormat($value): void
{
if ($this->access('edit') != '1') {
Expand Down

0 comments on commit 7834b34

Please sign in to comment.