Posted by YesCT on November 23, 2012 at 3:29am
Project:
Drupal core
Introduced in branch:
8.x Description:
The Flood API is now a service. There is a Drupal\Core\Flood\FloodInterface with a default implementation that uses the database.
The implementation can be accessed through Drupal::flood(). The service provides the methods isAllowed(), register() and clear(), which directly map to the previous functions.
Drupal 7
<?php
// Check if an event is allowed.
flood_is_allowed('mymodule.event', $limit, $interval, $identifier);
// Register an event.
flood_register_event('mymodule.event', $interval, $identifier);
// Clear a flood event.
flood_clear_event('mymodule.event', $identifier);
?>Drupal 8
<?php
// Check if an event is allowed.
Drupal::flood()->isAllowed('mymodule.event', $limit, $interval, $identifier);
// Register an event.
Drupal::flood()->register('mymodule.event', $interval, $identifier));
// Clear a flood event.
Drupal::flood()->clear('mymodule.event', $identifier);
?>Just like before, $identifier defaults to the current IP address and $interval defaults to one hour.
Impacts:
Module developers