function InstallHelper::createFileEntity

Same name in other branches
  1. 8.9.x core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()
  2. 10 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()
  3. 11.x core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()

Creates a file entity based on an image path.

Parameters

string $path: Image path.

Return value

int File ID.

1 call to InstallHelper::createFileEntity()
InstallHelper::processImage in core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php
Process images into media entities.

File

core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php, line 844

Class

InstallHelper
Defines a helper class for importing default content.

Namespace

Drupal\demo_umami_content

Code

protected function createFileEntity($path) {
    $filename = basename($path);
    try {
        $uri = $this->fileSystem
            ->copy($path, 'public://' . $filename, FileSystemInterface::EXISTS_REPLACE);
    } catch (FileException $e) {
        $uri = FALSE;
    }
    $file = $this->entityTypeManager
        ->getStorage('file')
        ->create([
        'uri' => $uri,
        'status' => 1,
    ]);
    $file->save();
    $this->storeCreatedContentUuids([
        $file->uuid() => 'file',
    ]);
    return $file->id();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.