Skip to content
Snippets Groups Projects
Commit a583b0a4 authored by Carlos Busto Capeáns's avatar Carlos Busto Capeáns Committed by Ivan Vidusenko
Browse files

Issue #3030412 by cbccharlie, Fonski: "Link to content" generates only default language URL

parent 6ea41cf9
No related branches found
No related tags found
1 merge request!3fix: Link to content generates only default language URL
......@@ -191,7 +191,7 @@ class MediaResponsiveThumbnailFormatter extends ResponsiveImageFormatter {
->first() : $file->get('thumbnail')->first(),
'#item_attributes' => $item_attributes,
'#responsive_image_style_id' => $responsive_image_style ? $responsive_image_style->id() : '',
'#url' => $this->getMediaThumbnailUrl($file, $items->getEntity()),
'#url' => $this->getMediaThumbnailUrl($file, $items->getEntity(), $langcode),
];
// Add cacheability of each item in the field.
......@@ -223,16 +223,22 @@ class MediaResponsiveThumbnailFormatter extends ResponsiveImageFormatter {
* The media item.
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity that the field belongs to.
* @param string $langcode
* The language that should be used to render the field. Defaults
* to the current content language.
*
* @return \Drupal\Core\Url|null
* The URL object for the media item or null if we don't want to add
* a link.
*/
protected function getMediaThumbnailUrl(MediaInterface $media, EntityInterface $entity) {
protected function getMediaThumbnailUrl(MediaInterface $media, EntityInterface $entity, $langcode) {
$url = NULL;
$image_link_setting = $this->getSetting('image_link');
// Check if the formatter involves a link.
if ($image_link_setting == 'content') {
if ($langcode && $entity->hasTranslation($langcode)) {
$entity = $entity->getTranslation($langcode);
}
if (!$entity->isNew()) {
$url = $entity->toUrl();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment