"break" used when should be "return"

lyricnz - January 9, 2009 - 11:40
Project:UpDown
Version:6.x-1.0
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

In the following function, the code checks for $displaymode=='none' before exiting from the function. This should use "return" (from the function) not "break" (from a loop/switch) like it does now.

<?php
function updown_comment_preprocess_comment(&$variables) {
 
$node = $variables['node'];// handy shorthand
  // we allow for different voting options on comments based on the node-type
 
if (variable_get('updown_comment_'. $node->type, FALSE)) {
   
$comment = $variables['comment'];
   
$display_mode = variable_get('updown_comment_display_'. $node->type, 'beginning');
    if (
$display_mode == 'none') {
      break;
// don't double-run the token generator
   
}
   
$widget = (user_access('rate content with updown')) ? theme('updown_active_widget', 'comment', $comment->cid, variable_get('updown_unvote_comment_'. $node->type, FALSE), variable_get('updown_votedown_comment_'. $node->type, TRUE)) : theme('updown_inactive_widget', 'comment', $comment->cid);
    switch (
$display_mode) {
      case
'beginning':
       
// add widget to start of comment content
       
$variables['content'] = $widget . $comment->comment;
        break;
      case
'end':
       
$variables['content'] .= $widget;
        break;
      case
'vars':
       
$variables['updown'] = $widget;
        break;
    }
  }
}
?>

#1

lyricnz - January 9, 2009 - 11:41

And the comment on the same line seems incorrect.

 
 

Drupal is a registered trademark of Dries Buytaert.