public function ImageStyle::flush in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/image/src/Entity/ImageStyle.php \Drupal\image\Entity\ImageStyle::flush()
Flushes cached media for this style.
Parameters
string $path: (optional) The original image path or URI. If it's supplied, only this image derivative will be flushed.
Return value
$this
Overrides ImageStyleInterface::flush
1 call to ImageStyle::flush()
- ImageStyle::postSave in core/
modules/ image/ src/ Entity/ ImageStyle.php - Acts on a saved entity before the insert or update hook is invoked.
File
- core/
modules/ image/ src/ Entity/ ImageStyle.php, line 245 - Contains \Drupal\image\Entity\ImageStyle.
Class
- ImageStyle
- Defines an image style configuration entity.
Namespace
Drupal\image\EntityCode
public function flush($path = NULL) {
// A specific image path has been provided. Flush only that derivative.
if (isset($path)) {
$derivative_uri = $this
->buildUri($path);
if (file_exists($derivative_uri)) {
file_unmanaged_delete($derivative_uri);
}
return $this;
}
// Delete the style directory in each registered wrapper.
$wrappers = \Drupal::service('stream_wrapper_manager')
->getWrappers(StreamWrapperInterface::WRITE_VISIBLE);
foreach ($wrappers as $wrapper => $wrapper_data) {
if (file_exists($directory = $wrapper . '://styles/' . $this
->id())) {
file_unmanaged_delete_recursive($directory);
}
}
// Let other modules update as necessary on flush.
$module_handler = \Drupal::moduleHandler();
$module_handler
->invokeAll('image_style_flush', array(
$this,
));
// Clear caches so that formatters may be added for this style.
drupal_theme_rebuild();
Cache::invalidateTags($this
->getCacheTagsToInvalidate());
return $this;
}