You are here

public function TwigExtension::fileUri in Twig Tweak 8.2

Returns a URI to the file.

Parameters

object $input: An object that contains the URI.

Return value

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

File

src/TwigExtension.php, line 1234

Class

TwigExtension
Twig extension with some useful functions and filters.

Namespace

Drupal\twig_tweak

Code

public function fileUri($input) {
  if ($input instanceof EntityReferenceFieldItemListInterface) {
    $referenced_entities = $input
      ->referencedEntities();
    if (isset($referenced_entities[0])) {
      return self::getUriFromEntity($referenced_entities[0]);
    }
  }
  elseif ($input instanceof EntityReferenceItem) {
    return self::getUriFromEntity($input->entity);
  }
  elseif ($input instanceof EntityInterface) {
    return self::getUriFromEntity($input);
  }
}