// Create two content types, with one content type containing a field that
// references entities of the second content type.
$this->
createContentType([ 'type' => 'bundle_with_reference_field',
'name' => 'bundle_with_reference_field',
]);
$this->
createContentType([ 'type' => 'bundle_referenced',
'name' => 'bundle_referenced',
]);
$this->
createEntityReferenceField('node', 'bundle_with_reference_field', 'field_reference', 'Reference field', 'node', 'default',
[ 'target_bundles' =>
['bundle_referenced'
],
]);
// Enable layout builder to the content type with the reference field, and
// add the reference field to the layout builder display.
$this->container->
get('entity_display.repository'
) ->
getViewDisplay('node', 'bundle_with_reference_field', 'full'
) ->
enableLayoutBuilder() ->
setComponent('field_reference',
['type' => 'entity_reference_label'
]) ->
save();
}