Kloport
10/21/2017 - 2:05 PM

Find bundle image url from a referenced content in a Paragraph

function THEME_preprocess_paragraph__PARAGRAPH(array &$variables) {
    $paragraph = $variables['paragraph'];
    $node = $paragraph->get('field_REFERENCED_CONTENT')->getValue();
    $node = \Drupal::entityTypeManager()->getStorage('node')->load($node[0]['target_id']);
    $tid = ($node->field_BUNDLE_IMAGE->target_id);
    $media = \Drupal\media_entity\Entity\Media::load($tid);
    $variables['image_url'] = file_create_url($media->field_image->entity->uri->value);
}