Skip to content
Snippets Groups Projects
Commit e1d39e33 authored by Jeff Geerling's avatar Jeff Geerling
Browse files

Issue #1969212: Add hook_honeypot_reject so other modules can react to...

Issue #1969212: Add hook_honeypot_reject so other modules can react to rejected form submissions (D8).
parent 14dd9312
No related branches found
Tags 8.x-1.14-beta3
No related merge requests found
......@@ -46,6 +46,24 @@ function hook_honeypot_add_form_protection($options, $form) {
}
}
/**
* React to the rejection of a form submission.
*
* When honeypot rejects a form submission, it calls this hook with the form ID
* and the user ID (0 if anonymous) of the user that was disallowed from
* submitting the form.
*
* @param (string) $form_id
* Form ID of the form the user was disallowed from submitting.
* @param (int) $uid
* 0 for anonymous users, otherwise the user ID of the user.
*/
function hook_honeypot_reject($form_id, $uid) {
if ($form_id == 'mymodule_form') {
// Do something...
}
}
/**
* Add time to the Honeypot time limit.
*
......
......@@ -238,7 +238,7 @@ function _honeypot_time_restriction_validate($form, &$form_state) {
* - 'honeypot_time'
*/
function _honeypot_log($form_id, $type) {
honeypot_log_failure();
honeypot_log_failure($form_id);
if (variable_get('honeypot_log', 0)) {
$variables = array(
'%form' => $form_id,
......@@ -285,9 +285,13 @@ function honeypot_get_time_limit($form_values = array()) {
/**
* Log the failed submision with timestamp.
*
* @param $form_id
* Form ID for the rejected form submission.
*/
function honeypot_log_failure() {
function honeypot_log_failure($form_id) {
global $user;
// Log failed submissions for authenticated users.
if ($user->uid) {
db_insert('honeypot_user')
......@@ -301,4 +305,7 @@ function honeypot_log_failure() {
else {
drupal_container()->get('flood')->register('honeypot.event');
}
// Allow other modules to react to honeypot rejections.
module_invoke_all('honeypot_reject', $form_id, $user->uid);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment