You are here

private static function TwigExtension::getUriFromEntity in Twig Tweak 8.2

Extracts file URI from content entity.

Parameters

object $entity: Entity object that contains information about the file.

Return value

string|null A URI that may be used to access the file.

1 call to TwigExtension::getUriFromEntity()
TwigExtension::fileUri in src/TwigExtension.php
Returns a URI to the file.

File

src/TwigExtension.php, line 1258

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

private static function getUriFromEntity($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
        ->getFileUri();
    }
  }
  elseif ($entity instanceof FileInterface) {
    return $entity
      ->getFileUri();
  }
}