You are here

function text_field_diff_view in Diff 7.3

Diff field callback for parsing text field comparative values.

File

includes/text.inc, line 11
Provide diff field functions for the Text module.

Code

function text_field_diff_view($items, $context) {
  $field = $context['field'];
  $instance = $context['instance'];
  $settings = $context['settings'];
  $diff_items = array();
  foreach ($items as $delta => $item) {
    $diff_items[$delta] = array();

    // Compute the format for appending to the label.
    $format_text = '';
    if ($instance['settings']['text_processing'] && $settings['compare_format']) {
      $format_id = empty($item['format']) ? filter_fallback_format() : $item['format'];
      if ($format = filter_format_load($format_id)) {
        $format_text = $format->name;
      }
      else {
        $format_text = t('Missing format !format', array(
          '!format' => $format_id,
        ));
      }
    }

    // Compare the summary fields.
    $summary = $field['type'] == 'text_with_summary' && $settings['compare_summary'];
    if ($summary) {

      // Allow users to optionally clean system specific characters.
      if (empty($item['summary'])) {
        $diff_items[$delta][] = t('Summary field is empty.');
      }
      else {
        if ($format_text) {
          $diff_items[$delta][] = t('Summary (!text_format):', array(
            '!text_format' => $format_text,
          ));
        }
        else {
          $diff_items[$delta][] = t('Summary:');
        }
        $diff_items[$delta][] = diff_normalise_text($item['summary']);
      }
    }

    // Only show label if field has summary displayed.
    if ($summary) {
      if ($format_text) {
        $diff_items[$delta][] = t('Content (!text_format):', array(
          '!text_format' => $format_text,
        ));
      }
      else {
        $diff_items[$delta][] = t('Content:');
      }
    }

    // Allow users to optionally clean system specific characters.
    $diff_items[$delta][] = diff_normalise_text($item['value']);

    // If no summary, append the format selection to the bottom of the screen.
    // This prevents adding the "Content (format)" label.
    if ($format_text && !$summary) {
      $diff_items[$delta][] = t('Text format: !text_format', array(
        '!text_format' => $format_text,
      ));
    }
    $diff_items[$delta] = $diff_items[$delta];
  }
  return $diff_items;
}