Last active
April 13, 2023 12:38
-
-
Save DanLaufer/b74ccba8e6c0175a6d3756e28f53aaa6 to your computer and use it in GitHub Desktop.
Drupal 8 - Get a field from a paragraph in template_preprocess_node()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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