How to programmatically reference entities? I am trying to reference an entity within my hook, so that every time a new entity is inserted, I create another entity referencing the first entity. I have not yet found a working way to reference an existing entity in my &quot;field_content&quot; when creating a new entity. 
My code looks like the below excerpt:
function ost_notifications_entity_insert(EntityInterface $entity) {
  if ($entity-&gt;bundle() == 'deadline' || $entity-&gt;bundle() == 'message') {
    $new_entity = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;create([
      'type' =&gt; 'notification',
      'title' =&gt; $entity-&gt;label(),
      'field_content' =&gt; &quot;referenced entity goes here&quot;
    ]);
    $new_entity-&gt;save();
  }
}
As pointed out by 4k4 in the comments, the most robust way is assign an entity object to the field like so:
$new_entity = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;create([
  'type' =&gt; 'notification',
  'title' =&gt; $entity-&gt;label(),
  'field_content' =&gt; [
    'entity' =&gt; $entity,
  ],
]);

For posterity, you can also do it by setting the field column (target_id) directly, but this is only useful if you have a saved entity. The first example will work for both new and existing entities.
$new_entity = \Drupal::entityTypeManager()-&gt;getStorage('node')-&gt;create([
  'type' =&gt; 'notification',
  'title' =&gt; $entity-&gt;label(),
  'field_content' =&gt; [
    'target_id' =&gt; $entity-&gt;id(),
  ],
]);