Skip to content
Snippets Groups Projects

Pass the Media creation date to getLocalThumbnailUri().

1 unresolved thread
2 files
+ 29
3
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -257,7 +257,7 @@ public function getMetadata(MediaInterface $media, $name) {
return parent::getMetadata($media, 'default_name');
case 'thumbnail_uri':
return $this->getLocalThumbnailUri($resource) ?: parent::getMetadata($media, 'thumbnail_uri');
return $this->getLocalThumbnailUri($resource, $media) ?: parent::getMetadata($media, 'thumbnail_uri');
case 'type':
return $resource->getType();
@@ -387,6 +387,8 @@ public function defaultConfiguration() {
*
* @param \Drupal\media\OEmbed\Resource $resource
* The oEmbed resource.
* @param \Drupal\media\MediaInterface|null $media
* The media entity that contains the resource.
*
* @return string|null
* The local thumbnail URI, or NULL if it could not be downloaded, or if the
@@ -397,7 +399,15 @@ public function defaultConfiguration() {
* toggle-able. See https://www.drupal.org/project/drupal/issues/2962751 for
* more information.
*/
protected function getLocalThumbnailUri(Resource $resource) {
protected function getLocalThumbnailUri(Resource $resource, MediaInterface $media = NULL) {
if (is_null($media)) {
@trigger_error('Calling ' . __METHOD__ . '() without the $media argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3432920', E_USER_DEPRECATED);
$token_data = [];
}
else {
$token_data = ['date' => $media->getCreatedTime()];
}
// If there is no remote thumbnail, there's nothing for us to fetch here.
    • Comment on lines -400 to 401

      This will break any plugins or custom code that extends Oembed and implements this method. Can we add a default value of NULL and trigger a deprecation error if the value is NULL

Please register or sign in to reply
$remote_thumbnail_url = $resource->getThumbnailUrl();
if (!$remote_thumbnail_url) {
@@ -409,7 +419,11 @@ protected function getLocalThumbnailUri(Resource $resource) {
// contain HTML, the tags will be removed and XML entities will be decoded.
$configuration = $this->getConfiguration();
$directory = $configuration['thumbnails_directory'];
$directory = $this->token->replace($directory);
// The thumbnail directory might contain a date token, so we pass in the
// creation date of the media entity so that the token won't rely on the
// current request time, making the current request have a max-age of 0.
// @see system_tokens() for $type == 'date'.
$directory = $this->token->replace($directory, $token_data);
$directory = PlainTextOutput::renderFromHtml($directory);
// The local thumbnail doesn't exist yet, so try to download it. First,
Loading