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.