Skip to content

Commit

Permalink
Allow additional fields to be mapped to the file entitiy
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Smith committed Apr 2, 2024
1 parent 9f1914d commit 99e0414
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/FileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,18 @@ protected function fileCreateEntity(\StdClass $stub): FileInterface {
}
}

return \Drupal::service('file.repository')->writeData(file_get_contents($path), $destination, FileSystemInterface::EXISTS_REPLACE);
$entity = \Drupal::service('file.repository')->writeData(file_get_contents($path), $destination, FileSystemInterface::EXISTS_REPLACE);

foreach ($stub as $property => $value) {
// If path or URI has been specified then the value has already been handled.
if (in_array($property, ['path', 'uri'])) {
continue;
}
$entity->set($property, $value);
}

$entity->save();
return $entity;
}

/**
Expand Down

0 comments on commit 99e0414

Please sign in to comment.