class FlushSingleImage in Flush Single Image Styles 8
Class FlushSingleImage.
Hierarchy
- class \Drupal\flush_single_image\FlushSingleImage implements FlushSingleImageInterface
Expanded class hierarchy of FlushSingleImage
1 string reference to 'FlushSingleImage'
1 service uses FlushSingleImage
File
- src/
FlushSingleImage.php, line 11
Namespace
Drupal\flush_single_imageView source
class FlushSingleImage implements FlushSingleImageInterface {
/**
* Drupal\Core\Entity\EntityTypeManager definition.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* Drupal\Core\File\FileSystem definition.
*
* @var \Drupal\Core\File\FileSystem
*/
protected $fileSystem;
/**
* Constructs a new FlushSingleImage object.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, FileSystemInterface $file_system) {
$this->entityTypeManager = $entity_type_manager;
$this->fileSystem = $file_system;
}
/**
* {inheritdoc}
*/
public function flush($path) {
$style_paths = $this
->getStylePaths($path);
foreach ($style_paths as $style_path) {
$this->fileSystem
->unlink($style_path);
}
return $style_paths;
}
/**
* {inheritdoc}
*/
public function getStylePaths($path) {
$path = $this
->buildUri($path);
$styles = $this->entityTypeManager
->getStorage('image_style')
->loadMultiple();
$style_paths = [];
foreach ($styles as $style) {
$style_path = $style
->buildUri($path);
if (is_file($style_path) && file_exists($style_path)) {
$style_paths[] = $style_path;
}
}
return $style_paths;
}
/**
* Build a URI for a given path if it's missing the scheme.
*/
protected function buildUri($path) {
if (!$this->fileSystem
->uriScheme($path)) {
$path = file_default_scheme() . '://' . preg_replace('/^\\//', '', $path);
}
return $path;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FlushSingleImage:: |
protected | property | Drupal\Core\Entity\EntityTypeManager definition. | |
FlushSingleImage:: |
protected | property | Drupal\Core\File\FileSystem definition. | |
FlushSingleImage:: |
protected | function | Build a URI for a given path if it's missing the scheme. | |
FlushSingleImage:: |
public | function |
{inheritdoc} Overrides FlushSingleImageInterface:: |
|
FlushSingleImage:: |
public | function |
{inheritdoc} Overrides FlushSingleImageInterface:: |
|
FlushSingleImage:: |
public | function | Constructs a new FlushSingleImage object. |