Last active
November 17, 2022 06:43
-
-
Save junaidpv/16d84c549edeaf817b1a19428fea1af4 to your computer and use it in GitHub Desktop.
Patch for the webform module to integrate wtih the core ban module to block the IP address of a submission.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/src/WebformSubmissionListBuilder.php b/src/WebformSubmissionListBuilder.php | |
| index b684647ec..48cc91c43 100644 | |
| --- a/src/WebformSubmissionListBuilder.php | |
| +++ b/src/WebformSubmissionListBuilder.php | |
| @@ -1114,6 +1114,19 @@ class WebformSubmissionListBuilder extends EntityListBuilder { | |
| 'url' => $this->requestHandler->getUrl($entity, $this->sourceEntity, 'webform_submission.log'), | |
| ]; | |
| } | |
| + | |
| + if ($this->moduleHandler()->moduleExists('ban') && $this->currentUser->hasPermission('ban IP addresses')) { | |
| + /** @var \Drupal\ban\BanIpManager */ | |
| + $ban_ip_manager = \Drupal::service('ban.ip_manager'); | |
| + if (!$ban_ip_manager->isBanned($entity->getRemoteAddr())) { | |
| + $operations['block'] = [ | |
| + 'title' => $this->t('Block IP Address'), | |
| + 'weight' => 100, | |
| + 'url' => Url::fromRoute('ban.admin_page', ['default_ip' => $entity->getRemoteAddr()]), | |
| + 'attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW), | |
| + ]; | |
| + } | |
| + } | |
| } | |
| // Add destination to all operation links. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment