Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#3 | views_datasource-missing-root-elements-2054847-1.patch | 5.59 KB | ianchan |
#1 | views_datasource-Missing-root-elements-2054847-0.patch | 5.92 KB | wwedding |
Comments
Comment #1
wwedding CreditAttribution: wwedding commentedThis is a patch that can be applied to fix this.
Comment #2
ianchan CreditAttribution: ianchan commentedHi,
First time patch submission! Attached is against the latest dev version for 6.x-1.x.
Comment #3
ianchan CreditAttribution: ianchan commentedSorry, now I see how to add a comment to a patch attachment.