I'm trying to enable grouping for the Views Datasource module. I'm looping through the $rows array, which is where output is stored by the module before it's formatted into JSON. Problem is, the grouping field is stored in $options as its machine name, but $rows uses the user-defined label for field names. Basically, I just need a function to take the machine name for a field and return the display-set label for it.

I already tried field_views_field_label, but it returns an array of the labels for fields defined in the content type, where I need the label defined in the view display.

$group = $options["grouping"][0]["field"];
// Get grouping field as defined by the field options in the view display
$root = $options["root_object"];
$top_child = $options["top_child_object"];
if ($group) {
  $grouped = array();
    foreach ($rows[$root] as $key => $array) { // Values are numeric
      // Grab the grouping field value from inside the 3rd-level array.
      // Creating a label for grouping field will break everything
      $groupnode = $array[$top_child][$group];
      foreach ($array[$top_child] as $prop => $value) {
        if ($prop != $group) { // Ignore grouped field
          $grouped[$root][$groupnode][$prop][$key] = $value;
  $rows = $grouped;

2 Answers 2


I recommend to take a look at this answer which provides lots of information on how to change the output produced by Views Datasource. This should give you a starter.


I finally learned of the Search Krumo module, which let me search for the variable I was looking for. It was $view->query->pager->display->handler->handlers['field'][$group]->options['label'], where $group is the machine name of the grouped field. No function was necessary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.