You are here

public static function Util::viewsData in Charts 8

Same name and namespace in other branches
  1. 8.4 src/Util/Util.php \Drupal\charts\Util\Util::viewsData()
  2. 8.3 src/Util/Util.php \Drupal\charts\Util\Util::viewsData()
  3. 5.0.x src/Util/Util.php \Drupal\charts\Util\Util::viewsData()

Parameters

$view:

$labelValues:

$labelField:

$color:

Return value

array

1 call to Util::viewsData()
template_preprocess_views_view_charts in ./charts.module

File

src/Util/Util.php, line 14

Class

Util

Namespace

Drupal\charts\Util

Code

public static function viewsData($view, $labelValues, $labelField, $color) {
  $data = array();
  foreach ($view->result as $id => $row) {
    $numberFields = 0;
    $rowData = array();
    foreach ($labelValues as $fieldId => $rowDataValue) {
      $rowData[$numberFields] = array(
        'value' => $view->field[$fieldId]
          ->getValue($row),
        'label_field' => $view->field[$labelField]
          ->getValue($row),
        'label' => $view->field[$fieldId]
          ->label(),
        // 'label' => $view->display_handler->display['id'], to use display_id
        'color' => $color[$fieldId],
      );
      $numberFields++;
    }
    $data[$id] = $rowData;
  }
  return $data;
}