Here is the code of custom style plugin.

<?php
  // ...

  function render() {
    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
    // Turn this all into an $options array for the jump menu.
    $this->view->row_index = 0;
    $fields = array();

    foreach ($sets as $title => $records) {
      foreach ($records as $row_index => $row) {
        $this->view->row_index = $row_index;
        // get_field - returns NULL if more than one grouping field selected
        $fields[] = $this->get_field_value($this->view->row_index, $this->options['data_field']);
        $this->view->row_index++;
      }
    }
    unset($this->view->row_index);

    return var_export($fields, TRUE);
  }

  // ...
?>

It uses views_plugin_style::get_field_value to get raw data from field, but prints error if more than one grouping field selected:

__clone method called on non-object in /var/d7/sites/project.22/modules/views/modules/field/views_handler_field_field.inc on line 650

Comments

elaman’s picture

Status: Active » Needs review

I've written quick hack, but still not sure if it could handle all situations.

<?php
  // ...

  function render() {
    $sets = $this->render_grouping($this->view->result, $this->options['grouping']);
    // Turn this all into an $options array for the jump menu.
    $this->view->row_index = 0;
    $fields = array();

    foreach ($sets as $title => $records) {
      // walk through groups and get rows
      $rows = $this->get_group_rows($records);
      // prepare objects for view
      foreach ($rows as $row_index => $row) {
        $this->view->row_index = $row_index;
        $fields[] = $this->view->style_plugin->get_field_value($this->view->row_index, $this->options['data_field']);
        $this->view->row_index++;
      }
    }
    unset($this->view->row_index);

    return var_export($fields, TRUE);
  }

  /**
   * Get rows from groups.
   */
  function get_group_rows($target) {
    $first = reset($target);
    // get rows if its a group
    if (is_array($first) && isset($first['group'])) {
      return $this->get_group_rows($first['rows']);
    }
    // return rows
    else {
      return $target;
    }
  }

  // ...
?>
tim.plunkett’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Needs review » Active

Please read http://drupal.org/patch/create and upload your changes as a patch, then set to "needs review".

juhaniemi’s picture

I had kinda similar issue related to get_field_value(). If the field is empty, it ends up in the same PHP fatal error: __clone method called on non-object.

My display plugin needs to get the data directly, not through theme functions (the plugin outputs a custom JSON document). So this function is the ideal function to get the actual data by the field_name (names are not exactly the same ones in the $view->result row arrays).

MustangGB’s picture

Category: Support request » Feature request
Issue summary: View changes