You are here

public function ViewsJsonQuery::parseRow in Views Json Source 8

Same name and namespace in other branches
  1. 1.x src/Plugin/views/query/ViewsJsonQuery.php \Drupal\views_json_source\Plugin\views\query\ViewsJsonQuery::parseRow()

Parse row.

A recursive function to flatten the JSON object. Example: {person:{name:{first_name:"John", last_name:"Doe"}}} becomes: $row->person/name/first_name = "John", $row->person/name/last_name = "Doe"

1 call to ViewsJsonQuery::parseRow()
ViewsJsonQuery::parse in src/Plugin/views/query/ViewsJsonQuery.php
Parse.

File

src/Plugin/views/query/ViewsJsonQuery.php, line 435

Class

ViewsJsonQuery
Base query handler for views_json_source.

Namespace

Drupal\views_json_source\Plugin\views\query

Code

public function parseRow($parent_key, $parent_row, &$row) {
  foreach ($parent_row as $key => $value) {
    if (is_array($value)) {
      unset($row[$key]);
      $this
        ->parseRow(is_null($parent_key) ? $key : $parent_key . '/' . $key, $value, $row);
    }
    else {
      if ($parent_key) {
        $new_key = $parent_key . '/' . $key;
        $row[$new_key] = $value;
      }
      else {
        $row[$key] = $value;
      }
    }
  }
  return $row;
}