public function SocialGroupViewsBulkOperationsBulkForm::viewsForm in Open Social 8.8
Same name and namespace in other branches
- 8.9 modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 8.5 modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 8.6 modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 8.7 modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 10.3.x modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 10.0.x modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 10.1.x modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
- 10.2.x modules/social_features/social_group/src/Plugin/views/field/SocialGroupViewsBulkOperationsBulkForm.php \Drupal\social_group\Plugin\views\field\SocialGroupViewsBulkOperationsBulkForm::viewsForm()
File
- modules/
social_features/ social_group/ src/ Plugin/ views/ field/ SocialGroupViewsBulkOperationsBulkForm.php, line 68
Class
- SocialGroupViewsBulkOperationsBulkForm
- Defines the Groups Views Bulk Operations field plugin.
Namespace
Drupal\social_group\Plugin\views\fieldCode
public function viewsForm(array &$form, FormStateInterface $form_state) {
$this->view
->setExposedInput([
'status' => TRUE,
]);
parent::viewsForm($form, $form_state);
// Continue, if group members as a result on the manage members view.
if (empty($form['output'][0]['#rows']) || $this->view
->id() !== 'group_manage_members') {
return;
}
$group = _social_group_get_current_group();
$tempstoreData = $this
->getTempstoreData($this->view
->id(), $this->view->current_display);
// Make sure the selection is saved for the current group.
if (!empty($tempstoreData['group_id']) && $tempstoreData['group_id'] !== $group
->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 Group ID to the data.
$tempstoreData['group_id'] = $group
->id();
$this
->setTempstoreData($tempstoreData, $this->view
->id(), $this->view->current_display);
// Reorder the form array.
$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']];
// Styling related for the wrapper div.
$wrapper['#attributes']['class'][] = 'card';
$wrapper['#attributes']['class'][] = 'card__block';
// Add some JS for altering titles and switches.
$form['#attached']['library'][] = 'social_group/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';
}
/** @var \Drupal\Core\StringTranslation\TranslatableMarkup $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> Member</b> is selected', '<b><em class="placeholder">@count</em> Members</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 (!empty($tempstoreData['exclude_mode']) && $tempstoreData['exclude_mode']) {
$excluded = TRUE;
}
$wrapper['multipage']['list']['#title'] = !$excluded ? $this
->t('See selected members on other pages') : $this
->t('Members excluded on other pages:');
}
// Update the clear submit button.
if (!empty($wrapper['multipage']['clear'])) {
$wrapper['multipage']['clear']['#value'] = $this
->t('Clear selection on all pages');
$wrapper['multipage']['clear']['#attributes']['class'][] = 'btn-default dropdown-toggle waves-effect waves-btn margin-top-l margin-left-m';
}
// Add the group to the display id, so the ajax callback that is run
// will count and select across pages correctly.
if ($group) {
$wrapper['multipage']['#attributes']['data-group-id'] = $group
->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 . '/' . $group
->id();
}
}
// Actions are not a select list but a dropbutton list.
$actions =& $wrapper['actions'];
$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_group']['action']['#access'] = FALSE;
}