public function updateVisibility($entity, $new_type, array &$context) {
    // Find the corresponding visibility for the new group_type.
    $default_visibility = SocialGroupHelperService::getDefaultGroupVisibility($new_type);

    // Store some results for post-processing in the 'finished' callback.
    // The contents of 'results' will be available as $results in the
    // 'finished' function updateVisibilityFinishedCallback().
    if ($entity instanceof Post) {
      $entity->setVisibility($default_visibility);
      $entity->save();
    }
    if ($entity instanceof Node) {
      $entity->set('field_content_visibility', $default_visibility);
      $entity->save();
    }
    // For GroupMembers we have to update the GroupContent.
    if ($entity instanceof GroupMembership) {
      $new_group_type = $new_type . '-group_membership';
      $membershipEntity = $entity->getGroupContent();
      $membershipEntity->set('type', $new_group_type);
      $membershipEntity->save();
      $entity = $membershipEntity;
    }

    // Make sure our GroupContent referenced entities also get invalidated.
    $tags = $entity->getCacheTagsToInvalidate();
    Cache::invalidateTags($tags);

    // Add referenced entity to results. Might want to add it to the result.
    $context['results'][] = $entity;

    // Optional message displayed under the progressbar.
    $context['message'] = t('Updating group content (@id)', ['@id' => $entity->id()]);
  }
public function updateVisibility($entity, $new_type, array &$context) {
    // Find the corresponding visibility for the new group_type.
    $default_visibility = SocialGroupHelperService::getDefaultGroupVisibility($new_type);

    // Store some results for post-processing in the 'finished' callback.
    // The contents of 'results' will be available as $results in the
    // 'finished' function updateVisibilityFinishedCallback().
    if ($entity instanceof Post) {
      $entity->setVisibility($default_visibility);
      $entity->save();
    }
    if ($entity instanceof Node) {
      $entity->set('field_content_visibility', $default_visibility);
      $entity->save();
    }
    // For GroupMembers we have to update the GroupContent.
    if ($entity instanceof GroupMembership) {
      $new_group_type = $new_type . '-group_membership';
      $membershipEntity = $entity->getGroupContent();
      $membershipEntity->set('type', $new_group_type);
      $membershipEntity->save();
      $entity = $membershipEntity;
    }

    // Make sure our GroupContent referenced entities also get invalidated.
    $tags = $entity->getCacheTagsToInvalidate();
    Cache::invalidateTags($tags);

    // Add referenced entity to results. Might want to add it to the result.
    $context['results'][] = $entity;

    // Optional message displayed under the progressbar.
    $context['message'] = t('Updating group content (@id)', ['@id' => $entity->id()]);
  }
public function updateVisibility ( $ entity , $ new_type , array & $ context ) { // Find the corresponding visibility for the new group_type. $ default_visibility = SocialGroupHelperService :: getDefaultGroupVisibility ( $ new_type ) ; // Store some results for post-processing in the 'finished' callback. // The contents of 'results' will be available as $results in the // 'finished' function updateVisibilityFinishedCallback(). if ( $ entity instanceof Post ) { $ entity -> setVisibility ( $ default_visibility ) ; $ entity -> save ( ) ; } if ( $ entity instanceof Node ) { $ entity -> set ( 'field_content_visibility' , $ default_visibility ) ; $ entity -> save ( ) ; } // For GroupMembers we have to update the GroupContent. if ( $ entity instanceof GroupMembership ) { $ new_group_type = $ new_type . '-group_membership' ; $ membershipEntity = $ entity -> getGroupContent ( ) ; $ membershipEntity -> set ( 'type' , $ new_group_type ) ; $ membershipEntity -> save ( ) ; $ entity = $ membershipEntity ; } // Make sure our GroupContent referenced entities also get invalidated. $ tags = $ entity -> getCacheTagsToInvalidate ( ) ; Cache :: invalidateTags ( $ tags ) ; // Add referenced entity to results. Might want to add it to the result. $ context [ 'results' ] [ ] = $ entity ; // Optional message displayed under the progressbar. $ context [ 'message' ] = t ( 'Updating group content (@id)' , [ '@id' => $ entity -> id ( ) ] ) ; }
Update visibility for all Group Content based on a new group type.

@param \Drupal\node\Entity\Node|\Drupal\social_post\Entity\Post|\Drupal\group\GroupMembership|\Drupal\group\Entity\GroupContentInterface $entity
The content we are updating.
@param string $new_type
The new Group type.
@param array $context
Passed on by reference.

@throws \Drupal\Core\Entity\EntityStorageException
Update visibility for all Group Content based on a new group type .