Entity references are common practice in drupal. With this snippet you can directly get the title of a referenced entity.

$entity->get('field_contest')->referencedEntities()[0]->label()

If you have multiple referenced entities, do:

$entities = $entity->get('field_contest')->referencedEntities();
foreach($entities as $entity) {
  print $entity->label();
}

 

 

Saved you some valuable time?

Buy me a drink 🍺 to keep me motivated to create free content like this!