Skip to content

Commit

Permalink
Move the logic to implicitly allow WebP images
Browse files Browse the repository at this point in the history
  • Loading branch information
dtdesign committed Dec 12, 2024
1 parent b95865d commit 0f7634d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,23 @@ public function getMaxSize()
*/
public function getAllowedExtensions()
{
return $this->processor->getAllowedExtensions();
$extensions = $this->processor->getAllowedExtensions();

if (\in_array('*', $extensions)) {
return $extensions;
}

// Check if auto scaling is enabled and is set to convert images which
// would yield WebP.
if (!\ATTACHMENT_IMAGE_AUTOSCALE || \ATTACHMENT_IMAGE_AUTOSCALE_FILE_TYPE === 'keep') {
return $extensions;
}

if (!\in_array('webp', $extensions)) {
$extensions[] = 'webp';
}

return $extensions;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,7 @@ public function getAllowedFileExtensions(array $context): array
return [];
}

$extensions = $attachmentHandler->getAllowedExtensions();
if (\in_array('*', $extensions)) {
return $extensions;
}

// Check if auto scaling is enabled and is set to convert images which
// would yield WebP.
if (!\ATTACHMENT_IMAGE_AUTOSCALE || \ATTACHMENT_IMAGE_AUTOSCALE_FILE_TYPE === 'keep') {
return $extensions;
}

if (!\in_array('webp', $extensions)) {
$extensions[] = 'webp';
}

return $extensions;
}
return $attachmentHandler->getAllowedExtensions(); }

#[\Override]
public function canAdopt(File $file, array $context): bool
Expand Down

0 comments on commit 0f7634d

Please sign in to comment.