|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Drupal\os2forms_webform_list; |
| 4 | + |
| 5 | +use Drupal\Core\Entity\EntityInterface; |
| 6 | +use Drupal\Core\Entity\EntityListBuilder; |
| 7 | +use Drupal\webform\Utility\WebformDialogHelper; |
| 8 | +use Drupal\webform\WebformSubmissionListBuilder; |
| 9 | + |
| 10 | +/** |
| 11 | + * Defines a class to build a listing of webform entities. |
| 12 | + * |
| 13 | + * @see \Drupal\webform\Entity\Webform |
| 14 | + */ |
| 15 | +class CustomWebformSubmissionListBuilder extends WebformSubmissionListBuilder { |
| 16 | + |
| 17 | + /** |
| 18 | + * Build the webform submission entity list. |
| 19 | + * |
| 20 | + * @return array |
| 21 | + * A renderable array containing the entity list. |
| 22 | + */ |
| 23 | + protected function buildEntityList(): array { |
| 24 | + $build = []; |
| 25 | + |
| 26 | + // Filter form. |
| 27 | + if (empty($this->account)) { |
| 28 | + $build['filter_form'] = $this->buildFilterForm(); |
| 29 | + } |
| 30 | + |
| 31 | + // Customize buttons. |
| 32 | + if ($this->customize) { |
| 33 | + $build['customize'] = $this->buildCustomizeButton(); |
| 34 | + } |
| 35 | + |
| 36 | + // Display info. |
| 37 | + if ($this->total) { |
| 38 | + $build['info'] = $this->buildInfo(); |
| 39 | + } |
| 40 | + |
| 41 | + // Table. |
| 42 | + $build += EntityListBuilder::render(); |
| 43 | + $build['table']['#sticky'] = TRUE; |
| 44 | + $build['table']['#attributes']['class'][] = 'webform-results-table'; |
| 45 | + |
| 46 | + // Bulk operations only visible on webform submissions pages. |
| 47 | + $webform_submission_bulk_form = $this->configFactory->get('webform.settings')->get('settings.webform_submission_bulk_form'); |
| 48 | + if ($webform_submission_bulk_form |
| 49 | + && !$this->account |
| 50 | + && $this->webform |
| 51 | + && $this->webform->access('submission_update_any') |
| 52 | + && $this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { |
| 53 | + $build['table'] = \Drupal::formBuilder()->getForm('\Drupal\webform\Form\WebformSubmissionBulkForm', $build['table'], $this->webform->access('submission_delete_any')); |
| 54 | + } |
| 55 | + |
| 56 | + // Must preload libraries required by (modal) dialogs. |
| 57 | + // Must preload libraries required by (modal) dialogs. |
| 58 | + WebformDialogHelper::attachLibraries($build); |
| 59 | + |
| 60 | + return $build; |
| 61 | + } |
| 62 | + |
| 63 | + public function getDefaultOperations(EntityInterface $entity): array { |
| 64 | + if ($this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { |
| 65 | + return parent::getDefaultOperations($entity); |
| 66 | + } |
| 67 | + else { |
| 68 | + $webform = $entity->getWebform(); |
| 69 | + $operations = []; |
| 70 | + |
| 71 | + if ($entity->access('view')) { |
| 72 | + $operations[ 'view' ] = [ |
| 73 | + 'title' => $this->t('View'), |
| 74 | + 'weight' => 20, |
| 75 | + 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform.user.submission'), |
| 76 | + ]; |
| 77 | + } |
| 78 | + |
| 79 | + if ($entity->access('view_any') |
| 80 | + && $this->currentUser->hasPermission('access webform submission log') |
| 81 | + && $webform->hasSubmissionLog() |
| 82 | + && $this->moduleHandler->moduleExists('webform_submission_log')) { |
| 83 | + $operations[ 'log' ] = [ |
| 84 | + 'title' => $this->t('Log'), |
| 85 | + 'weight' => 100, |
| 86 | + 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform_submission.log'), |
| 87 | + ]; |
| 88 | + } |
| 89 | + |
| 90 | + return $operations; |
| 91 | + } |
| 92 | + } |
| 93 | +} |
0 commit comments