Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
8d989472
Commit
8d989472
authored
Apr 06, 2014
by
alexpott
Browse files
Issue
#1957152
by brantwynn: Replace calls to the flood service with Drupal::flood().
parent
c2423131
Changes
3
Hide whitespace changes
Inline
Side-by-side
core/modules/contact/lib/Drupal/contact/MessageFormController.php
View file @
8d989472
...
...
@@ -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 @@ public function save(array $form, array &$form_state) {
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
,
...
...
core/modules/system/lib/Drupal/system/Tests/System/FloodTest.php
View file @
8d989472
...
...
@@ -48,7 +48,7 @@ function testCleanUp() {
$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
));
...
...
core/modules/system/system.module
View file @
8d989472
...
...
@@ -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
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment