Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanLaufer/f76241520365dac460dff8f0dc5a964b to your computer and use it in GitHub Desktop.
Save DanLaufer/f76241520365dac460dff8f0dc5a964b to your computer and use it in GitHub Desktop.
Drupal 8 - Drill down from Node to paragraph reference to paragraph entity to taxonomy reference field
function example_preprocess_node(&$variables) {
$node = $variables['node'];
$paragraph = $node->field_paragraph_example->entity;
$nested_paragraph = $paragraph->field_another_paragraph_ref->entity;
$term = $nested_paragraph->field_example_term_ref->entity;
// The following simple syntax works when you just need the first value of the field:
$textfield_value_on_term = $term->field_exampletext_on_term->value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment