You are here

public function AnonymousPublishingClAdminSpam::submitForm in Anonymous Publishing 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/anonymous_publishing_cl/src/Form/AnonymousPublishingClAdminSpam.php, line 201

Class

AnonymousPublishingClAdminSpam

Namespace

Drupal\anonymous_publishing_cl\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $operation = $form_state
    ->getValue('operation');
  $ids = $form_state
    ->getValue('items');
  $hidden = unserialize($form_state
    ->getValue('hidden_values'));
  foreach ($ids as $id) {
    if ($operation = 'ban') {
      $existp = $this->database
        ->select('ban_ip')
        ->fields('blocked_ips')
        ->condition('ip', $hidden[$id])
        ->execute()
        ->fetchAssoc();
      if (FALSE == $existp) {
        $this->database
          ->insert('ban_ip')
          ->fields(array(
          'ip',
        ), array(
          $hidden[$id],
        ))
          ->execute();
      }
    }
    if ($operation == 'unban') {
      $this->database
        ->delete('ban_ip')
        ->condition('ip', $hidden[$id])
        ->execute();
    }
  }
  $this
    ->messenger()
    ->addMessage($this
    ->t('The update has been performed.'));
}