You are here

function node_convert_format_field_value_helper in Node Convert 7

Format a field's values.

@internal param $singular_label @internal param $plural_label @internal param $columns @internal param string $prefix_label @internal param $field

Parameters

$field_values:

array $options:

Return value

string

1 call to node_convert_format_field_value_helper()
node_convert_format_field_value in ./node_convert.util.inc
Returns a string containing the value of the $field from the $node object.

File

./node_convert.util.inc, line 403
API and Utility Functions.

Code

function node_convert_format_field_value_helper($field_values, $options = array()) {
  $output = '';
  $prefix_label = isset($options['prefix_label']) ? $options['prefix_label'] : '';
  $singular_label = isset($options['singular_label']) ? $options['singular_label'] : '';
  $plural_label = isset($options['plural_label']) ? $options['plural_label'] : '';
  $columns = isset($options['columns']) ? $options['columns'] : array();
  $no_labels = isset($options['no_labels']) ? $options['no_labels'] : array();
  if (empty($field_values)) {
    if (!$no_labels) {
      $output = 'NULL';
    }
    return $output;
  }

  // Prefix a label.
  if (!empty($prefix_label) && !$no_labels) {
    $output .= $prefix_label . ' ; ';
  }

  // Add the label depending on number of field values.
  $count = count($field_values);
  $label = format_plural($count, $singular_label, $plural_label, array());
  $items = array();
  foreach ($field_values as $item) {
    $column_values = array();
    foreach ($columns as $column_key => $column) {
      $column_label = '';
      if (!is_numeric($column_key) && !empty($item[$column]) && !$no_labels) {
        $column_label = $column_key . ': ';
      }
      $column_value = isset($item[$column]) ? $item[$column] : '';
      $column_values[] = $column_label . filter_xss_admin($column_value);
    }
    $items[] = implode(' ', $column_values);
  }
  $final_label = '';
  if (!$no_labels) {
    $final_label = $label . ': ';
  }
  $output .= $final_label . implode(', ', $items);
  return $output;
}