function InstallHelper::createFileEntity
Same name in other branches
- 9 core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()
- 8.9.x core/profiles/demo_umami/modules/demo_umami_content/src/InstallHelper.php \Drupal\demo_umami_content\InstallHelper::createFileEntity()
- 10 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 865
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, FileExists::Replace);
} catch (FileException) {
$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.