function comment_ip_form_comment_admin_overview_alter in Comment IP 8
Implements hook_form_FORM_ID_alter().
File
- ./
comment_ip.module, line 14 - Comment IP primary module file.
Code
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();
}
}