You are here

public function CronExpireDate::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 Date::render

File

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

Class

CronExpireDate
Field handler to display the newer of last comment / node updated.

Namespace

Drupal\httpbl\Plugin\views\field

Code

public function render(ResultRow $values) {
  $value = $this
    ->getValue($values);
  $format = $this->options['date_format'];
  if (in_array($format, array(
    'cron time expire',
  ))) {
    $custom_format = $this->options['custom_date_format'];
  }
  if ($value) {
    $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
    $time_diff = \Drupal::time()
      ->getRequestTime() - $value;

    // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
    switch ($format) {
      case 'cron time expire':
        if ($time_diff >= 0) {

          // Instead of showing "0 seconds"...
          return $this
            ->t('(next cron)');
        }
        else {
          return $this
            ->t('in ' . $this->dateFormatter
            ->formatTimeDiffUntil($value, array(
            'granularity' => is_numeric($custom_format) ? $custom_format : 2,
          )));
        }
      default:
        return format_date($value, $format, '', $timezone);
    }
  }
  parent::render($values);
}