Skip to content

Commit fe7a060

Browse files
committed
Added custom list builder class for webform submissions
1 parent 6e52ea4 commit fe7a060

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

modules/os2forms_webform_list/os2forms_webform_list.module

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ function os2forms_webform_list_entity_type_alter(array &$entity_types) {
1414
/** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */
1515
// Define a new list builder classes.
1616
$entity_types['webform']->setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformEntityListBuilder');
17+
$entity_types['webform_submission']->setListBuilderClass('Drupal\os2forms_webform_list\CustomWebformSubmissionListBuilder');
1718
$entity_types['maestro_template']->setListBuilderClass('Drupal\os2forms_webform_list\CustomMaestroTemplateEntityListBuilder');
1819
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
'access webform submission list bulk operations and actions':
2+
title: 'Access webform submission list bulk operations and actions'
3+
description: 'Access webform submission list bulk operations and actions'
4+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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

Comments
 (0)