Generated URL of parent entity is not translated

Created on 19 October 2022, over 1 year ago
Updated 20 May 2024, about 1 month 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.69.0 2024