function file_replace_file_replace in File Replace (D8) 8
Implements hook_file_replace().
File
- ./
file_replace.module, line 38 - File replace functionality.
Code
function file_replace_file_replace(FileInterface $file) {
// Flush image cache.
if (\Drupal::moduleHandler()
->moduleExists('image')) {
if (explode('/', $file
->getMimeType())[0] == 'image') {
/** @var \Drupal\image\Entity\ImageStyle[] $image_styles */
$image_styles = \Drupal::entityTypeManager()
->getStorage('image_style')
->loadMultiple();
foreach ($image_styles as $image_style) {
$image_style
->flush($file
->getFileUri());
}
}
}
}