You are here

function profile2_diff_entity_view_alter in Profile 2 7.2

Implementation of hook_entity_view_alter().

File

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

Code

function profile2_diff_entity_view_alter(&$build) {
  if (isset($build['#entity_type']) && $build['#entity_type'] == 'profile2') {
    $profile = $build['#entity'];
    if (_profile2_revision_access($profile, array(
      'view own profile revisions',
      'view any profile revisions',
    ))) {
      $enabled_types = variable_get('profile2_diff_show_diff_inline_types', array());
      if (!empty($enabled_types[$profile->type])) {
        $path = current_path();
        $base_path = _profile2_revision_base_path($profile, TRUE);
        if (strpos($path, $base_path) === 0 && strpos($path, '/view/') == strlen($base_path)) {
          module_load_include('inc', 'profile2_diff', 'profile2_diff.pages');
          module_load_include('inc', 'diff', 'diff.pages');

          // Allow for old vid as extra URL arg.
          $count = count(explode('/', $base_path));
          $old_vid = arg($count + 2);
          $build = array(
            '#markup' => profile2_diff_inline_show($profile, $old_vid),
          );
        }
        $tmp = isset($build['#prefix']) ? $build['#prefix'] : '';
        $build['#prefix'] = "<div id='diff-inline-{$profile->pid}'>" . $tmp;
        $tmp = isset($build['#suffix']) ? $build['#suffix'] : '';
        $build['#suffix'] = $tmp . '</div>';
      }
    }
  }
}