You are here

public static function ImageCrop::countFileUsages in Image Widget Crop 8.2

Same name and namespace in other branches
  1. 8 src/Element/ImageCrop.php \Drupal\image_widget_crop\Element\ImageCrop::countFileUsages()

Counts how many times a file has been used.

Parameters

\Drupal\file\FileInterface $file: The file entity to check usages.

Return value

int Returns how many times the file has been used.

1 call to ImageCrop::countFileUsages()
ImageCrop::processCrop in src/Element/ImageCrop.php
Render API callback: Expands the image_crop element type.

File

src/Element/ImageCrop.php, line 283

Class

ImageCrop
Provides a form element for crop.

Namespace

Drupal\image_widget_crop\Element

Code

public static function countFileUsages(FileInterface $file) {
  $counter = 0;
  $file_usage = \Drupal::service('file.usage')
    ->listUsage($file);
  foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($file_usage)) as $usage) {
    $counter += (int) $usage;
  }
  return $counter;
}