You are here

class DeleteGroup in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  2. 8.2 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  3. 8.3 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  4. 8.4 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  5. 8.5 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  6. 8.6 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  7. 8.7 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  8. 8.8 modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  9. 10.3.x modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  10. 10.0.x modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  11. 10.1.x modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup
  12. 10.2.x modules/social_features/social_group/src/Controller/DeleteGroup.php \Drupal\social_group\Controller\DeleteGroup

Class DeleteGroup.

@package Drupal\social_group\Controller

Hierarchy

Expanded class hierarchy of DeleteGroup

File

modules/social_features/social_group/src/Controller/DeleteGroup.php, line 15

Namespace

Drupal\social_group\Controller
View source
class DeleteGroup {

  /**
   * Get the group and all of its content that needs to be deleted.
   */
  public static function deleteGroupAndContent($nids, $posts, &$context) {
    $results = [];

    // Load each node and delete it.
    foreach ($nids as $nid) {
      $node = Node::load($nid);
      $message = t('Delete @type "@title"', [
        '@type' => $node
          ->getType(),
        '@title' => $node
          ->getTitle(),
      ]);
      $results[] = $node
        ->delete();
    }

    // Load each post and delete it.
    foreach ($posts as $post_id) {
      $post = Post::load($post_id);
      $message = t("Deleting @type\\'s", [
        '@type' => $post
          ->bundle(),
      ]);
      $results[] = $post
        ->delete();
    }
    $context['message'] = $message;
    $context['results'] = $results;
  }

  /**
   * Callback when the batch for group and content deletion is done.
   */
  public function deleteGroupAndContentFinishedCallback($success, $results, $operations) {

    // The 'success' parameter means no fatal PHP errors were detected. All
    // other error management should be handled using 'results'.
    if ($success) {
      $message = \Drupal::translation()
        ->formatPlural(count($results), 'One item deleted.', '@count items deleted.');

      // Provide some feedback when its a success.
      drupal_set_message(t("Your group and all of it's topic's, event's and post's have been deleted."));

      // TODO: log to the database.
    }
    else {
      $message = t('There was an unexpected error.');
      drupal_set_message($message, 'error');
    }

    // Redirect the user back to their groups overview once the batch is done.
    return new RedirectResponse(Url::fromRoute('view.groups.page_user_groups')
      ->setRouteParameter('user', \Drupal::currentUser()
      ->id())
      ->toString());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeleteGroup::deleteGroupAndContent public static function Get the group and all of its content that needs to be deleted.
DeleteGroup::deleteGroupAndContentFinishedCallback public function Callback when the batch for group and content deletion is done.