You are here

function comment_goodness_preprocess_comment_wrapper in Comment goodness 7

Implements hook_preprocess_HOOK().

Provide a template variable to vary the placement of the comment form; either above or below the comments dependent on the sort order. For ASC sorted comments, the comment form is placed at the bottom of the list, near the newest comment. For DESC sorted comments, the comment form is placed above the comments, again, near the newest comment.

File

./comment_goodness.module, line 491
Comment goodness provides newest to oldest comment sorting

Code

function comment_goodness_preprocess_comment_wrapper(&$variables) {

  // Get the configured form placement for this node type.
  $form_placement = variable_get('comment_form_placement_' . $variables['node']->type, comment_goodness_FORM_PLACEMENT_BOTTOM);
  switch ($form_placement) {
    case comment_goodness_FORM_PLACEMENT_TOP:
      $variables['comment_form_placement'] = 'top';
      break;
    case comment_goodness_FORM_PLACEMENT_BOTTOM:
      $variables['comment_form_placement'] = 'bottom';
      break;
    case comment_goodness_FORM_PLACEMENT_SORT:
    default:

      // Bottom placement of the comment form is the Drupal default.
      $variables['comment_form_placement'] = 'bottom';

      // Get the configured default sort ordering for this node type.
      $sort = variable_get('comment_default_sorting_' . $variables['node']->type, comment_goodness_OLDER_FIRST);

      // Indicate that the comment form should be rendered above the comments
      // if the sort order is newest to oldest (ASC).
      if ($sort == comment_goodness_NEWER_FIRST) {
        $variables['comment_form_placement'] = 'top';
      }
      break;
  }

  // Get the section labels
  $comment_section_label = variable_get('comment_section_label_' . $variables['node']->type, comment_goodness_COMMENT_SECTION_LABEL);
  $comment_form_label = variable_get('comment_form_label_' . $variables['node']->type, comment_goodness_COMMENT_FORM_LABEL);

  // Add the labels to the page variables
  $variables['labels'] = array(
    'section_label' => check_plain($comment_section_label),
    'form_label' => check_plain($comment_form_label),
  );
}