Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanLaufer/b74ccba8e6c0175a6d3756e28f53aaa6 to your computer and use it in GitHub Desktop.
Save DanLaufer/b74ccba8e6c0175a6d3756e28f53aaa6 to your computer and use it in GitHub Desktop.
Drupal 8 - Get a field from a paragraph in template_preprocess_node()
if($node) {
// we have a node, so use headline in hero, or fall back to node title
if($node->field_hero_section && $node->field_hero_section->getValue() && $node->field_hero_section->getValue()[0]) {
$paragraph = $node->field_hero_section->getValue()[0];
$paragraph_entity = \Drupal\paragraphs\Entity\Paragraph::load( $paragraph['target_id'] );
return $paragraph_entity->field_headline->value;
} else {
return $node->getTitle();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment