Problem/Motivation
I would like to redirect users to right language alias when the entity exists in the requested language.
For instance, lets assume that the node is having URL alias in source language (English) as /test-node-en. This node is having translation available in French with URL alias as /test-node-fr. So when the user requests /fr/test-node-en, it responds with 404 page. At this point, I would like the user to get redirected to /fr/test-node-fr page.
Proposed resolution
The URL alias requested for the entity needs to be checked in the path_alias table. If the requested URL is valid: fetch the entity id, load the entity and check if the translation is available in the requested language. If yes, then redirect the user to the right alias of the requested language.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 3227048-redirect_to_right_alias-7.patch | 6.2 KB | rajiv.singh |
| #6 | 3227048-redirect_to_right_alias-6.patch | 6.17 KB | gskharmujai |
| #3 | 3227048-redirect_to_right_alias-3.patch | 6.08 KB | vatsalkhanna |
Comments
Comment #2
vatsalkhanna commentedComment #3
vatsalkhanna commentedFixed issue with the redirect response. Updated patch.
Comment #4
walkingdexter commentedHi @vatsalkhanna!
Your solution is for a very specific case. In my opinion, this logic should be implemented in a custom module. In addition, the presented solution does not correspond to the main idea of the module - redirecting from pages of non-existent translations. In your case, the entity translation is assumed to exist.
Comment #5
gskharmujai commentedHi @vatsalkhanna
I had implemented this patch for one of my use cases but when i try to view an unpublished translation it redirects back to the source translation but it shows up a Drupal warning block but no message is displayed.
After investigating i found out that the redirection message value was not set. I had updated the patch to hide the warning generation code when the message is empty.
Comment #6
gskharmujai commentedComment #7
rajiv.singh commented@gskharmujai I have updated patch to check if the translation is published, else it was giving error for unpublished(or having other workflow state)