public function AnonymousPublishingClAdminUnverified::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/ AnonymousPublishingClAdminUnverified.php, line 223
Class
Namespace
Drupal\anonymous_publishing_cl\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
$operation = $form_state
->getValue('operation');
$ids = $form_state
->getValue('items');
$hiddens = unserialize($form_state
->getValue('hidden_values'));
$deleted = $moved = 0;
$ownip = \Drupal::request()
->getClientIp();
foreach ($ids as $id) {
$hidden = $hiddens[$id];
if ($operation == 'ban') {
// Don't block self.
if ($ownip == $hidden['ip']) {
$this
->messenger()
->addMessage(t("You've tried to ban your own IP (request is ignored)."));
continue;
}
if (!empty($hidden['ip'])) {
$existp = $this->database
->select('blocked_ips')
->where('ip = :ip', array(
':ip' => $hidden['ip'],
))
->execute()
->fetchAssoc();
if (FALSE == $existp) {
$res = $this->database
->insert('blocked_ips')
->fields([
'ip' => $hidden['ip'],
])
->execute();
}
else {
$res = TRUE;
}
if ($res) {
$res = $this->database
->delete('anonymous_publishing')
->condition('apid', $id)
->execute();
$moved++;
}
}
if ($hidden['cid']) {
Comment::load($hidden['cid'])
->delete();
$deleted++;
}
elseif ($hidden['nid']) {
Node::load($hidden['nid'])
->delete();
$deleted++;
}
}
}
if ($moved) {
$msg1 = t('IP-address moved to <code>{blocked_ips}</code>.');
$msg1 .= ' ';
}
else {
$msg1 = '';
}
if ($deleted) {
$msg2 = t('Spam deleted.');
}
else {
$msg2 = t('No spam could be identified.');
}
$this
->messenger()
->addStatus($msg1 . $msg2);
}