You are here

function theme_coder_review_warning in Coder 7.2

Same name and namespace in other branches
  1. 7 coder_review/coder_review.module \theme_coder_review_warning()

Returns HTML for a coder_review warning to be included in results.

Parameters

array $variables: An associative array, which includes the following keys:

  • warning: Either summary warning description, or an array in format:

    • #warning: A summary warning description.
    • #description: A detailed warning description.
    • #link: A link to an explanatory document.
  • severity_name: The severity name as a string.
  • lineno: An integer line number on which error was detected.
  • line: A string with the contents of line.
  • review_name: A string with the review name.
  • rule_name: A string with the rule name.
1 call to theme_coder_review_warning()
do_coder_reviews in coder_review/coder_review.common.inc
Performs coder reviews for multiple code review definition files.
1 theme call to theme_coder_review_warning()
do_coder_reviews in coder_review/coder_review.common.inc
Performs coder reviews for multiple code review definition files.

File

coder_review/coder_review.common.inc, line 274
Common functions used by both the drush and form interfaces.

Code

function theme_coder_review_warning($variables) {

  // Theme the output for the Drupal shell.
  if (_drush()) {
    return theme_drush_coder_review_warning($variables);
  }
  $warning = $variables['warning'];
  $severity_name = $variables['severity_name'];
  $review_name = $variables['review_name'];
  $rule_name = $variables['rule_name'];
  $lineno = $variables['lineno'];
  $line = $variables['line'];

  // Extract description from warning.
  if (is_array($warning)) {
    $description = isset($warning['#description']) ? _t($warning['#description']) : '';
    if (isset($warning['#warning'])) {
      $warning_msg = _t($warning['#warning']);
    }
    elseif (isset($warning['#text'])) {
      $warning += array(
        '#args' => array(),
      );
      $warning_msg = _t($warning['#text'], $warning['#args']);
    }
    if (isset($warning['#link'])) {
      $warning_msg .= ' (' . l(_t('Drupal Docs'), $warning['#link']) . ')';
    }
    $warning = $warning_msg;
  }
  if ($lineno) {
    if ($lineno > 0) {
      $warning = _t('Line @number: !warning [@review_@rule]', array(
        '@number' => $lineno,
        '!warning' => $warning,
        '@review' => $review_name,
        '@rule' => $rule_name,
      ));
    }
    else {
      $warning = _t('File: !warning [@review_@rule]', array(
        '!warning' => $warning,
        '@review' => $review_name,
        '@rule' => $rule_name,
      ));
    }
    if ($line) {
      $warning .= '<pre>' . check_plain($line) . '</pre>';
    }
  }

  // Add informative images and classes to the output.
  $class = 'coder-warning';
  if ($severity_name) {
    $class .= " coder-{$severity_name}";
  }
  $path = _coder_review_path() . '/..';
  $title = _t('severity: @severity', array(
    '@severity' => $severity_name,
  ));
  $img = theme('image', array(
    'path' => $path . "/images/{$severity_name}.png",
    'alt' => $title,
    'title' => $title,
    'attributes' => array(
      'align' => 'right',
      'class' => 'coder',
    ),
    'getsize' => FALSE,
  ));
  $avail_reviews = _coder_review_reviews();
  if (isset($avail_reviews[$review_name]['#image'])) {
    $title = _t('review: @review_@rule', array(
      '@review' => $review_name,
      '@rule' => $rule_name,
    ));
    $review_image = $avail_reviews[$review_name]['#image'];
    $img .= theme('image', array(
      'path' => (substr($review_image, 0, 7) == 'images/' ? "{$path}/" : '') . $review_image,
      'alt' => $title,
      'title' => $title,
      'attributes' => array(
        'align' => 'right',
        'class' => 'coder-review',
      ),
      'getsize' => FALSE,
    ));
  }
  if (!empty($description)) {
    $img .= theme('image', array(
      'path' => $path . '/images/more.png',
      'alt' => t('click to read more'),
      'atributes' => array(
        'align' => 'right',
        'class' => 'coder-more',
      ),
      'getsize' => FALSE,
    ));
    $warning .= '<div class="coder-description">' . t('Explanation: @description', array(
      '@description' => $description,
    )) . '</div>';
  }
  return '<div class="' . $class . '">' . $img . $warning . '</div>';
}