public function getActiveCampaignPage($campaign) {
    // Check if Campaign is Paused.
    $isPaused = $campaign->get('field_pause_campaign')->value;
    $fieldPauseLandingPage = $campaign->get('field_pause_landing_page')->getValue();
    $landingPageIds = [];
    if ($isPaused && isset($fieldPauseLandingPage[0]['target_id'])) {
      $landingPageIds[] = $fieldPauseLandingPage[0]['target_id'];
    }
    else {
      $fieldCampaignPages = $campaign->get('field_campaign_pages')->getValue();
      foreach ($fieldCampaignPages as $field) {
        $landingPageIds[] = $field['target_id'];
      }
    }
    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    // Load Landing page and check if it's published.
    $landingPages = $nodeStorage->loadMultiple($landingPageIds);
    /** @var \Drupal\node\Entity\Node $node */
    foreach ($landingPages as $node) {
      if ($node->isPublished()) {
        $publishedPages[] = $node;
      }
    }

    // If all pages are disabled, show Pause page.
    if (empty($publishedPages) && isset($fieldPauseLandingPage[0]['target_id'])) {
      return $nodeStorage->load($fieldPauseLandingPage[0]['target_id']);
    }

    return reset($publishedPages);
  }
public function getActiveCampaignPage($campaign) {
    // Check if Campaign is Paused.
    $isPaused = $campaign->get('field_pause_campaign')->value;
    $fieldPauseLandingPage = $campaign->get('field_pause_landing_page')->getValue();
    $landingPageIds = [];
    if ($isPaused && isset($fieldPauseLandingPage[0]['target_id'])) {
      $landingPageIds[] = $fieldPauseLandingPage[0]['target_id'];
    }
    else {
      $fieldCampaignPages = $campaign->get('field_campaign_pages')->getValue();
      foreach ($fieldCampaignPages as $field) {
        $landingPageIds[] = $field['target_id'];
      }
    }
    /** @var \Drupal\node\NodeStorage $nodeStorage */
    $nodeStorage = $this->entityTypeManager->getStorage('node');

    // Load Landing page and check if it's published.
    $landingPages = $nodeStorage->loadMultiple($landingPageIds);
    /** @var \Drupal\node\Entity\Node $node */
    foreach ($landingPages as $node) {
      if ($node->isPublished()) {
        $publishedPages[] = $node;
      }
    }

    // If all pages are disabled, show Pause page.
    if (empty($publishedPages) && isset($fieldPauseLandingPage[0]['target_id'])) {
      return $nodeStorage->load($fieldPauseLandingPage[0]['target_id']);
    }

    return reset($publishedPages);
  }
public function getActiveCampaignPage ( $ campaign ) { // Check if Campaign is Paused. $ isPaused = $ campaign -> get ( 'field_pause_campaign' ) -> value ; $ fieldPauseLandingPage = $ campaign -> get ( 'field_pause_landing_page' ) -> getValue ( ) ; $ landingPageIds = [ ] ; if ( $ isPaused && isset ( $ fieldPauseLandingPage [ 0 ] [ 'target_id' ] ) ) { $ landingPageIds [ ] = $ fieldPauseLandingPage [ 0 ] [ 'target_id' ] ; } else { $ fieldCampaignPages = $ campaign -> get ( 'field_campaign_pages' ) -> getValue ( ) ; foreach ( $ fieldCampaignPages as $ field ) { $ landingPageIds [ ] = $ field [ 'target_id' ] ; } } /** @var \Drupal\node\NodeStorage $nodeStorage */ $ nodeStorage = $ this -> entityTypeManager -> getStorage ( 'node' ) ; // Load Landing page and check if it's published. $ landingPages = $ nodeStorage -> loadMultiple ( $ landingPageIds ) ; /** @var \Drupal\node\Entity\Node $node */ foreach ( $ landingPages as $ node ) { if ( $ node -> isPublished ( ) ) { $ publishedPages [ ] = $ node ; } } // If all pages are disabled, show Pause page. if ( empty ( $ publishedPages ) && isset ( $ fieldPauseLandingPage [ 0 ] [ 'target_id' ] ) ) { return $ nodeStorage -> load ( $ fieldPauseLandingPage [ 0 ] [ 'target_id' ] ) ; } return reset ( $ publishedPages ) ; }
Get Campaign page referenced in Campaign node.

@param \Drupal\node\NodeInterface $campaign
Campaign node.

@return mixed Published campaign page or FALSE if there is no published referenced campaign page.
Get Campaign page referenced in Campaign node .