I am trying to get comment data with views.get

It seems I am only able to get the CID and I cannot ask for specific fields

Comments

gdoteof’s picture

Status: Active » Needs review

it didn't seem this was possible with the current implementation. I am balls to the wall busy and cvs won't check out for me, so I am sorry for no patch.. someone else is free to make one or I will on request in the coming days but I added:

  // If it's a comment it should not go through services_node_load
  // But rather be passed directly
  elseif($view->base_table == 'comments') {
    foreach ($view->result as $comment) {
          $nodes[] = $comment;
        }
    }

for a final function of

function views_service_get($view_name, $fields = array(), $args = array(), $offset = 0, $limit = 0) {
  $view = views_get_view($view_name);

  // Put all arguments and then execute
  $view->set_arguments($args, FALSE);
  $view->set_offset($offset);
  $view->set_items_per_page($limit);
  $view->execute();

  // Get row plugin setting
  $row_plugin = $view->display[$view->current_display]->display_options['row_plugin'];

  $nodes = array();
  // If row plugin is node, then we must do a node_load
  if ($row_plugin == 'node') {
    foreach ($view->result as $node) {
      $nodes[] = services_node_load(node_load($node->nid), $fields);
    }
  }
  // If it's a comment it should not go through services_node_load
  // But rather be passed directly
  elseif($view->base_table == 'comments') {
    foreach ($view->result as $comment) {
          $nodes[] = $comment;
        }
    }
  // Otherwise, pass through the fields filter, just in case
  else {
    foreach ($view->result as $node) {
      $nodes[] = services_node_load($node, $fields);
    }
  }

  return $nodes;
}

It's not perfect, as you can't filter by fields. However it does respect the views' fields. It should be noted this only works when row type is set to 'fields' and not 'comments'

marcingy’s picture

It might be worth you getting involved in the efforts going on here to improve views handling in services - http://drupal.org/node/329048.

marcingy’s picture

added tag

gdd’s picture

Status: Needs review » Closed (fixed)

This should work properly in the new views.get function, included in the current -dev version. If you continue to have problems please open a new issue as that version is very different.