Rendered entity reference field (list-group) disappears, when user can't access the referenced items. Why? I have been trying to find the reason for this problem for a few days now... without any luck. Which is why I would like to ask for help here...

In a nutshell: I'm working on a simple LMS and have defined a content type Course that contains an entity reference field field_lessons, which refers to another content type Lesson. In the template file node--course--full.html.twig I'm using the following code to render a "table of contents" in the sidebar:

...
&lt;aside&gt;
  {{ content.field_lessons }}
&lt;/aside&gt;
...


In addition I'm using a template file field--node--field-lessons--course.html.twig for rendering the field:

...
&lt;nav class="list-group"&gt;
  {% for item in items %}
    {% if (item.viewaccess) %}
      &lt;a class="list-group-item list-group-item-action" href="..."&gt;
    {% else %}
      &lt;span class="list-group-item list-group-item-action disabled"&gt;
    {% endif %}
      &lt;div class="list-group-item-heading"&gt;
        {{ item.title }}
      &lt;/div&gt;
      ...
    {% if (item.viewaccess) %}
      &lt;/a&gt;
    {% else %}
      &lt;/span&gt;
    {% endif %}        
  {% endfor %}
&lt;/nav&gt;
...


(Note that I deliberately left out a few insignificant details in the code: These are marked with "...".)

So, depending on whether the current user can access a single lesson (I'm using the variable item.viewaccess, which depends on hook_node_access() and is set in hook_preprocess_node()), each lesson is rendered as active or disabled list-group-item. So far, this works perfectly.

Something weird happens, however, as soon as all lessons are locked for the current user: In this case, none of the lessons gets rendered and the whole table of contents (i.e. the whole &lt;nav&gt; block) disappears.

I'm totally stumped at this point. Can anyone offer an idea as to why this happens?
Any help would be much appreciated.
FWIW :

The entity reference field formatters that are in core use the method getEntitiesToView() (From class EntityReferenceFormatterBase) to load the referenced entities.

This method honors entity access :

$access = $this-&gt;checkAccess($entity);
// ...
if ($access-&gt;isAllowed()) {
  // ...
     $entities[$delta] = $entity;
    }
//...
return $entities;


so yes, it seems normal that nothing is rendered.