Some targets with prefix are not checked properly

Created on 18 February 2025, 5 days ago

Problem/Motivation

On our site entity mesh does not detect properly links with language prefix.

Steps to reproduce

Example:

The problem comes from \Drupal\entity_mesh\EntityRender::processInternalHref

  protected function processInternalHref(TargetInterface $target, string $langcode) {
    $found_data = FALSE;
    // Remove the langcode to find the alias.
    // @todo take into account other languages also to support cross-language paths.
    // @todo this is the default URL creation, change with the real one.
    $alias = str_replace('/' . $langcode, '', $target->getPath() ?? '');

Proposed resolution

Use the prefix service to find the alias.
https://drupal.stackexchange.com/a/251484

function getLanguagePrefix() {
    if($prefixes = \Drupal::config('language.negotiation')->get('url.prefixes')) {
      $language = \Drupal::languageManager()->getCurrentLanguage()->getId();
      return "/". $prefixes[$language];
    }
    return null;
  }
🐛 Bug report
Status

Active

Version

1.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