Name property from BreadcrumbList should be string TranslatableMarkup given

Created on 16 January 2025, 3 months ago

Problem/Motivation

When we tried to export content using default content we get the following error:
Object support when dumping a YAML file has been disabled
Debugging we saw that the error comes from the metatag breadcrumb and comparing it with the other metatags the name property is a \Drupal\Core\StringTranslation\TranslatableMarkup object instead of a string.

The problem comes from \Drupal\schema_metatag\Plugin\schema_metatag\PropertyType\BreadcrumbList::getItems

  public function getItems($input_value) {
    $values = [];
    if (!empty($input_value)) {
      $entity_route = $this->routeMatch->getCurrentRouteMatch();
      $breadcrumbs = $this->breadcrumbManager->build($entity_route)->getLinks();
      $key = 1;
      foreach ($breadcrumbs as $item) {
        ....

        $text = $item->getText();
        ...

        $values[$key] = [
          '@id' => $url,
          'name' => $text,
          'item' => $url,
        ];
        $key++;
      }
    }
    return $values;
  }

The method \Drupal\Core\Link::getText returns and \Drupal\Core\StringTranslation\TranslatableMarkup and default content expects a string.

Steps to reproduce

Install metatag and schema_metatag
Configure the schema breadcrumb metatag on a content.
Create a node and export it using default content.

Proposed resolution

Cast the TranslatableMarkup to a string.

🐛 Bug report
Status

Active

Version

3.0

Component

Code

Created by

🇪🇸Spain eduardo morales alberti Spain, 🇪🇺

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024