You are here

public static function Imce::getFileEntity in IMCE 8

Same name and namespace in other branches
  1. 8.2 src/Imce.php \Drupal\imce\Imce::getFileEntity()

Returns a managed file entity by uri.

Optionally creates it.

3 calls to Imce::getFileEntity()
Delete::deleteFileUri in src/Plugin/ImcePlugin/Delete.php
Deletes a file by uri.
ImceFileField::setWidgetValue in src/ImceFileField.php
Sets widget file id values by validating and processing the submitted data.
Resize::resizeItems in src/Plugin/ImcePlugin/Resize.php
Resizes a list of imce items and returns succeeded ones.

File

src/Imce.php, line 296

Class

Imce
Imce container class for helper methods.

Namespace

Drupal\imce

Code

public static function getFileEntity($uri, $create = FALSE, $save = FALSE) {
  $file = FALSE;
  if ($files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'uri' => $uri,
  ])) {
    $file = reset($files);
  }
  elseif ($create) {
    $file = static::createFileEntity($uri, $save);
  }
  return $file;
}