public function getNodeCampaignNode(NodeInterface $node) {
    $campaign = NULL;

    if ($node->getType() == 'campaign') {
      return $node;
    }

    if ($node->getType() == 'campaign_page') {
      $campaign = $node->field_campaign_parent->entity;
      if (!empty($campaign)) {
        return $campaign;
      }
    }

    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    // Get Campaign node with reference to given Landing page node.
    /** @var \Drupal\Core\Entity\Query\QueryInterface $query */
    $query = $nodeStorage->getQuery()
      ->condition('status', 1)
      ->condition('type', 'campaign');
    $orGroup = $query->orConditionGroup()
      ->condition('field_campaign_pages', $node->id(), 'IN')
      ->condition('field_pause_landing_page', $node->id());
    $nids = $query->condition($orGroup)->execute();

    /** @var \Drupal\node\NodeInterface $campaign */
    $campaign = $nodeStorage->load(reset($nids));

    return $campaign;
  }
public function getNodeCampaignNode(NodeInterface $node) {
    $campaign = NULL;

    if ($node->getType() == 'campaign') {
      return $node;
    }

    if ($node->getType() == 'campaign_page') {
      $campaign = $node->field_campaign_parent->entity;
      if (!empty($campaign)) {
        return $campaign;
      }
    }

    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    // Get Campaign node with reference to given Landing page node.
    /** @var \Drupal\Core\Entity\Query\QueryInterface $query */
    $query = $nodeStorage->getQuery()
      ->condition('status', 1)
      ->condition('type', 'campaign');
    $orGroup = $query->orConditionGroup()
      ->condition('field_campaign_pages', $node->id(), 'IN')
      ->condition('field_pause_landing_page', $node->id());
    $nids = $query->condition($orGroup)->execute();

    /** @var \Drupal\node\NodeInterface $campaign */
    $campaign = $nodeStorage->load(reset($nids));

    return $campaign;
  }
public function getNodeCampaignNode ( NodeInterface $ node ) { $ campaign = NULL ; if ( $ node -> getType ( ) == 'campaign' ) { return $ node ; } if ( $ node -> getType ( ) == 'campaign_page' ) { $ campaign = $ node -> field_campaign_parent -> entity ; if ( ! empty ( $ campaign ) ) { return $ campaign ; } } /** @var \Drupal\node\NodeStorage $nodeStorage */ $ nodeStorage = $ this -> entityTypeManager -> getStorage ( 'node' ) ; // Get Campaign node with reference to given Landing page node. /** @var \Drupal\Core\Entity\Query\QueryInterface $query */ $ query = $ nodeStorage -> getQuery ( ) -> condition ( 'status' , 1 ) -> condition ( 'type' , 'campaign' ) ; $ orGroup = $ query -> orConditionGroup ( ) -> condition ( 'field_campaign_pages' , $ node -> id ( ) , 'IN' ) -> condition ( 'field_pause_landing_page' , $ node -> id ( ) ) ; $ nids = $ query -> condition ( $ orGroup ) -> execute ( ) ; /** @var \Drupal\node\NodeInterface $campaign */ $ campaign = $ nodeStorage -> load ( reset ( $ nids ) ) ; return $ campaign ; }
Retrieves referenced Campaign node for the node.

@param \Drupal\node\NodeInterface $node
The node.

@return \Drupal\node\NodeInterface|null
Campaign node or NULL.
Retrieves referenced Campaign node for the node .