You are here

public function SocialEventManagersViewsBulkOperationsBulkForm::viewsForm in Open Social 10.3.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  2. 8.5 modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  3. 8.6 modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  4. 8.7 modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  5. 8.8 modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  6. 10.0.x modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  7. 10.1.x modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()
  8. 10.2.x modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php \Drupal\social_event_managers\Plugin\views\field\SocialEventManagersViewsBulkOperationsBulkForm::viewsForm()

Form constructor for the bulk form.

Parameters

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

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

Overrides ViewsBulkOperationsBulkForm::viewsForm

File

modules/social_features/social_event/modules/social_event_managers/src/Plugin/views/field/SocialEventManagersViewsBulkOperationsBulkForm.php, line 124

Class

SocialEventManagersViewsBulkOperationsBulkForm
Defines the Enrollments Views Bulk Operations field plugin.

Namespace

Drupal\social_event_managers\Plugin\views\field

Code

public function viewsForm(array &$form, FormStateInterface $form_state) {
  $this->view
    ->setExposedInput([
    'status' => TRUE,
  ]);
  parent::viewsForm($form, $form_state);
  if ($this->view
    ->id() !== 'event_manage_enrollments') {
    return;
  }
  $action_options = $this
    ->getBulkOptions();
  if (!empty($this->view->result) && !empty($action_options)) {
    $list =& $form[$this->options['id']];
    foreach ($this->view->result as $row_index => $row) {
      $entity = $this
        ->getEntity($row);
      $list[$row_index]['#title'] = $this
        ->getEntityLabel($entity);
    }
  }
  $event = social_event_get_current_event();
  if (!$event) {
    return;
  }
  $tempstoreData = $this
    ->getTempstoreData($this->view
    ->id(), $this->view->current_display);

  // Make sure the selection is saved for the current event.
  if (!empty($tempstoreData['event_id']) && $tempstoreData['event_id'] !== $event
    ->id()) {

    // If not we clear it right away.
    // Since we don't want to mess with cached date.
    $this
      ->deleteTempstoreData($this->view
      ->id(), $this->view->current_display);

    // Reset initial values.
    $this
      ->updateTempstoreData();

    // Initialize it again.
    $tempstoreData = $this
      ->getTempstoreData($this->view
      ->id(), $this->view->current_display);
  }

  // Add the Event ID to the data.
  $tempstoreData['event_id'] = $event
    ->id();
  $this
    ->setTempstoreData($tempstoreData, $this->view
    ->id(), $this->view->current_display);

  // Reorder the form array.
  if (!empty($form['header'])) {
    $multipage = $form['header'][$this->options['id']]['multipage'];
    unset($form['header'][$this->options['id']]['multipage']);
    $form['header'][$this->options['id']]['multipage'] = $multipage;
  }

  // Render proper classes for the header in VBO form.
  $wrapper =& $form['header'][$this->options['id']];
  if (!empty($event
    ->id())) {
    $wrapper['multipage']['#attributes']['event-id'] = $event
      ->id();
    if (!empty($wrapper['multipage']['#attributes']['data-display-id'])) {
      $current_display = $wrapper['multipage']['#attributes']['data-display-id'];
      $wrapper['multipage']['#attributes']['data-display-id'] = $current_display . '/' . $event
        ->id();
    }
  }

  // Styling related for the wrapper div.
  $wrapper['#attributes']['class'][] = 'card';
  $wrapper['#attributes']['class'][] = 'card__block';
  $form['#attached']['library'][] = 'social_event_managers/views_bulk_operations.frontUi';

  // Render select all results checkbox.
  if (!empty($wrapper['select_all'])) {
    $wrapper['select_all']['#title'] = $this
      ->t('Select / unselect all @count members across all the pages', [
      '@count' => $this->tempStoreData['total_results'] ? ' ' . $this->tempStoreData['total_results'] : '',
    ]);

    // Styling attributes for the select box.
    $form['header'][$this->options['id']]['select_all']['#attributes']['class'][] = 'form-no-label';
    $form['header'][$this->options['id']]['select_all']['#attributes']['class'][] = 'checkbox';
  }
  $count = 0;

  /** @var \Drupal\Core\StringTranslation\TranslatableMarkup $title */
  if (!empty($wrapper['multipage']) && !empty($wrapper['multipage']['#title'])) {
    $title = $wrapper['multipage']['#title'];
    $arguments = $title
      ->getArguments();
    $count = empty($arguments['%count']) ? 0 : $arguments['%count'];
  }
  $title = $this
    ->formatPlural($count, '<b><em class="placeholder">@count</em> enrollee</b> is selected', '<b><em class="placeholder">@count</em> enrollees</b> are selected');
  $wrapper['multipage']['#title'] = [
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => $title,
  ];

  // Add selector so the JS of VBO applies correctly.
  $wrapper['multipage']['#attributes']['class'][] = 'vbo-multipage-selector';

  // Get tempstore data so we know what messages to show based on the data.
  $tempstoreData = $this
    ->getTempstoreData($this->view
    ->id(), $this->view->current_display);
  if (!empty($wrapper['multipage']['list']['#items']) && count($wrapper['multipage']['list']['#items']) > 0) {
    $excluded = FALSE;
    if (isset($tempstoreData['exclude_mode']) && $tempstoreData['exclude_mode']) {
      $excluded = TRUE;
    }
    $wrapper['multipage']['list']['#title'] = !$excluded ? $this
      ->t('See selected enrollees on other pages') : $this
      ->t('See excluded enrollees on other pages');
  }

  // Update the clear submit button.
  if (!empty($wrapper['multipage']['clear'])) {
    $wrapper['multipage']['clear']['#value'] = $this
      ->t('Clear all selected enrollees');
    $wrapper['multipage']['clear']['#attributes']['class'][] = 'btn-default dropdown-toggle waves-effect waves-btn margin-top-l margin-left-m';
  }
  $actions =& $wrapper['actions'];
  if (!empty($actions) && !empty($wrapper['action'])) {
    $actions['#theme'] = 'links__dropbutton__operations__actions';
    $actions['#label'] = $this
      ->t('Actions');
    $actions['#type'] = 'dropbutton';
    $items = [];
    foreach ($wrapper['action']['#options'] as $key => $value) {
      if (!empty($key) && array_key_exists($key, $this->bulkOptions)) {
        $items[] = [
          '#type' => 'submit',
          '#value' => $value,
        ];
      }
    }

    // Add our links to the dropdown buttondrop type.
    $actions['#links'] = $items;
  }

  // Remove the Views select list and submit button.
  $form['actions']['#type'] = 'hidden';
  $form['header']['social_views_bulk_operations_bulk_form_enrollments_1']['action']['#access'] = FALSE;
}