Reference to an untranslated page causes 404 of parent page

Created on 19 April 2023, over 1 year ago
Updated 7 August 2024, 4 months ago

Problem/Motivation

When creating a content type with an entity reference field, it's possible that that field links to a page that's untranslated.

With the current setup of the module, the parent page that links to the untranslated entity will also throw a 404, even though it's translated.

Steps to reproduce

* Create a content type with a reference field
* Create a page in a certain language
* Create another page in another language, and add a reference to the earlier created page
* When viewing this page, you'll also receive a 404.

Proposed resolution

Add extra validation in the entity_view hook to see if the current page matches the entity before giving the 404

Remaining tasks

TBD: Decide what needs to happen with the link to the node, if it still needs to be shown or not.

🐛 Bug report
Status

Needs work

Version

1.0

Component

Code

Created by

🇧🇪Belgium brentg Ghent

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

Comments & Activities

  • Issue created by @brentg
  • @brentg opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇧🇪Belgium al0a

    Created a patch, with another approach: We shouldn't check on the view mode, since this can be anything. It also supports multiple entities.

  • 🇧🇪Belgium daften

    I tried to reproduce this problem using the steps from the description, but couldn't do that. Maybe the link being shown is already prevented by another contrib module on the project I tested it on or the behaviour changed in Drupal core.

    The patch looks good, but without a means to reproduce it, I can't merge it in.

  • Status changed to Needs work 4 months ago
  • 🇧🇪Belgium kevinvb

    Tested the patch because without it the functionality of this module will prevent being able to index content in the following case:

    1. Have a multilingual website
    2. Make sure the full content is being index in you search api index
    3. Index content while in eg. English

    If you have content in Dutch but it isn't translated to English the module will throw a 404 because it checks on the view mode and it uses the current language (EN) which makes it impossible to index the content in your search index.
    Using the patch, not the MR, on Drupal 10.3 it makes indexing the content possible because it doesn't intervene anymore.

    I would however advise to make the patch and MR similar. And instead of combining variables into checking the routeName it would be better to use:
    $entity->toUrl()->getRouteName()

Production build 0.71.5 2024