You are here

function _taxonomy_revision_diff_body_rows in Taxonomy revision 7

Creates an array of rows which represent the difference between terms.

Parameters

object $old_term: Term for comparison which will be displayed on the left side.

object $new_term: Term for comparison which will be displayed on the right side.

boolean $state: The state to render for the diff.

1 call to _taxonomy_revision_diff_body_rows()
taxonomy_revision_diffs_show in ./taxonomy_revision.pages.inc
Create a comparison for the term between versions 'old_revision_id' and 'new_revision_id'.

File

./taxonomy_revision.pages.inc, line 271
UI pages for revisions, similar with pages from node.pages.inc.

Code

function _taxonomy_revision_diff_body_rows($old_term, $new_term, $state = 'raw') {

  // This is an unique index only, so no need for drupal_static().
  static $table_row_counter = 0;
  if ($theme = variable_get('diff_theme', 'default')) {
    drupal_add_css(drupal_get_path('module', 'diff') . "/css/diff.{$theme}.css");
  }
  module_load_include('inc', 'diff', 'includes/taxonomy');
  $rows = array();
  $any_visible_change = FALSE;
  $context = array(
    'entity_type' => 'taxonomy_term',
    'states' => array(
      $state,
    ),
    'view_mode' => 'diff_standard',
  );
  module_load_include('inc', 'diff', 'diff.pages');
  $term_diffs = diff_compare_entities($old_term, $new_term, $context);

  // Track line numbers between multiple diffs.
  $line_stats = array(
    'counter' => array(
      'x' => 0,
      'y' => 0,
    ),
    'offset' => array(
      'x' => 0,
      'y' => 0,
    ),
  );

  // Render diffs for each.
  foreach ($term_diffs as $term_diff) {
    $show_header = !empty($term_diff['#name']);

    // These are field level settings.
    if ($show_header && isset($term_diff['#settings']['show_header'])) {
      $show_header = $show_header && $term_diff['#settings']['show_header'];
    }

    // Line counting and line header options.
    if (empty($term_diff['#settings']['line_counter'])) {
      $line_counter = FALSE;
    }
    else {
      $line_counter = $term_diff['#settings']['line_counter'];
    }

    // Every call to 'line' resets the counters.
    if ($line_counter) {
      $line_stats['counter']['x'] = 0;
      $line_stats['counter']['y'] = 0;
      if ($line_counter == 'line' && 0) {
        $line_stats['offset']['x'] = 0;
        $line_stats['offset']['y'] = 0;
      }
      $line_stats_ref = $line_stats;
    }
    else {
      $line_stats_ref = NULL;
    }
    list($old, $new) = diff_extract_state($term_diff, $state);
    if ($term_diff_rows = diff_get_rows($old, $new, $line_counter && $line_counter != 'hidden', $line_stats_ref)) {
      if ($line_counter && $line_counter != 'line') {
        $line_stats['offset']['x'] += $line_stats_ref['counter']['x'];
        $line_stats['offset']['y'] += $line_stats_ref['counter']['y'];
      }
      if ($show_header) {
        $rows['diff-header-' . $table_row_counter++] = array(
          array(
            'data' => t('Changes to %name', array(
              '%name' => $term_diff['#name'],
            )),
            'class' => 'diff-section-title',
            'colspan' => 4,
          ),
        );
      }

      // To avoid passing counter to the Diff engine, index rows manually here
      // to allow modules to interact with the table. i.e. no array_merge().
      foreach ($term_diff_rows as $row) {
        $rows['diff-row-' . $table_row_counter++] = $row;
      }
      $any_visible_change = TRUE;
    }
  }
  if (!$any_visible_change) {
    $rows['diff-empty-' . $table_row_counter++] = array(
      array(
        'data' => t('No visible changes'),
        'class' => 'diff-section-title',
        'colspan' => 4,
      ),
    );

    // @todo: revise this.
    // Needed to keep safari happy.
    $rows['diff-empty-' . $table_row_counter++] = array(
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
      array(
        'data' => '',
      ),
    );
  }
  return $rows;
}