Generated URL of parent entity is not translated

Created on 19 October 2022, about 2 years ago
Updated 20 May 2024, 6 months ago

Problem/Motivation

When parent entity have translation the URL is not translated

Proposed resolution

See the attached patch

🐛 Bug report
Status

Postponed: needs info

Version

1.0

Component

Code

Created by

🇵🇹Portugal fall_0ut

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.

  • 🇫🇷France erwangel

    What about this ?

      // ------ Added line ( 45 of last dev - media_parent_entity_link_media_view() ) 
      //        to get the current language then set the right translated link
      $language = \Drupal::languageManager()->getCurrentLanguage();
      foreach ($components as $componentkey => $component) {
        if (!empty($component['third_party_settings']['media_parent_entity_link']['link_to_parent'])) {
          if ($entity->_referringItem) {
            if ($entity->_referringItem->getParent()) {
              if ($entity->_referringItem->getParent()->getParent()) {
                /* @var \Drupal\Core\Entity\EntityInterface $parententity */
                if ($parententity = $entity->_referringItem->getParent()
                  ->getParent()
                  ->getValue()) {
                  if (!$parententity->isNew()) {
                    try {
                      // ------ Set the right translated link here ------
                      //$url = $parententity->toUrl();
                      $url = $parententity->toUrl('canonical', ['language' => $language]);
                    }
                    catch (Exception $exception) {
                      $url = FALSE;
                    }
                    if ($url) {
                      ...
    

    In some of my tests it gives the right links

Production build 0.71.5 2024