You are here

public function StatusEnhanced::render in http:BL 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/StatusEnhanced.php, line 55

Class

StatusEnhanced
Field handler to display human-ized definitions of the integer status values.

Namespace

Drupal\httpbl\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = $values->{$this->field_alias};
  if (!empty($this->options['status_enhanced']) || !isset($this->valueOptions[$value])) {

    // Status with humanized conversion.
    $httpblManager = \Drupal::service('httpbl.evaluator');
    $human = $httpblManager
      ->getHumanStatus($value);
    $enhanced_value = t($value . ' - <em style="color: lightgrey;">' . $human . '</em>');

    //alternate, without any forced style.

    //$enhanced_value = t($value . ' - ' . $human);

    //$enhanced_value = t($value . ' - <span class="humanized">' . $human . '</span>');

    // If this entity is blacklisted && Ban module exists...
    if ($value == HTTPBL_LIST_BLACK && \Drupal::moduleHandler()
      ->moduleExists('ban')) {

      // Also check if it has been banned.
      $ip = $values->httpbl_host_host_ip;
      $banManager = \Drupal::service('ban.ip_manager');

      // If this host is also found in ban_ip table...
      if ($banManager
        ->isBanned($ip)) {

        // Report as banned on the list, in addition to being blacklisted.
        $enhanced_value = t($value . ' - <em style="color: lightgrey;">' . $human . ' and Banned!</em>');

        //alternate, without any forced style.

        //$enhanced_value  = t($value . ' - ' . $human . ' and Banned!');

        //$enhanced_value  = t($value . ' - <span class="humanized">' . $human . ' and Banned!</span>');
      }
    }

    // @todo Probably will have to play by the rules.  Not ready to sanatize this.

    //$result = $this->sanitizeValue($enhanced_value);
    $result = $enhanced_value;
  }
  else {
    $result = $this->valueOptions[$value];
  }
  return $result;
}