You are here

public function Lists::preRender in Campaign Monitor 8

Runs before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

\Drupal\views\ResultRow[] $values: An array of all ResultRow objects returned from the query.

Overrides FieldPluginBase::preRender

File

modules/campaignmonitor_local/src/Plugin/views/Field/Lists.php, line 72

Class

Lists
Field handler to provide a list of CM lists.

Namespace

Drupal\campaignmonitor_local\Plugin\views\field

Code

public function preRender(&$values) {
  $uids = [];
  $this->items = [];
  $lists = campaignmonitor_get_list_options();
  foreach ($values as $record) {
    $uids[] = $record->uid;
  }
  if ($uids) {
    $available_lists = campaignmonitor_get_list_options();
    $result = $this->database
      ->query('SELECT cls.uid, cls.list_id FROM {campaignmonitor_local_subscriptions} cls WHERE cls.uid IN ( :uids[] ) AND cls.list_id IN ( :lids[] )', [
      ':uids[]' => $uids,
      ':lids[]' => array_keys($available_lists),
    ]);
    foreach ($result as $sub) {
      $this->items[$sub->uid][$sub->list_id]['name'] = $lists[$sub->list_id];
      $this->items[$sub->uid][$sub->list_id]['list_id'] = $sub->list_id;
    }
  }
}