You are here

protected function ContactFormBlock::floodControl in Form Block 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/Block/ContactFormBlock.php \Drupal\formblock\Plugin\Block\ContactFormBlock::floodControl()

Returns the current status of flood control.

Return value

bool|string False if flood control should not be enabled or an error message if flood control is enabled.

1 call to ContactFormBlock::floodControl()
ContactFormBlock::build in src/Plugin/Block/ContactFormBlock.php
Implements \Drupal\block\BlockBase::build().

File

src/Plugin/Block/ContactFormBlock.php, line 219

Class

ContactFormBlock
Provides a block for contact form.

Namespace

Drupal\formblock\Plugin\Block

Code

protected function floodControl() {
  $limit = $this->configFactory
    ->get('contact.settings')
    ->get('flood.limit');
  $interval = $this->configFactory
    ->get('contact.settings')
    ->get('flood.interval');
  if (!$this->flood
    ->isAllowed('contact', $limit, $interval)) {
    return $this
      ->t('You cannot send more than %limit messages in @interval. Try again later.', [
      '%limit' => $limit,
      '@interval' => $this->dateFormatter
        ->formatInterval($interval),
    ]);
  }
  return FALSE;
}