-
Notifications
You must be signed in to change notification settings - Fork 3
Added custom list builder class for webform submissions #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| 'access webform submission list bulk operations and actions': | ||
| title: 'Access webform submission list bulk operations and actions' | ||
| description: 'Access webform submission list bulk operations and actions' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| <?php | ||
|
|
||
| namespace Drupal\os2forms_webform_list; | ||
|
|
||
| use Drupal\Core\Entity\EntityInterface; | ||
| use Drupal\Core\Entity\EntityListBuilder; | ||
| use Drupal\webform\Utility\WebformDialogHelper; | ||
| use Drupal\webform\WebformSubmissionListBuilder; | ||
|
|
||
| /** | ||
| * Defines a class to build a listing of webform entities. | ||
| * | ||
| * @see \Drupal\webform\Entity\Webform | ||
| */ | ||
| class CustomWebformSubmissionListBuilder extends WebformSubmissionListBuilder { | ||
|
|
||
| /** | ||
| * Build the webform submission entity list. | ||
| * | ||
| * @return array | ||
| * A renderable array containing the entity list. | ||
| */ | ||
| protected function buildEntityList(): array { | ||
| $build = []; | ||
|
|
||
| // Filter form. | ||
| if (empty($this->account)) { | ||
| $build['filter_form'] = $this->buildFilterForm(); | ||
| } | ||
|
|
||
| // Customize buttons. | ||
| if ($this->customize) { | ||
| $build['customize'] = $this->buildCustomizeButton(); | ||
| } | ||
|
|
||
| // Display info. | ||
| if ($this->total) { | ||
| $build['info'] = $this->buildInfo(); | ||
| } | ||
|
|
||
| // Table. | ||
| $build += EntityListBuilder::render(); | ||
| $build['table']['#sticky'] = TRUE; | ||
| $build['table']['#attributes']['class'][] = 'webform-results-table'; | ||
|
|
||
| // Bulk operations only visible on webform submissions pages. | ||
| $webform_submission_bulk_form = $this->configFactory->get('webform.settings')->get('settings.webform_submission_bulk_form'); | ||
| if ($webform_submission_bulk_form | ||
| && !$this->account | ||
| && $this->webform | ||
| && $this->webform->access('submission_update_any') | ||
| && $this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { | ||
| $build['table'] = \Drupal::formBuilder()->getForm('\Drupal\webform\Form\WebformSubmissionBulkForm', $build['table'], $this->webform->access('submission_delete_any')); | ||
| } | ||
|
|
||
| // Must preload libraries required by (modal) dialogs. | ||
| // Must preload libraries required by (modal) dialogs. | ||
| WebformDialogHelper::attachLibraries($build); | ||
|
|
||
| return $build; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is lot of copy-paste from the parent class: WebformSubmissionListBuilder, but if my findings are correctn, then only thing added is the check for a new permission: condider removing the code duplication and depend as much as possible on the contrib code - in that way there is much less support in the future, should the contrib code change. This function can be simplified: |
||
|
|
||
| /** | ||
| * Add permissions check on operations. | ||
| * | ||
| * @return array | ||
| * A renderable array containing the entity list. | ||
| */ | ||
| public function getDefaultOperations(EntityInterface $entity): array { | ||
| if ($this->currentUser->hasPermission('access webform submission list bulk operations and actions')) { | ||
| return parent::getDefaultOperations($entity); | ||
| } | ||
| else { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again, instead of duplicating the code i would suggest to rely as much as possible on the contibuted code. |
||
| $webform = $entity->getWebform(); | ||
| $operations = []; | ||
|
|
||
| if ($entity->access('view')) { | ||
| $operations['view'] = [ | ||
| 'title' => $this->t('View'), | ||
| 'weight' => 20, | ||
| 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform.user.submission'), | ||
| ]; | ||
| } | ||
|
|
||
| if ($entity->access('view_any') | ||
| && $this->currentUser->hasPermission('access webform submission log') | ||
| && $webform->hasSubmissionLog() | ||
| && $this->moduleHandler->moduleExists('webform_submission_log')) { | ||
| $operations['log'] = [ | ||
| 'title' => $this->t('Log'), | ||
| 'weight' => 100, | ||
| 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform_submission.log'), | ||
| ]; | ||
| } | ||
|
|
||
| return $operations; | ||
| } | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't agree with the name here. The name should give a hint about a purpose of the class/file. Currently it only say that is customly made, which is obvious already.