3

Having an entity reference, Drupal 8 automatically renders the base language of a referenced entity if it isn't translated yet. Is there a way to globally prevent that? So if there is ContentType1 referencing ContentType2, both have a default language of en-gb. Translating ContentType1 to de-de will by default still show ContentType2's en-gb node unless I manually translate it or change a thing.

What I currently do is comparing the current page language \Drupal::languageManager()->getCurrentLanguage()->getId(); with the current node language $variables['node']->language()->getId(); and return an empty node.html.twig.

Is there a better solution? Especially when you have multiple node.twig.html

1 Answer 1

1

One way to think about it is to disable language fallback mechanism in Drupal. Although there are 3 different modules which handle language fallback priority, none of them provide such functionality.
However, the module Disable Language allows admin to disable an entire language entirely without deleting the content itself.
I think you can use its code to implement an EventSubscriber which checks whether the node has a translation for the current site language then return a NotFoundException in this case. This will cover direct node access.
I'm not entirely sure how to deal with nodes loaded via DB. I think you can use hook_entity_load for this case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.