You are here

public function ExportUserConfirm::buildForm in Open Social 8

Same name and namespace in other branches
  1. 8.2 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm::buildForm()
  2. 8.3 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm::buildForm()
  3. 8.4 modules/social_features/social_user_export/src/Form/ExportUserConfirm.php \Drupal\social_user_export\Form\ExportUserConfirm::buildForm()

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides ConfirmFormBase::buildForm

File

modules/social_features/social_user_export/src/Form/ExportUserConfirm.php, line 100

Class

ExportUserConfirm
Class ExportUserConfirm.

Namespace

Drupal\social_user_export\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // Retrieve the data to be exported from the temp store.
  $data = $this->tempStoreFactory
    ->get('user_operations_export')
    ->get($this
    ->currentUser()
    ->id());
  if (!$data) {
    return $this
      ->redirect('entity.user.collection');
  }
  $export_params = [
    'apply_all' => !empty($data['apply_all']),
    'accounts' => [],
    'query' => [],
  ];

  // If not selected all items, show list of selected items,
  // else show quantity of all items.
  if (empty($data['apply_all'])) {
    $form['accounts'] = [
      '#prefix' => '<ul>',
      '#suffix' => '</ul>',
      '#tree' => TRUE,
    ];
    foreach ($data['entities'] as $account) {
      $export_params['accounts'][] = $account
        ->id();
      $form['accounts'][] = [
        '#type' => 'markup',
        '#markup' => '<li>' . $account
          ->getDisplayName() . '</li>',
      ];
    }
  }
  else {
    if (empty($data['query'])) {
      $data['query'] = [];
    }
    $export_params['query'] = $data['query'];
    $view = _social_user_export_get_view($data['query']);
    $form['message'] = [
      '#type' => 'item',
      '#markup' => t('@count users will be exported', [
        '@count' => $view->total_rows,
      ]),
    ];
  }
  $form_state
    ->set('export_params', $export_params);
  $form = parent::buildForm($form, $form_state);
  return $form;
}