I have a paragraph type to output a list of content. The editor can set different options, one of them is to show the list as teasers or just node titles linked to node. The corresponding part in code looks like:
if ($teaser_display) {
$value = \Drupal::entityTypeManager()->getViewBuilder('node')->view($node, 'teaser');
}
else {
$value = \Drupal::entityTypeManager()->getViewBuilder('node')->viewField($node->get('title'), ['link' => true, 'type' => 'entity_reference_label']);
}
Is there a way to build the render array for titel field linked to the node without creating a dedicated view mode and without rendering the markup directly? I thought it should somehow work to use the method viewField() as $display_options can either be a view mode or an array with display options.
$paragraph->field_reference
withentity_reference_label
. 2) Yes, now the title is not configurable in view modes and hardcoded in the node template, but this is going to change. See drupal.org/project/drupal/issues/2353867'#cache' => ['tags' => $node->getCacheTags()],
, which btw. the field formatter on the paragraph field would do.