Render entity fields retrieved by EntityQuery I'm building a table with TableSort retrieved by EntityQuery like explained in this post. 

The result fields vary a lot and I have a hard time to figure out how to render the results of the different field types, like dates, arrays of entities, taxnomomies, etc.

The most simple way to format the rows is just outputting the field values:

$row = [
    'data' =&gt; [
        $node-&gt;title-&gt;value,
        $node-&gt;field_date-&gt;value,
        $node-&gt;field_persons-&gt;value,
        $node-&gt;field_tags-&gt;value,
];


Now I want to output every column in a different way:


titles linked to the node
dates formatted and not as timestamps
persons as list with every person name linked to his node
tags as list with every tag linked to it's taxonomy


I managed to get titles and dates outputted like I wanted, but I can't figure out to do that for persons and tags:

foreach ($nids as $nid) {
    $node = \Drupal\node\Entity\NODE::load($nid);
    $link['#markup'] = '&lt;a href="/node/'.$nid.'"&gt;'.$node-&gt;title-&gt;value.'&lt;a&gt;';

    kint($node);

    $row = [
        'data' =&gt; [
            \Drupal::service('renderer')-&gt;render($link),
            format_date((int)$node-&gt;field_date-&gt;value,'custom','Y-m-d'),
            $node-&gt;field_persons-&gt;value,
            $node-&gt;field_tags-&gt;value,
        ],
    ];
    $rows[] = $row;
}


Is there a more elegant way to output content of individual fields? Or do I have to find out for every field how to output it investigating it's field type and building the result on my own?

How would I do that for persons or tags outputting the list of result with links to their nodes?
Fields have a view() method that accept either a view mode or an array with formatter/display settings (same format as stored in a view display config entity or passed to a base field). 

$entity->get('field_date')->view('teaser').

That returns a render array that you can then display.

If you also use #type table then you can make each row a numeric child key and you can directly use the render array.