You are here

function social_user_export_form_alter in Open Social 8.3

Same name and namespace in other branches
  1. 8 modules/social_features/social_user_export/social_user_export.module \social_user_export_form_alter()
  2. 8.2 modules/social_features/social_user_export/social_user_export.module \social_user_export_form_alter()
  3. 8.4 modules/social_features/social_user_export/social_user_export.module \social_user_export_form_alter()

Implements hook_form_alter().

File

modules/social_features/social_user_export/social_user_export.module, line 14
The Social User Export module.

Code

function social_user_export_form_alter(&$form, FormStateInterface $form_state, $form_id) {
  switch ($form_id) {
    case 'views_form_user_admin_people_page_1':

      // Fetch the amount of rows directly from the already executed view.
      $count = $form['output'][0]['#view']->total_rows;
      $form_state
        ->set('query', \Drupal::request()->query
        ->all());
      $form['#attached']['library'][] = 'social_user_export/select_all';
      $form['#attached']['drupalSettings']['socialUserExport'] = [
        'usersCount' => $count,
      ];
      $form['select_all'] = [
        '#type' => 'hidden',
        '#attributes' => [
          'id' => 'select-all',
        ],
      ];
      break;
    case 'views_exposed_form':
      $view = $form_state
        ->get('view');
      if ($view
        ->id() == 'user_admin_people' && ($view->current_display = 'page_1')) {
        $form['created']['min']['#type'] = 'date';
        $form['created']['min']['#title'] = t('Registered from');
        $form['created']['max']['#type'] = 'date';
        $form['created']['max']['#title'] = t('Registered to');
        if (isset($form['group']) && ($items = _social_user_export_get_groups())) {
          $form['group'] = array_merge($form['group'], [
            '#type' => 'select',
            '#options' => $items,
            '#empty_option' => t('- Any -'),
            '#size' => 1,
          ]);
        }
      }
      break;
  }
}