Objectives
- We want to add on a node page layout a block which uses a field from the currently rendered content (node).
- We want this block to be translated the same as the currently rendered entity.
- As a anonymous user, we want it to respect the published settings of the currently rendered entity.
- As an admin, we want to be able to see this block if the content is unpublished.
- We want to support cases when a content is not translated. The default Drupal behaviour is to use the default translation.
Configuration
- Do not use Published (= Yes) setting.
Views will remove itself results on which you don’t have permission—unless you have disabled access checks in the Query settings parameter of the view. Also, as an admin, you will still be able to see the block if the content is unpublished.
- Set Default translation (= True).
Views will retrieve the default translation, which is the default result when you attempt to go on a node page which has no translation.
- Set Rendering Language to Interface text language selected for page.
Views will attempt to translate the content. If no content translation is found, default translation will be used.
- Contextual filter set to Content: ID with Content ID from URL as default value.
- Hide block if the view output is empty.
No need to keep this block if there is no output (or keep it if you need it anyway).
Additional information
- Tested on Drupal 8.5.5 on simplytest.me.