Getting the number of Flood events within threshold? 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.

&lt;?php

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