$file = \Drupal\file\Entity\File::load(123); /** @var \Drupal\file\FileInterface $file */ $file_relative_url = $file->createFileUrl(); // /sites/default/files/example.jpg $file_absolute_url = $file->createFileUrl(FALSE); // http://example.com/sites/default/files/example.jpg $file_uri = $file->getFileUri(); // public://example.jpg
Similar Posts:
- how to Programmatically update an entity reference field in Drupal 8 & 9
- How to change entity before it is created or updated.
- how to set date field programmatically drupal 8 / 9
- url without www and http to https in drupal 8/9
- Drupal: Creating a Computed Entity Field
2,237