Problem

The Drupal 6 version of this module completely ignores most settings, including the root and first child settings. This means row output isn't wrapped in what are often necessary API-like root elements unless someone implements it in their own custom template.

Proposed resolution

The following code can be cribbed directly from the D7 theme functions with some other slight modifications and placed into heme/views-views-json-style-exhibit.tpl.php or theme/views-views-json-style-simple.tpl.php.

$objects = array();

foreach ($rows as $row) {

  $object = array();
  /* Convert the $rows into a hierachial key=>value array */
  foreach ($row as $field) {
    if ($options["field_output"] == "normal") {
      if ($field->label)
        $label = $plaintext_output ? strip_tags($field->label) : $field->label;
      else {
        $label = $plaintext_output ? strip_tags($field->id) : $field->id;
      }
      if (!$field->is_multiple) {
        $content = $plaintext_output ? strip_tags($field->content) : $field->content;
      }
      else {
        $content = array();
        foreach ($field->content as $n => $oc) $content[$n] = ($plaintext_output ? strip_tags($oc) : $oc);
      }
    }
    elseif ($options["field_output"] == "raw") {
      $label = $plaintext_output ? strip_tags($field->id) : $field->id;
      if (!$field->is_multiple) {
        $content = $plaintext_output ? strip_tags($field->raw) : $field->raw;
      }
      else {
        $content = array();
        foreach ($field->raw as $n => $oc) $content[$n] = $plaintext_output ? strip_tags($oc) : $oc;
      }
    }

    // check if user wants nested arrays
    if (strlen($top_child_object) != 0) {
      $object[$top_child_object][$label] = $content;
    }
    else {
      $object[$label] = $content;
    }
  }
  $objects[] = $object;
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wwedding’s picture

Status: Active » Needs review
FileSize
5.92 KB

This is a patch that can be applied to fix this.

ianchan’s picture

Hi,

First time patch submission! Attached is against the latest dev version for 6.x-1.x.

ianchan’s picture

Sorry, now I see how to add a comment to a patch attachment.