public static function getLocations($locations_to_be_displayed = null) {
    $db = \Drupal::database();
    $branches_list = [
      'branch' => [],
      'camp' => [],
    ];
    $query = $db->select('node_field_data', 'n')
      ->fields('n', ['nid', 'title', 'type'])
      ->condition('type', ['branch', 'camp'], 'IN')
      ->condition('status', 1);
    $items = $query->execute()->fetchAll();
    foreach ($items as $item) {
      // By default we show all locations instead of showing empty popup.
      if (!empty($locations_to_be_displayed) && !in_array($item->nid, $locations_to_be_displayed)) {
        continue;
      }
      $branches_list[$item->type][$item->nid] = $item->title;
    }

    return $branches_list;
  }
public static function getLocations($locations_to_be_displayed = null) {
    $db = \Drupal::database();
    $branches_list = [
      'branch' => [],
      'camp' => [],
    ];
    $query = $db->select('node_field_data', 'n')
      ->fields('n', ['nid', 'title', 'type'])
      ->condition('type', ['branch', 'camp'], 'IN')
      ->condition('status', 1);
    $items = $query->execute()->fetchAll();
    foreach ($items as $item) {
      // By default we show all locations instead of showing empty popup.
      if (!empty($locations_to_be_displayed) && !in_array($item->nid, $locations_to_be_displayed)) {
        continue;
      }
      $branches_list[$item->type][$item->nid] = $item->title;
    }

    return $branches_list;
  }
public static function getLocations ( $ locations_to_be_displayed = null ) { $ db = \ Drupal :: database ( ) ; $ branches_list = [ 'branch' => [ ] , 'camp' => [ ] , ] ; $ query = $ db -> select ( 'node_field_data' , 'n' ) -> fields ( 'n' , [ 'nid' , 'title' , 'type' ] ) -> condition ( 'type' , [ 'branch' , 'camp' ] , 'IN' ) -> condition ( 'status' , 1 ) ; $ items = $ query -> execute ( ) -> fetchAll ( ) ; foreach ( $ items as $ item ) { // By default we show all locations instead of showing empty popup. if ( ! empty ( $ locations_to_be_displayed ) && ! in_array ( $ item -> nid , $ locations_to_be_displayed ) ) { continue ; } $ branches_list [ $ item -> type ] [ $ item -> nid ] = $ item -> title ; } return $ branches_list ; }
Get Locations list.
Get Locations list .