Hello Community,
since I wanted to show the output of a view in a custom DOM I created a custom views display style plugin via the following documentation
https://www.drupal.org/docs/8/creating-custom-modules/building-a-views-d...
Everything went quite smoothly till I recognized, that my multilingual page always shows the default language of the node in my view even when changing the language.
After some searching around I found out, that I have to manually check the current language in the TWIG template and get the translated node. That was quite the surprise for me since every other overwritten TWIG file in my custom theme didn't need that.
Im talking about the following:
{% if rows|length %}
{% for row in view.result %}
{% set current_language = row.node_field_data_langcode %}
{% if row._entity.hastranslation(current_language) %}
{% set entity = row._entity.translation(current_language) %}
{% else %}
{# No translation available for this node #}
{% endif %}
{% endfor %}
{% elseif empty %}
<div class="view-empty">
{{ empty }}
</div>
{% endif %}
And I just don't understand why this is necessary. Can't Drupal just set the node to the correct language before I iterate trough it in my custom views display style plugin?
Comments
Comment #2
kevin.pfeifer CreditAttribution: kevin.pfeifer commentedComment #8
kevin.pfeifer CreditAttribution: kevin.pfeifer commented