function _views_geojson_render_multiple_field in Views GeoJSON 6
We almost duplicate the content_handler_field_multiple::render function to get the multiple rendered field values in an array
Parameters
$field:
$values:
Return value
unknown_type
File
- ./
views_geojson.module, line 25 - Provide a GeoJSON Views feed style.
Code
function _views_geojson_render_multiple_field($field, $values) {
$options = $field->options;
// If this is not a grouped field, use content_handler_field::render().
if (!$field->defer_query) {
return $field
->render($values);
}
// We're down to a single node here, so we can retrieve the actual field
// definition for the node type being considered.
$content_field = content_fields($field->content_field['field_name'], $values->{$field->aliases['type']});
$vid = $values->{$field->field_alias};
if (isset($field->field_values[$vid])) {
// Gather items, respecting the 'Display n values starting from m' settings.
$count_skipped = 0;
$items = array();
foreach ($field->field_values[$vid] as $item) {
if (empty($options['multiple']['multiple_from']) || $count_skipped >= $options['multiple']['multiple_from']) {
if (empty($options['multiple']['multiple_number']) || count($items) < $options['multiple']['multiple_number']) {
// Grab the nid - needed for render_link().
$nid = $item['_nid'];
unset($item['_nid']);
$items[] = $item;
}
else {
break;
}
}
$count_skipped++;
}
// Build a pseudo-node from the retrieved values.
$node = drupal_clone($values);
// content_format and formatters will need a 'type'.
$node->type = $values->{$field->aliases['type']};
$node->nid = $values->{$field->aliases['nid']};
$node->vid = $values->{$field->aliases['vid']};
// Some formatters need to behave differently depending on the build_mode
// (for instance: preview), so we provide one.
$node->build_mode = NODE_BUILD_NORMAL;
// Render items.
$formatter_name = $options['format'];
if ($items && ($formatter = _content_get_formatter($formatter_name, $content_field['type']))) {
$rendered = array();
if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) {
// Single-value formatter.
$n = 0;
foreach ($items as $item) {
$output = content_format($content_field, $item, $formatter_name, $node);
if (!empty($output)) {
$rendered[++$n] = $field
->render_link($output, (object) array(
'nid' => $nid,
));
}
}
}
else {
// Multiple values formatter.
$output = content_format($content_field, $items, $formatter_name, $values);
if (!empty($output)) {
$rendered[++$n] = $field
->render_link($output, (object) array(
'nid' => $nid,
));
}
}
if (count($rendered) > 1) {
// TODO: could we use generic field display ?
//return theme('content_view_multiple_field', $rendered, $content_field, $values);
return $rendered;
}
elseif ($rendered) {
return $rendered[1];
}
}
}
return '';
}