/Drupal - Check for Node with Specific Paragraph Reference And get References on one of those fields
Last active
October 19, 2018 12:07
-
-
Save DanLaufer/9cb714d8dcc5921965a51b9a92d9dd22 to your computer and use it in GitHub Desktop.
Drupal - Check for Node with Specific Paragraph Reference
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
$query = \Drupal::entityQuery('node'); | |
$node_ids = $query | |
->condition('status', 1) | |
->exists('field_sidebar') | |
->execute(); | |
$count_fixed = 0; | |
$node_ids_with_related_links = []; | |
foreach($node_ids as $node_id) { | |
$node = \Drupal\node\Entity\Node::load($node_id); | |
$sidebar_paragraphs = $node->get('field_sidebar')->referencedEntities(); | |
foreach($sidebar_paragraphs as $parag) { | |
if($parag->getParagraphType()->id == 'related_links') { | |
$count_fixed++; | |
print_r('Title: '.$node->getTitle()); echo '<br />'; | |
print_r('Type: '.$node->getType()); echo '<br />'; | |
print_r('Node ID: '.$node_id); echo '<br />'; | |
print_r('Link: <a href="https://www.mysite.com/node/'.$node_id.'" target="_blank">Link</a>'); echo '<br />'; | |
print_r('Edit Link: <a href="https://www.mysite.com/node/'.$node_id.'/edit" target="_blank">Edit Link</a>'); echo '<br />'; | |
array_push($node_ids_with_related_links, $node_id); | |
$related_links = $parag->get('field_related_links')->referencedEntities(); | |
foreach($related_links as $linked_entity) { | |
print_r('---Linked Entity: <a href="https://www.mysite.com/node/'.$linked_entity->id().'" target="_blank">'.$linked_entity->getTitle().'</a> '); | |
print_r('(<a href="https://www.mysite.com/node/'.$linked_entity->id().'/edit" target="_blank">edit</a>)'); echo '<br />'; | |
} | |
echo '<br /><br /><br />'; | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment