You are here

public static function Imce::createFileEntity in IMCE 8

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

Creates a file entity with an uri.

1 call to Imce::createFileEntity()
Imce::getFileEntity in src/Imce.php
Returns a managed file entity by uri.

File

src/Imce.php, line 310

Class

Imce
Imce container class for helper methods.

Namespace

Drupal\imce

Code

public static function createFileEntity($uri, $save = FALSE) {
  $values = [
    'uri' => $uri,
    'uid' => \Drupal::currentUser()
      ->id(),
    'status' => 1,
    'filesize' => filesize($uri),
    'filename' => \Drupal::service('file_system')
      ->basename($uri),
    'filemime' => \Drupal::service('file.mime_type.guesser')
      ->guess($uri),
  ];
  $file = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->create($values);
  if ($save) {
    $file
      ->save();
  }
  return $file;
}