You are here

public function RoleExpireExpiryData::preRender in Role Expire 8

Same name and namespace in other branches
  1. 2.x src/Plugin/views/field/RoleExpireExpiryData.php \Drupal\role_expire\Plugin\views\field\RoleExpireExpiryData::preRender()

inheritdoc}

Overrides FieldPluginBase::preRender

File

src/Plugin/views/field/RoleExpireExpiryData.php, line 125

Class

RoleExpireExpiryData
Field handler to display the role expire data.

Namespace

Drupal\role_expire\Plugin\views\field

Code

public function preRender(&$values) {
  $this->items = [];
  if (is_array($values)) {
    $format = $this->options['custom_date_format'];
    $timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
    foreach ($values as $user) {
      $expirations = $this->roleExpireApi
        ->getAllUserRecords($user->uid);
      foreach ($expirations as $role => $timestamp) {
        $date = $this->dateFormatter
          ->format($timestamp, 'custom', $format, $timezone);
        $this->items[$user->uid][$role]['expireData'] = $this
          ->t('@role (@date)', [
          '@role' => $role,
          '@date' => $date,
        ]);
      }
    }
  }
}