comment_ip.module in Comment IP 8
Same filename and directory in other branches
Comment IP primary module file.
File
comment_ip.moduleView source
<?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();
}
}
Functions
Name | Description |
---|---|
comment_ip_form_comment_admin_overview_alter | Implements hook_form_FORM_ID_alter(). |