Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
honeypot-3028981
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
honeypot-3028981
Commits
e42d70aa
Commit
e42d70aa
authored
4 months ago
by
Tim Rohaly
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3028981
by TR, PtrTon: Allow custom conditionals for skipping Honeypot validation
parent
360d1345
No related branches found
Branches containing commit
Tags
5.x-1.8
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
honeypot.api.php
+22
-0
22 additions, 0 deletions
honeypot.api.php
src/HoneypotService.php
+10
-0
10 additions, 0 deletions
src/HoneypotService.php
with
32 additions
and
0 deletions
honeypot.api.php
+
22
−
0
View file @
e42d70aa
...
...
@@ -5,6 +5,8 @@
* API Functionality for Honeypot module.
*/
use
Drupal\Core\Form\FormStateInterface
;
/**
* @addtogroup hooks
* @{
...
...
@@ -95,6 +97,26 @@ function hook_honeypot_time_limit($honeypot_time_limit, array $form_values, $num
return
$additions
;
}
/**
* Determines if honeypot validation should be skipped.
*
* In some cases it can be useful to skip honeypot validation.
* For instance if a certain IP should be allowed to run automated scripts.
*
* @param array $element
* The element triggering the validation
* This will be either the honeypot or time restriction element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The Drupal form state.
*
* @return bool
* FALSE if validation should be skipped, TRUE to proceed as usual.
*/
function
hook_honeypot_should_validate
(
array
$element
,
FormStateInterface
$form_state
)
{
// Skip validation for a certain whitelisted ip.
return
\Drupal
::
request
()
->
getClientIp
()
===
'some-whitelisted-ip'
;
}
/**
* @} End of "addtogroup hooks".
*/
This diff is collapsed.
Click to expand it.
src/HoneypotService.php
+
10
−
0
View file @
e42d70aa
...
...
@@ -296,6 +296,11 @@ class HoneypotService implements HoneypotServiceInterface {
* The complete form structure.
*/
public
function
validateHoneypot
(
array
&
$element
,
FormStateInterface
$form_state
,
array
&
$complete_form
):
void
{
$shouldValidate
=
$this
->
moduleHandler
->
invokeAll
(
'honeypot_should_validate'
,
[
$element
,
$form_state
]);
if
(
in_array
(
FALSE
,
$shouldValidate
,
TRUE
))
{
return
;
}
// Get the honeypot field value.
$honeypot_value
=
$element
[
'#value'
];
...
...
@@ -323,6 +328,11 @@ class HoneypotService implements HoneypotServiceInterface {
return
;
}
$shouldValidate
=
$this
->
moduleHandler
->
invokeAll
(
'honeypot_should_validate'
,
[
$element
,
$form_state
]);
if
(
in_array
(
FALSE
,
$shouldValidate
,
TRUE
))
{
return
;
}
$triggering_element
=
$form_state
->
getTriggeringElement
();
// Don't do anything if the triggering element is a preview button.
if
(
$triggering_element
[
'#value'
]
==
(
string
)
$this
->
t
(
'Preview'
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment