private function UriExtractor::getUriFromEntity in Twig Tweak 3.x
Same name and namespace in other branches
- 3.1.x src/UriExtractor.php \Drupal\twig_tweak\UriExtractor::getUriFromEntity()
Extracts file URI from content entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: Entity object that contains information about the file.
Return value
string|null A URI that can be used to access the file.
1 call to UriExtractor::getUriFromEntity()
- UriExtractor::extractUri in src/
UriExtractor.php - Returns a URI to the file.
File
- src/
UriExtractor.php, line 67
Class
- UriExtractor
- URI extractor service.
Namespace
Drupal\twig_tweakCode
private function getUriFromEntity(ContentEntityInterface $entity) : ?string {
if ($entity instanceof MediaInterface) {
$source = $entity
->getSource();
$value = $source
->getSourceFieldValue($entity);
if ($source instanceof OEmbedInterface) {
return $value;
}
/** @var \Drupal\file\FileInterface $file */
$file = $this->entityTypeManager
->getStorage('file')
->load($value);
if ($file) {
return $file
->getFileUri();
}
}
elseif ($entity instanceof FileInterface) {
return $entity
->getFileUri();
}
return NULL;
}