You are here

function PollStatus::render in Poll 8

Parameters

\Drupal\views\ResultRow $values:

Return value

mixed

Overrides FieldPluginBase::render

File

src/Plugin/views/field/PollStatus.php, line 21

Class

PollStatus
Field handler which displays the flag indicating whether the poll is active including the runtime.

Namespace

Drupal\poll\Plugin\views\field

Code

function render(ResultRow $values) {

  /** @var \Drupal\poll\PollInterface $entity */
  $entity = $values->_entity;
  if ($entity
    ->isOpen() && $entity
    ->getRuntime() != 0) {
    $date = \Drupal::service('date.formatter')
      ->format($entity
      ->getCreated() + $entity
      ->getRuntime(), 'short');
    $output = 'Yes (until ' . rtrim(strstr($date, '-', true)) . ')';
  }
  else {
    if ($entity
      ->isOpen()) {
      $output = t('Yes');
    }
    else {
      $output = 'No';
    }
  }
  return $output;
}