comment_ip-8.x-1.x-dev/comment_ip.module
comment_ip.module
<?php
/**
* @file
* Comment IP primary module file.
*/
use Drupal\comment\Entity\Comment;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_FORM_ID_alter().
*/
function comment_ip_form_comment_admin_overview_alter(&$form, FormStateInterface $form_state) {
$user = \Drupal::currentUser();
if ($user->hasPermission('ban IP addresses')) {
// Add commentors IP address to comment row.
$form['options']['operation']['#options']['ban'] = t('Delete the selected comments and block their IPs');
}
$reorder = [
'changed' => $form['comments']['#header']['changed'],
'operations' => $form['comments']['#header']['operations'],
];
unset($form['comments']['#header']['changed']);
unset($form['comments']['#header']['operations']);
$form['comments']['#header']['ip'] = [
'data' => t('IP'),
'specifier' => 'ip',
'field' => 'hostname',
];
$form['comments']['#header']['changed'] = $reorder['changed'];
$form['comments']['#header']['operations'] = $reorder['operations'];
foreach ($form['comments']['#options'] as $id => $option) {
$comment = Comment::load($id);
$form['comments']['#options'][$id]['ip'] = $comment->getHostname();
}
}
