protected function Twitter::getLocalImageUri in Media entity Twitter 8.2
Computes the destination URI for a tweet image.
Parameters
mixed $id: The tweet ID.
\Drupal\media\MediaInterface $media: The media entity.
string|null $media_url: The URL of the media (i.e., photo, video, etc.) associated with the tweet.
Return value
string The desired local URI.
1 call to Twitter::getLocalImageUri()
- Twitter::getMetadata in src/
Plugin/ media/ Source/ Twitter.php - Gets the value for a metadata attribute for a given media item.
File
- src/
Plugin/ media/ Source/ Twitter.php, line 409
Class
- Twitter entity media source.
Namespace
Drupal\media_entity_twitter\Plugin\media\SourceCode
protected function getLocalImageUri($id, MediaInterface $media, $media_url = NULL) {
$directory = $this->configFactory
->get('media_entity_twitter.settings')
->get('local_images');
// Ensure that the destination directory is writable. If not, log a warning
// and return the default thumbnail.
$ready = $this->fileSystem
->prepareDirectory($directory, FileSystemInterface::CREATE_DIRECTORY | FileSystemInterface::MODIFY_PERMISSIONS);
if (!$ready) {
$this->logger
->warning('Could not prepare thumbnail destination directory @dir', [
'@dir' => $directory,
]);
return parent::getMetadata($media, 'thumbnail_uri');
}
$local_uri = $directory . '/' . $id . '.';
if ($media_url) {
$local_uri .= pathinfo($media_url, PATHINFO_EXTENSION);
}
else {
// If there is no media associated with the tweet, we will generate an
// SVG thumbnail.
$local_uri .= 'svg';
}
return $local_uri;
}