public static function batchUpdateGroupContentVisibility(Group $group, $new_type) {
    // Set it up as a batch. We need to update visibility.
    // Load all the GroupContentEntities from Post to Memberships to content.
    $entities = $group->getContentEntities();

    $posts = self::getPostsFromGroup($group);
    foreach ($posts as $pid => $post) {
      $entities[] = $post;
    }
    $memberships = $group->getMembers();
    foreach ($memberships as $member) {
      $entities[] = $member;
    }

    $num_operations = count($entities);
    $operations = [];

    // Update Memberships & ContentVisibility.
    // As per documentation each entity has it's own operation.
    for ($i = 0; $i < $num_operations; $i++) {
      $operations[] = [
        '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibility',
        [
          $entities[$i],
          $new_type,
        ],
      ];
    }

    // Provide all the operations and the finish callback to our batch.
    $batch = [
      'title' => t('Updating Group Content...'),
      'operations' => $operations,
      'finished' => '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibilityFinishedCallback',
    ];

    batch_set($batch);

    $group->set('type', $new_type);
    $group->save();
  }
public static function batchUpdateGroupContentVisibility(Group $group, $new_type) {
    // Set it up as a batch. We need to update visibility.
    // Load all the GroupContentEntities from Post to Memberships to content.
    $entities = $group->getContentEntities();

    $posts = self::getPostsFromGroup($group);
    foreach ($posts as $pid => $post) {
      $entities[] = $post;
    }
    $memberships = $group->getMembers();
    foreach ($memberships as $member) {
      $entities[] = $member;
    }

    $num_operations = count($entities);
    $operations = [];

    // Update Memberships & ContentVisibility.
    // As per documentation each entity has it's own operation.
    for ($i = 0; $i < $num_operations; $i++) {
      $operations[] = [
        '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibility',
        [
          $entities[$i],
          $new_type,
        ],
      ];
    }

    // Provide all the operations and the finish callback to our batch.
    $batch = [
      'title' => t('Updating Group Content...'),
      'operations' => $operations,
      'finished' => '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibilityFinishedCallback',
    ];

    batch_set($batch);

    $group->set('type', $new_type);
    $group->save();
  }
public static function batchUpdateGroupContentVisibility ( Group $ group , $ new_type ) { // Set it up as a batch. We need to update visibility. // Load all the GroupContentEntities from Post to Memberships to content. $ entities = $ group -> getContentEntities ( ) ; $ posts = self :: getPostsFromGroup ( $ group ) ; foreach ( $ posts as $ pid => $ post ) { $ entities [ ] = $ post ; } $ memberships = $ group -> getMembers ( ) ; foreach ( $ memberships as $ member ) { $ entities [ ] = $ member ; } $ num_operations = count ( $ entities ) ; $ operations = [ ] ; // Update Memberships & ContentVisibility. // As per documentation each entity has it's own operation. for ( $ i = 0 ; $ i < $ num_operations ; $ i ++ ) { $ operations [ ] = [ '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibility' , [ $ entities [ $ i ] , $ new_type , ] , ] ; } // Provide all the operations and the finish callback to our batch. $ batch = [ 'title' => t ( 'Updating Group Content...' ) , 'operations' => $ operations , 'finished' => '\Drupal\social_group\GroupContentVisibilityUpdate::updateVisibilityFinishedCallback' , ] ; batch_set ( $ batch ) ; $ group -> set ( 'type' , $ new_type ) ; $ group -> save ( ) ; }
Update Group content after Group changed.

@param \Drupal\group\Entity\Group $group
The Group we've updated.
@param string $new_type
The Group's new group type.

@throws \Drupal\Core\Entity\EntityStorageException
Update Group content after Group changed .