You are here

public function FlexibleGroupContentVisibilityUpdate::updateVisibility in Open Social 8.7

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::updateVisibility()
  2. 8.6 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()
  3. 8.8 modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()
  4. 10.3.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()
  5. 10.0.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()
  6. 10.1.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()
  7. 10.2.x modules/social_features/social_group/modules/social_group_flexible_group/src/FlexibleGroupContentVisibilityUpdate.php \Drupal\social_group_flexible_group\FlexibleGroupContentVisibilityUpdate::updateVisibility()

Update visibility for all Group Content based on a new group type.

Parameters

\Drupal\node\Entity\Node|\Drupal\social_post\Entity\Post|\Drupal\group\GroupMembership|\Drupal\group\Entity\GroupContentInterface $entity: The content we are updating.

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

array $context: Passed on by reference.

Throws

\Drupal\Core\Entity\EntityStorageException

File

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

Class

FlexibleGroupContentVisibilityUpdate
Class FlexibleGroupContentVisibilityUpdate.

Namespace

Drupal\social_group_flexible_group

Code

public function updateVisibility($entity, array $new_options, array &$context) {

  // 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) {
    $default_visibility = self::calculateVisibility($entity
      ->getVisibility(), $new_options);
    $entity
      ->setVisibility($default_visibility);
    $entity
      ->save();
  }
  if ($entity instanceof Node) {
    $default_visibility = self::calculateVisibility($entity
      ->getFieldValue('field_content_visibility', 'value'), $new_options);
    $entity
      ->set('field_content_visibility', $default_visibility);
    $entity
      ->save();
  }

  // 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(),
  ]);
}