For the multilingual Drupal 8 based website I have created a view with a list of nodes. On the top of the page I have implemented a custom block with a autocomplete textfield, the textfield returns a JSON response with all available languages. After selecting the language, I want to update the fields (titles), so that they are displayed in the language, selected by the user.

The approach I am thinking about is after submitting the textfield, update the fields output. But for this I would need to create some URL for the fields output. How can I create a URL for the fields section with Drupal tools? Is it possible to distinguish the areas on the view? Please, help.

  • Why not just use the Exposed Language filter instead of a custom Block? – prkos Feb 11 at 14:28
  • Exposed language filter triggers the interface language. But in my case I just need to translate the titles inside of one view – user91143 Feb 11 at 14:32

You can not update the output of some part of views from custom block without actually rendering the views again. You have to reload the views using ajax request/ simple http request (as you prefer) with the langcode in views argument.

What you can do is add a global contextual filter in the view, Use that contextual filter's value in template_preprocess_views_* listed here, If contextual value is not empty.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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