public static function getPostsFromGroup(Group $group) {
    $posts = &drupal_static(__FUNCTION__);
    if (!isset($posts)) {
      // Posts aren't marked as group content so we load them separately.
      $query = \Drupal::database()->select('post__field_recipient_group', 'pst');
      $query->addField('pst', 'entity_id');
      $query->condition('pst.field_recipient_group_target_id', $group->id());
      $query->execute()->fetchAll();

      $post_keys = $query->execute()->fetchAllAssoc('entity_id');

      // Store all the post entity ids.
      $post_ids = array_keys($post_keys);

      $posts = Post::loadMultiple($post_ids);
    }

    return $posts;
  }
public static function getPostsFromGroup(Group $group) {
    $posts = &drupal_static(__FUNCTION__);
    if (!isset($posts)) {
      // Posts aren't marked as group content so we load them separately.
      $query = \Drupal::database()->select('post__field_recipient_group', 'pst');
      $query->addField('pst', 'entity_id');
      $query->condition('pst.field_recipient_group_target_id', $group->id());
      $query->execute()->fetchAll();

      $post_keys = $query->execute()->fetchAllAssoc('entity_id');

      // Store all the post entity ids.
      $post_ids = array_keys($post_keys);

      $posts = Post::loadMultiple($post_ids);
    }

    return $posts;
  }
public static function getPostsFromGroup ( Group $ group ) { $ posts = & drupal_static ( __FUNCTION__ ) ; if ( ! isset ( $ posts ) ) { // Posts aren't marked as group content so we load them separately. $ query = \ Drupal :: database ( ) -> select ( 'post__field_recipient_group' , 'pst' ) ; $ query -> addField ( 'pst' , 'entity_id' ) ; $ query -> condition ( 'pst.field_recipient_group_target_id' , $ group -> id ( ) ) ; $ query -> execute ( ) -> fetchAll ( ) ; $ post_keys = $ query -> execute ( ) -> fetchAllAssoc ( 'entity_id' ) ; // Store all the post entity ids. $ post_ids = array_keys ( $ post_keys ) ; $ posts = Post :: loadMultiple ( $ post_ids ) ; } return $ posts ; }
Load all Posts based on a certain group.

@param \Drupal\group\Entity\Group $group
The Group where we should check our posts for.

@return \Drupal\Core\Entity\EntityInterface[]|\Drupal\social_post\Entity\Post[]
Returning the Posts that are part of a Group.
Load all Posts based on a certain group .