You are here

public function SocialCoreController::updateSelection in Open Social 10.0.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()
  2. 8.7 modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()
  3. 8.8 modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()
  4. 10.3.x modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()
  5. 10.1.x modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()
  6. 10.2.x modules/social_features/social_core/src/Controller/SocialCoreController.php \Drupal\social_core\Controller\SocialCoreController::updateSelection()

AJAX callback to update selection (multipage).

Parameters

string $view_id: The current view ID.

string $display_id: The display ID of the current view.

\Symfony\Component\HttpFoundation\Request $request: The request object.

File

modules/social_features/social_core/src/Controller/SocialCoreController.php, line 93

Class

SocialCoreController
Returns responses for social_core module routes.

Namespace

Drupal\social_core\Controller

Code

public function updateSelection($view_id, $display_id, Request $request) {
  $view_data = $this
    ->getTempstoreData($view_id, $display_id);
  if (empty($view_data)) {
    throw new NotFoundHttpException();
  }

  // If the group id doesn't match.
  // We reset the selection and update the group.
  if ($view_id === 'group_manage_members') {
    $group_id = $request->attributes
      ->get('group');
    if (!empty($group_id) && !empty($view_data['group_id'])) {
      if ($group_id !== $view_data['group_id']) {
        $view_data['list'] = [];
        $view_data['group_id'] = $group_id;
        $view_data['total_results'] = 0;
      }
    }
  }

  // If the event id doesn't match.
  // We reset the selection and update the group.
  if ($view_id === 'event_manage_enrollments') {

    // Get's overridden by GVBO in to the group argument.
    $event_id = $request->attributes
      ->get('group');
    if (!empty($event_id) && !empty($view_data['event_id'])) {
      if ($event_id !== $view_data['event_id']) {
        $view_data['list'] = [];
        $view_data['event_id'] = $event_id;
        $view_data['total_results'] = 0;
      }
    }
  }

  // All borrowed from ViewsBulkOperationsController.php.
  $list = $request->request
    ->get('list');
  $op = $request->request
    ->get('op', 'check');

  // Reverse operation when in exclude mode.
  if (!empty($view_data['exclude_mode'])) {
    if ($op === 'add') {
      $op = 'remove';
    }
    elseif ($op === 'remove') {
      $op = 'add';
    }
  }
  switch ($op) {
    case 'add':
      foreach ($list as $bulkFormKey) {
        if (!isset($view_data['list'][$bulkFormKey])) {
          $view_data['list'][$bulkFormKey] = $this
            ->getListItem($bulkFormKey);
        }
      }
      break;
    case 'remove':
      foreach ($list as $bulkFormKey) {
        if (isset($view_data['list'][$bulkFormKey])) {
          unset($view_data['list'][$bulkFormKey]);
        }
      }
      break;
    case 'method_include':
      unset($view_data['exclude_mode']);
      $view_data['list'] = [];
      break;
    case 'method_exclude':
      $view_data['exclude_mode'] = TRUE;
      $view_data['list'] = [];
      break;
  }
  $this
    ->setTempstoreData($view_data);
  $count = empty($view_data['exclude_mode']) ? count($view_data['list']) : $view_data['total_results'] - count($view_data['list']);
  $response = new AjaxResponse();
  $response
    ->setData([
    'count' => $count,
  ]);
  return $response;
}