protected function InstallHelper::createFileEntity in Drupal 10
Same name and namespace in other branches
- 8 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()
- 9 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.
File
- core/
profiles/ demo_umami/ modules/ demo_umami_content/ src/ InstallHelper.php, line 839
Class
- InstallHelper
- Defines a helper class for importing default content.
Namespace
Drupal\demo_umami_contentCode
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();
}