I have a content type that has a Paragraph entity reference field named "Grants". This "Grants" paragraph field has another paragraph entity reference field names "contacts". So the entity references are nested as :
Awards content type ---->(refers)--->Grants paragraph field--->(refers)--->Contacts paragraph field
I am trying to read the contacts reference fields in hook_preprocess_paragraph method and I cannot do that:
function mytheme_preprocess_paragraph(array &$variables) {
$pval = $variables['elements']['#paragraph'];
$paragraph = $pval->field_grant_contacts->getValue();
foreach ( $paragraph as $element ) {
$p = \Drupal\paragraphs\Entity\Paragraph::load( $element['target_id'] );
$text = $p->field_contact_name->getValue();
}
dd($text);
}
I am trying to reference the primary field - field_grant_contact. Through that I'm trying to read field_contact_name and the getValue method returns null. Any help on how to read nested entity reference fields?