Issue #1957152 by brantwynn: Replace calls to the flood service with Drupal::flood().

8.0.x
Alex Pott 2014-04-06 21:34:23 +01:00
parent c242313140
commit 8d98947271
3 changed files with 50 additions and 3 deletions

View File

@ -8,9 +8,13 @@
namespace Drupal\contact;
use Drupal\Component\Utility\String;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\ContentEntityFormController;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Core\Language\Language;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form controller for contact message forms.
@ -24,6 +28,48 @@ class MessageFormController extends ContentEntityFormController {
*/
protected $entity;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The flood control mechanism.
*
* @var \Drupal\Core\Flood\FloodInterface
*/
protected $flood;
/**
* Constructs a MessageFormController object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Flood\FloodInterface $flood
* The flood control mechanism.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityManagerInterface $entity_manager, FloodInterface $flood) {
parent::__construct($entity_manager);
$this->configFactory = $config_factory;
$this->flood = $flood;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('entity.manager'),
$container->get('flood')
);
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::form().
*/
@ -195,7 +241,8 @@ class MessageFormController extends ContentEntityFormController {
drupal_mail('contact', 'page_autoreply', $sender->getEmail(), $language_interface->id, $params);
}
\Drupal::service('flood')->register('contact', \Drupal::config('contact.settings')->get('flood.interval'));
$config = $this->configFactory->get('contact.settings');
$this->flood->register('contact', $config->get('flood.interval'));
if (!$message->isPersonal()) {
watchdog('contact', '%sender-name (@sender-from) sent an e-mail regarding %category.', array(
'%sender-name' => $sender->name,

View File

@ -48,7 +48,7 @@ class FloodTest extends WebTestBase {
$name = 'flood_test_cleanup';
// Register expired event.
$flood = \Drupal::service('flood');
$flood = \Drupal::flood();
$flood->register($name, $window_expired);
// Verify event is not allowed.
$this->assertFalse($flood->isAllowed($name, $threshold));

View File

@ -1558,7 +1558,7 @@ function system_get_module_admin_tasks($module, array $info) {
*/
function system_cron() {
// Cleanup the flood.
\Drupal::service('flood')->garbageCollection();
\Drupal::flood()->garbageCollection();
foreach (Cache::getBins() as $cache_backend) {
$cache_backend->garbageCollection();