You are here

function dialog_comment_comment_view in Dialog 7.2

Same name and namespace in other branches
  1. 7 modules/dialog_comment/dialog_comment.module \dialog_comment_comment_view()

Implement hook_comment_view().

File

modules/dialog_comment/dialog_comment.module, line 19
Provides dialog integration for comment.module.

Code

function dialog_comment_comment_view($comment, $view_mode, $langcode) {

  // Attach the library for handling the dialog in the response.
  $comment->content['#attached']['library'][] = array(
    'system',
    'drupal.ajax',
  );

  // Modify the comment links.
  $links = isset($comment->content['links']['comment']['#links']) ? $comment->content['links']['comment']['#links'] : array();
  if (isset($links['comment-delete'])) {

    // Use a dialog for deleting comments.
    $links['comment-delete']['attributes']['class'][] = 'use-ajax';
    $links['comment-delete']['attributes']['data-dialog'] = 'true';
    $links['comment-delete']['attributes']['data-dialog-options'] = '{"width":"50%"}';
  }

  // Set the links back in their place.
  if (isset($comment->content['links']['comment']['#links'])) {
    $comment->content['links']['comment']['#links'] = $links;
  }
}