->
save();
/** @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface $display_repository */
$display_repository = \Drupal::
service('entity_display.repository'
);
if (!
$this->entity->
getEntityType()->
hasHandlerClass('view_builder'
)) { $display_repository->
getViewDisplay($entity_type,
$bundle, 'full'
) ->
setComponent($field_name,
[ 'type' => 'entity_reference_label',
]) ->
save();
} else { $referenced_entity_view_mode =
$this->
selectViewMode($this->entity->
getEntityTypeId());
$display_repository->
getViewDisplay($entity_type,
$bundle, 'full'
) ->
setComponent($field_name,
[ 'type' => 'entity_reference_entity_view',
'settings' =>
[ 'view_mode' =>
$referenced_entity_view_mode,
],
]) ->
save();
} // Create an entity that does reference the entity being tested.