StatusEnhanced.php in http:BL 8
File
src/Plugin/views/field/StatusEnhanced.php
View source
<?php
namespace Drupal\httpbl\Plugin\views\field;
use Drupal\Core\Form\FormStateInterface;
use Drupal\views\ResultRow;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\httpbl\HttpblManager;
class StatusEnhanced extends FieldPluginBase {
public function defineOptions() {
$options = parent::defineOptions();
$options['status_enhanced'] = array(
'default' => TRUE,
);
return $options;
}
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$form['status_enhanced'] = array(
'#title' => $this
->t('Status enhanced'),
'#description' => $this
->t('Shows the definitions of the integer status values, and when a blacklisted host is also banned.'),
'#type' => 'checkbox',
'#default_value' => !empty($this->options['status_enhanced']),
);
}
public function render(ResultRow $values) {
$value = $values->{$this->field_alias};
if (!empty($this->options['status_enhanced']) || !isset($this->valueOptions[$value])) {
$httpblManager = \Drupal::service('httpbl.evaluator');
$human = $httpblManager
->getHumanStatus($value);
$enhanced_value = t($value . ' - <em style="color: lightgrey;">' . $human . '</em>');
if ($value == HTTPBL_LIST_BLACK && \Drupal::moduleHandler()
->moduleExists('ban')) {
$ip = $values->httpbl_host_host_ip;
$banManager = \Drupal::service('ban.ip_manager');
if ($banManager
->isBanned($ip)) {
$enhanced_value = t($value . ' - <em style="color: lightgrey;">' . $human . ' and Banned!</em>');
}
}
$result = $enhanced_value;
}
else {
$result = $this->valueOptions[$value];
}
return $result;
}
}
Classes
Name |
Description |
StatusEnhanced |
Field handler to display human-ized definitions of the integer status values. |