You are here

function _social_group_delete_group in Open Social 8.9

Same name and namespace in other branches
  1. 8.4 modules/social_features/social_group/social_group.module \_social_group_delete_group()
  2. 8.5 modules/social_features/social_group/social_group.module \_social_group_delete_group()
  3. 8.6 modules/social_features/social_group/social_group.module \_social_group_delete_group()
  4. 8.7 modules/social_features/social_group/social_group.module \_social_group_delete_group()
  5. 8.8 modules/social_features/social_group/social_group.module \_social_group_delete_group()
  6. 10.3.x modules/social_features/social_group/social_group.module \_social_group_delete_group()
  7. 10.0.x modules/social_features/social_group/social_group.module \_social_group_delete_group()
  8. 10.1.x modules/social_features/social_group/social_group.module \_social_group_delete_group()
  9. 10.2.x modules/social_features/social_group/social_group.module \_social_group_delete_group()

Delete the group and all of its content.

1 string reference to '_social_group_delete_group'
social_group_form_alter in modules/social_features/social_group/social_group.module
Implements hook_form_alter().

File

modules/social_features/social_group/social_group.module, line 1502
The Social group module.

Code

function _social_group_delete_group() {

  // Get the group.
  if ($group = _social_group_get_current_group()) {
    $group_content_types = GroupContentType::loadByEntityTypeId('node');
    $group_content_types = array_keys($group_content_types);

    // Get all the node's related to the current group.
    $query = \Drupal::database()
      ->select('group_content_field_data', 'gcfd');
    $query
      ->addField('gcfd', 'entity_id');
    $query
      ->condition('gcfd.gid', $group
      ->id());
    $query
      ->condition('gcfd.type', $group_content_types, 'IN');
    $query
      ->execute()
      ->fetchAll();
    $entity_ids = $query
      ->execute()
      ->fetchAllAssoc('entity_id');

    // Store all the node ids.
    $nids = array_keys($entity_ids);

    // Get all the posts from this group.
    $query = \Drupal::database()
      ->select('post__field_recipient_group', 'pfrg');
    $query
      ->addField('pfrg', 'entity_id');
    $query
      ->condition('pfrg.field_recipient_group_target_id', $group
      ->id());
    $query
      ->execute()
      ->fetchAll();
    $post_ids = $query
      ->execute()
      ->fetchAllAssoc('entity_id');

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

    // Pass the $nids and $posts as 2 parameters in the operations.
    // See /social_group/src/Controller/DeleteGroup.php for further process.
    $batch = [
      'title' => t('Deleting the group and all the content within the group...'),
      'init_message' => t("Preparing to delete the group and all it's topic's, event's and post's..."),
      'operations' => [
        [
          '\\Drupal\\social_group\\Controller\\DeleteGroup::deleteGroupAndContent',
          [
            $nids,
            $posts,
          ],
        ],
      ],
      'finished' => '\\Drupal\\social_group\\Controller\\DeleteGroup::deleteGroupAndContentFinishedCallback',
    ];
    batch_set($batch);
  }
}