private static function TwigExtension::getUrlFromEntity in Twig Tweak 8.2
Extracts file URL from content entity.
Parameters
object $entity: Entity object that contains information about the file.
Return value
string|null A URL that may be used to access the file.
1 call to TwigExtension::getUrlFromEntity()
- TwigExtension::fileUrl in src/
TwigExtension.php - Returns a URL path to the file.
File
- src/
TwigExtension.php, line 1307
Class
- TwigExtension
- Twig extension with some useful functions and filters.
Namespace
Drupal\twig_tweakCode
private static function getUrlFromEntity($entity) {
if ($entity instanceof MediaInterface) {
$source = $entity
->getSource();
$value = $source
->getSourceFieldValue($entity);
if ($source instanceof OEmbedInterface) {
return $value;
}
elseif ($file = File::load($value)) {
return $file
->createFileUrl();
}
}
elseif ($entity instanceof FileInterface) {
return $entity
->createFileUrl();
}
}