-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #666 from UN-OCHA/develop
Develop -> Main - v2.1.1
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
html/modules/custom/reliefweb_utility/src/Entity/ImageStyleWithPipeline.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Drupal\reliefweb_utility\Entity; | ||
|
||
use Drupal\Core\File\Exception\FileException; | ||
use Drupal\imageapi_optimize\Entity\ImageStyleWithPipeline as BaseImageStyleWithPipeline; | ||
|
||
/** | ||
* Override of the ImageStyleWithPipeline to also delete webp images. | ||
*/ | ||
class ImageStyleWithPipeline extends BaseImageStyleWithPipeline { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function flush($path = NULL) { | ||
$result = parent::flush($path); | ||
|
||
// Also delete the webp version of the image if it exists. | ||
if (isset($path)) { | ||
/** @var \Drupal\Core\File\FileSystemInterface $file_system */ | ||
$file_system = \Drupal::service('file_system'); | ||
$derivative_uri = $this->buildUri($path); | ||
$derivative_uri_webp = $derivative_uri . '.webp'; | ||
|
||
if (file_exists($derivative_uri_webp)) { | ||
try { | ||
$file_system->delete($derivative_uri_webp); | ||
} | ||
catch (FileException $exception) { | ||
// Ignore failed deletion. | ||
} | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
} |