function events_preprocess_node(&$variables) { // Get route name. $routeName = \Drupal::routeMatch()->getRouteName(); // Get entity. $node = &$variables['node']; // Check if it's an event. if ($node->getType() === 'event' && $node->hasField('field_place')) { // Get the place. $place = $node->get('field_place')->entity; // Check if place is NULL. if ($place) { if ($node->get('field_teaser_media')->isEmpty()) { // Get teaser. $variables['place_teaser_media'] = $place ->get('field_teaser_media') ->view($routeName === 'entity.node.canonical' ? 'default' : 'small_teaser_square'); } // Get organization name from place. $variables['place_organization'] = $place ->get('field_address')[0] ->get('organization')->getValue(); } } }