Double translation of LinkVideoEmbedColorbox link text

Created on 28 November 2022, about 2 years ago
Updated 27 November 2023, about 1 year ago

Problem/Motivation

A double translation happens in the LinkVideoEmbedColorbox Field Formatter.

      $link_text = $this->t($this->getSetting('link_text'));
      $entity = $items->getEntity();
      $field_name = $this->getSetting('link_text_field');
      if ($entity->hasField($field_name) && !empty($entity->get($field_name)->value)) {
        $link_text = $entity->get($field_name)->value;
      }

      $element[$delta] = [
        ...
        'children' => [
          'link' => Link::fromTextAndUrl($this->t($link_text), Url::fromUri($videos[$delta]['children']['#url']))
            ->toRenderable(),
        ],

Main problem happens when there is no link_text_field used. The first translation returns a TranslatableMarkup object, and in the second call, the t function needs a string, and not a TranslatableMarkup object, where it breaks.

Steps to reproduce

Create a media item with above formatter, enter a link text, no link_text_field. View the element.

Proposed resolution

Remove the 2nd translation, it is not needed. when a field_link_text field is used, the translation happens on the content level, and should not be passed to a t function.

πŸ› Bug report
Status

Fixed

Version

6.1

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium mallezie Loenhout

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024