By default, when using the Views plugin to create the json feed, the nid is used as the label for each item record. The label is used within the Exhibit framework for a few things, most notably for me in the MapView infoWindow when more than one marker has the same coordinates. In this case, and in most cases, I think the label should be more user-friendly and descriptive.

I got around this by editing views_plugin_style_exhibit_json.inc

$items[$row->$base_field] = array_merge(array('label' => $row->$base_field, 'type' => $this->view->base_table), $item);

to

$newlabel = $row->$base_field;
if ($item['title_1']) {
$newlabel = $item['title_1'];
   if (strlen($item['title_1']) > 50) $newlabel = substr($item['title_1'],0,50)."...";
}
$items[$row->$base_field] = array_merge(array('id'=>$row->$base_field, 'label' => $newlabel, 'type' => $this->view->base_table), $item);

In the above, I always add two node Title fields to the View, the first one "title" is linked to the node, and the second "title_1" is not. The second field "title_1" is used as the label. Also, my titles were kind of long and blew up the MapView infoWindow bubbles, so I restricted the length of the strings to 50 characters. This is certainly not necessary and probably should be best done though a javascript function in Exhibit.

It would be nice that for each view/feed, you can specify (in the Views UI) which field you to use as the label and, optionally, the string length limit.

Comments

charlesc’s picture

It's very useful. Thanks!!