The FloodInterface has 4 methods:

  • register - which adds an event
  • clear - which clears an event
  • isAllowed - which checks to see if the number of logged events is greater than the threshold
  • garbageCollection - removes expired events

I'm creating an EntityForm and need to use the number of flood events to conditionally set certain form elements, does anyone know if there is a way to do this?


The only way to do that with the default FloodInterface would be to use the isAllowed method and adjust the threshold to the number of allowed attempts.

From a hook_form_alter() you could do something similar to this, where 'my_trigger' is the name of the event that is registered, such as 'contact' for the contact form or 'user.failed_login_ip' and 'user.failed_login_user' for user login. 5 would be the maximum number of times the event could have been registered in 3600 seconds.


function hook_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
  // Hide element if over the number of allowed attempts
  if (!\Drupal::flood()->isAllowed('my_trigger', 5, 3600)) {
    $form['my_element']['#access'] = FALSE;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.