protected function Twitter::getLocalImageUri in Media entity Twitter 8
Computes the destination URI for a tweet image.
Parameters
mixed $id: The tweet ID.
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.
2 calls to Twitter::getLocalImageUri()
- Twitter::getField in src/
Plugin/ MediaEntity/ Type/ Twitter.php - Gets a media-related field/value.
- Twitter::thumbnail in src/
Plugin/ MediaEntity/ Type/ Twitter.php - Gets thumbnail image.
File
- src/
Plugin/ MediaEntity/ Type/ Twitter.php, line 352
Class
- Provides media type plugin for Twitter.
Namespace
Drupal\media_entity_twitter\Plugin\MediaEntity\TypeCode
protected function getLocalImageUri($id, $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 = file_prepare_directory($directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
if (!$ready) {
$this->logger
->warning('Could not prepare thumbnail destination directory @dir', [
'@dir' => $directory,
]);
return $this
->getDefaultThumbnail();
}
$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;
}