Skip to content
Snippets Groups Projects

Issue #3362476: Webp Image not being updated when the Focalpoint/crop entity is Updated

<?php
use Drupal\image\ImageStyleInterface;
use Drupal\imageapi_optimize\Entity\ImageStyleWithPipeline;
use Drupal\imageapi_optimize\ImageAPIOptimizePipelineInterface;
/**
* Implements hook_entity_type_alter().
*/
@@ -8,4 +12,41 @@ function imageapi_optimize_webp_entity_type_alter(array &$entity_types) {
$entity_types['imageapi_optimize_pipeline']->setClass('Drupal\imageapi_optimize_webp\Entity\ImageAPIOptimizeWebPPipeline');
}
return [];
}
\ No newline at end of file
}
/**
* Implements hook_image_style_flush().
*/
function imageapi_optimize_webp_image_style_flush(ImageStyleInterface $style, ?string $path = NULL): void {
if (!$style instanceof ImageStyleWithPipeline) {
return;
}
if ($path === NULL) {
return;
}
$suffix = '.webp';
if (substr($path, -strlen($suffix)) === $suffix) {
return;
}
$pipeline = $style->getPipelineEntity();
if (!$pipeline instanceof ImageAPIOptimizePipelineInterface) {
return;
}
$processors = $pipeline->getProcessors();
$webPProcessorEnabled = FALSE;
foreach ($processors as $processor) {
if ($processor->getPluginId() === 'imageapi_optimize_webp') {
$webPProcessorEnabled = TRUE;
break;
}
}
if ($webPProcessorEnabled) {
$style->flush($path . $suffix);
}
}
Loading