You are here

function profile2_diff_profile2_form_preview_changes in Profile 2 7.2

Callback if 'View changes' is pressed.

The profile form architecture allows for more than one profile form on one edit page, although in practice this never happens, but for consistency we maintain this approach.

1 string reference to 'profile2_diff_profile2_form_preview_changes'
profile2_diff_form_profile2_form_alter in contrib/profile2_diff.module
Implements hook_form_alter().

File

contrib/profile2_diff.module, line 198
Provides functionality to show a diff between two profile2 revisions.

Code

function profile2_diff_profile2_form_preview_changes($form, &$form_state) {
  module_load_include('inc', 'profile2_diff', 'profile2_diff.pages');

  // Clone the existing profile(s) for later comparison.
  foreach ($form_state['profiles'] as $type => $profile) {
    $old_profiles[$type] = clone $profile;
  }

  // Build the profile object(s) within the form_state.
  // If there are multiple profile forms, this processes all of them.
  profile2_form_submit_build_profile($form, $form_state);

  // Generate a diff for each profile.
  $changes = '';
  foreach ($form_state['profiles'] as $type => $new_profile) {

    // Create diff of old node and edited node
    $state = variable_get('diff_default_state_profile2', 'raw');
    $rows = _profile2_diff_body_rows($old_profiles[$type], $new_profile, $state);

    // Build the table with the list of changes.
    $cols = _diff_default_cols();
    $header = _diff_default_header(t('Original'), t('Changes'));
    $changes .= theme('table__diff__preview', array(
      'header' => $header,
      'rows' => $rows,
      'attributes' => array(
        'class' => array(
          'diff',
        ),
      ),
      'colgroups' => $cols,
      'sticky' => FALSE,
    ));

    // Restore the old profile in the form state, otherwise successive
    // use of View Changes will cascade the differences.
    $form_state['profiles'][$type] = $old_profiles[$type];
  }

  // Attach diff to form state, is added to form in hook_form_alter().
  $form_state['profile_preview'] = $changes;
  $form_state['rebuild'] = TRUE;
}