You are here

public static function FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  2. 8.7 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  3. 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  4. 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  5. 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  6. 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
  7. 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()

Update Group content after Group changed.

Parameters

\Drupal\group\Entity\Group $group: The Group we've updated.

array $changed_visibility: The Group's old visibility.

array $new_options: The Group's new visibility options.

Throws

\Drupal\Core\Entity\EntityStorageException

1 call to FlexibleGroupContentVisibilityUpdate::batchUpdateGroupContentVisibility()
_social_flexible_group_edit_submit in modules/social_features/social_group/modules/social_group_flexible_group/social_group_flexible_group.module
Custom form submit handler for editing a flexible group.

File

modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php, line 61

Class

FlexibleGroupContentVisibilityUpdate
Class FlexibleGroupContentVisibilityUpdate.

Namespace

Drupal\social_group_flexible_group

Code

public static function batchUpdateGroupContentVisibility(Group $group, array $changed_visibility, array $new_options) {

  // Set it up as a batch. We need to update visibility.
  // Load all the GroupContentEntities from Post to content.
  // Memberships don't need an update.
  $entities = $posts = [];
  $entities = $group
    ->getContentEntities();
  $posts = self::getPostsFromGroup($group);

  // Add posts to the entities we need to update based on visibility.
  if (!empty($posts)) {
    foreach ($posts as $pid => $post) {
      if (in_array($post
        ->getVisibility(), $changed_visibility, FALSE)) {
        $entities[] = $post;
      }
    }
  }
  $num_operations = count($entities);
  $operations = [];

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

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