public function getLandingPageCampNode(NodeInterface $node) {
    $camp = NULL;
    // Exit if the node is not a landing page.
    if ($node->bundle() != 'landing_page') {
      return $camp;
    }

    // If the node has the Location field.
    if ($node->hasField('field_location')) {
      if ($value = $node->field_location->referencedEntities()) {
        // referencedEntities() returns an array of entities, since the location
        // field can only have a single value we reset to get that node object.
        $camp = reset($value);
      }
    }
    // Else if a camp links to this landing page use the linking camp.
    else {
      // Need to get <front> path if set & is a node.
      $front = $this->config->get('page.front');
      // To track if this node is the front page.
      $is_front = FALSE;

      // Setup to lookup all aliases for this node.
      $langcode = $node->language()->getId();
      $system_path = '/node/' . $node->id();

      // If the front is set to this node directly.
      $is_front = ($front == $system_path) ? TRUE : $is_front;

      // Query 1 Camp nodes that link to this landing page.
      $query = \Drupal::entityQuery('node');
      $group = $query->orConditionGroup()
        ->condition('field_camp_menu_links', 'entity:node/' . $node->id())
        ->condition('field_camp_menu_links', 'internal:' . $system_path);

      // Since the link field allows internal links we must check if this node's
      // aliases are linked also.
      if ($aliases = $this->lookupPathAliases($system_path, $langcode)) {
        foreach ($aliases as $alias) {
          $group->condition('field_camp_menu_links', 'internal:' . $alias->alias);
          // Checking to see if the alias is the front page config value.
          $is_front = ($front == $alias->alias) ? TRUE : $is_front;
        }
      }

      // If this node is the front page we add the '/' path. This is how <front>
      // is represented in the link field storage.
      if ($is_front) {
        $group->condition('field_camp_menu_links', 'internal:/');
      }
      $query->condition('status', 1)
        ->condition($group)
        ->range(0, 1);
      $entity_ids = $query->execute();
      // If results returned.
      if (!empty($entity_ids)) {
        $node_storage = $this->entityTypeManager->getStorage('node');
        $camp = $node_storage->load(reset($entity_ids));
      }
    }

    return $camp;
  }
public function getLandingPageCampNode(NodeInterface $node) {
    $camp = NULL;
    // Exit if the node is not a landing page.
    if ($node->bundle() != 'landing_page') {
      return $camp;
    }

    // If the node has the Location field.
    if ($node->hasField('field_location')) {
      if ($value = $node->field_location->referencedEntities()) {
        // referencedEntities() returns an array of entities, since the location
        // field can only have a single value we reset to get that node object.
        $camp = reset($value);
      }
    }
    // Else if a camp links to this landing page use the linking camp.
    else {
      // Need to get <front> path if set & is a node.
      $front = $this->config->get('page.front');
      // To track if this node is the front page.
      $is_front = FALSE;

      // Setup to lookup all aliases for this node.
      $langcode = $node->language()->getId();
      $system_path = '/node/' . $node->id();

      // If the front is set to this node directly.
      $is_front = ($front == $system_path) ? TRUE : $is_front;

      // Query 1 Camp nodes that link to this landing page.
      $query = \Drupal::entityQuery('node');
      $group = $query->orConditionGroup()
        ->condition('field_camp_menu_links', 'entity:node/' . $node->id())
        ->condition('field_camp_menu_links', 'internal:' . $system_path);

      // Since the link field allows internal links we must check if this node's
      // aliases are linked also.
      if ($aliases = $this->lookupPathAliases($system_path, $langcode)) {
        foreach ($aliases as $alias) {
          $group->condition('field_camp_menu_links', 'internal:' . $alias->alias);
          // Checking to see if the alias is the front page config value.
          $is_front = ($front == $alias->alias) ? TRUE : $is_front;
        }
      }

      // If this node is the front page we add the '/' path. This is how <front>
      // is represented in the link field storage.
      if ($is_front) {
        $group->condition('field_camp_menu_links', 'internal:/');
      }
      $query->condition('status', 1)
        ->condition($group)
        ->range(0, 1);
      $entity_ids = $query->execute();
      // If results returned.
      if (!empty($entity_ids)) {
        $node_storage = $this->entityTypeManager->getStorage('node');
        $camp = $node_storage->load(reset($entity_ids));
      }
    }

    return $camp;
  }
public function getLandingPageCampNode ( NodeInterface $ node ) { $ camp = NULL ; // Exit if the node is not a landing page. if ( $ node -> bundle ( ) != 'landing_page' ) { return $ camp ; } // If the node has the Location field. if ( $ node -> hasField ( 'field_location' ) ) { if ( $ value = $ node -> field_location -> referencedEntities ( ) ) { // referencedEntities() returns an array of entities, since the location // field can only have a single value we reset to get that node object. $ camp = reset ( $ value ) ; } } // Else if a camp links to this landing page use the linking camp. else { // Need to get <front> path if set & is a node. $ front = $ this -> config -> get ( 'page.front' ) ; // To track if this node is the front page. $ is_front = FALSE ; // Setup to lookup all aliases for this node. $ langcode = $ node -> language ( ) -> getId ( ) ; $ system_path = '/node/' . $ node -> id ( ) ; // If the front is set to this node directly. $ is_front = ( $ front == $ system_path ) ? TRUE : $ is_front ; // Query 1 Camp nodes that link to this landing page. $ query = \ Drupal :: entityQuery ( 'node' ) ; $ group = $ query -> orConditionGroup ( ) -> condition ( 'field_camp_menu_links' , 'entity:node/' . $ node -> id ( ) ) -> condition ( 'field_camp_menu_links' , 'internal:' . $ system_path ) ; // Since the link field allows internal links we must check if this node's // aliases are linked also. if ( $ aliases = $ this -> lookupPathAliases ( $ system_path , $ langcode ) ) { foreach ( $ aliases as $ alias ) { $ group -> condition ( 'field_camp_menu_links' , 'internal:' . $ alias -> alias ) ; // Checking to see if the alias is the front page config value. $ is_front = ( $ front == $ alias -> alias ) ? TRUE : $ is_front ; } } // If this node is the front page we add the '/' path. This is how <front> // is represented in the link field storage. if ( $ is_front ) { $ group -> condition ( 'field_camp_menu_links' , 'internal:/' ) ; } $ query -> condition ( 'status' , 1 ) -> condition ( $ group ) -> range ( 0 , 1 ) ; $ entity_ids = $ query -> execute ( ) ; // If results returned. if ( ! empty ( $ entity_ids ) ) { $ node_storage = $ this -> entityTypeManager -> getStorage ( 'node' ) ; $ camp = $ node_storage -> load ( reset ( $ entity_ids ) ) ; } } return $ camp ; }
Retrieves the Camp CT associated to the landing page provided.

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

@return \Drupal\node\Entity\Node|mixed|null
The camp node or Null.
Retrieves the Camp CT associated to the landing page provided .