By dahdoul on
In Drupal 7 language switcher block used to disable/strike untranslated language links, but it does not work that way in Drupal 8. for example if I go to http://example.com/node/1 language switcher dose not disable/strike untranslated language links. any solution? thanks
Comments
Did anyone get a solution for
Did anyone get a solution for this yet?
You can use either of these.
Using hook_language_switch_links_alter in a custom module
It's really easy to create a minimal custom module, all you need is a .info.yml and a .module file.
Using hook_preprocess_block in a module or (preferably) a theme (THEME_NAME.theme file)
hide the whole block if there are no language translation avail
@Karol Haltenberger, Thank you for this! The preprocess hooks works great. It hides any language in the list if the node does not have the translation for that language. How can I modify this preprocess hook to hide the whole block if there are no language translation available for the node.
I've made a few modifications
I've made a few modifications to what Karol Haltenberger posted. These include:
I will probably post this module up once I've fully tested it.
Exactly what i need
Leon Kessler, this is exactly what I've been looking for. Did you wind up doing further testing and posting this somewhere?
I ended up putting it in a
I ended up putting it in a module I called "language_fallback_disable", which (as well as disabling the switcher links) also gives a 404 when you try to access an entity in a language that it has not been translated to yet.
Unfortunately, I could not find a nice way to do that (the entity access system does not support languages), so it's ended up in a quite hacky code (essentially an EventSubscriber on the request which does the check and hijacks the response with a 404).
So it's not really contrib ready, but happy to ping over the module if you need it.
Test your module
I'll likw to test your "language_fallback_disable" module.
thank you for sharing this
thank you for sharing this kind of information
On my setup I use page
On my setup I use page manager to override the node/{node} pages, so the
$entity = reset($params);gives aDrupal\page_manager\Entity\PageVariantIn case of a node, the node entity is my 5th element, while for a taxonomy term it's the 4th.
A suggestion for your second function.
For anyone that got here,
For anyone that got here, this code became a module that can be found at https://www.drupal.org/project/language_switcher_extended
Combined module
Shouldn't this functionality be bundles in one contrib module solving this for
Update: Finding this 2 month later again with the same need, I think there should be! Or even better a core fix. Are there any related issues?
http://www.DROWL.de || Professionelle Drupal Lösungen aus Ostwestfalen-Lippe (OWL)
http://www.webks.de || webks: websolutions kept simple - Webbasierte Lösungen die einfach überzeugen!
http://www.drupal-theming.com || Individuelle Responsive Themes