You are here

function file_field_diff_view in Diff 7.3

Diff field callback for parsing file field comparative values.

File

includes/file.inc, line 29
Provide diff field functions for the file module.

Code

function file_field_diff_view($items, $context) {
  $field = $context['field'];
  $instance = $context['instance'];
  $settings = $context['settings'];
  $diff_items = array();
  foreach ($items as $delta => $item) {
    if (isset($item['file'])) {
      $output = array();

      // We populate as much as possible to allow the best flexability in any
      // string overrides.
      $t_args = array();
      foreach ($item as $key => $value) {
        if (is_scalar($value)) {
          $t_args['!' . $key] = $value;
        }
      }

      // Some states do not have the file properties in the item, so put these
      // out of the main file object.
      if (!empty($item['file'])) {
        $file_values = (array) $item['file'];
        foreach ($file_values as $key => $value) {
          if (is_scalar($value) && !isset($t_args['!' . $key])) {
            $t_args['!' . $key] = $value;
          }
        }
      }
      $output['file'] = t('File: !filename', $t_args);
      if ($settings['compare_description_field'] && !empty($instance['settings']['description_field'])) {
        if (!empty($item['description'])) {
          $output['description'] = t('Description: !description', $t_args);
        }
      }
      if ($settings['show_id']) {
        $output['fid'] = t('File ID: !fid', $t_args);
      }
      if ($settings['compare_display_field'] && !empty($field['settings']['display_field'])) {
        $output['display'] = $item['display'] ? t('Displayed') : t('Hidden');
      }
      $separator = $settings['property_separator'] == 'nl' ? "\n" : $settings['property_separator'];
      $diff_items[$delta] = implode($separator, $output);
    }
  }
  return $diff_items;
}