Fatal error: Cannot use string offset as an array ... in nodeformsettings/commentformsettings/commentformsettings.module

Submitted by ionut on 21/12/2011

Node and Comments Form Settings module for Drupal seems to have a small bug in its code...

After installing it I got this ugly error.

After a few searches on google, I decided to dive into the code and see what is causing it. 

On line 264 in commentformsettings.module there is a theme function which alters the comment form called phptemplate_box(). Inside it there is a call to commentformsettings_get_settings() which seem to return an empty value and the routine after this call doesn't handle this possibilty. A quick fix for this was to add an If statement before which checks if the result of the previous call is not empty.  Below is the modified function code: 

 

function phptemplate_box($title, $content, $region = 'main') {
$node = menu_get_object();
if(isset($node)) {
$settings = commentformsettings_get_settings($node->type);

if (!empty($settings)) {

    if($title == "Post new comment" && $settings['cfs_pnc']['cfs_post_new_comment'] == 1 && isset($settings['cfs_pnc']['cfs_post_new_comment_value'])) {
       $title = '';
    }

    if($title == "Post new comment" && $settings['cfs_pnc']['cfs_post_new_comment'] == 2 && isset($settings['cfs_pnc']['cfs_post_new_comment_value'])) {
       $title = t($settings['cfs_pnc']['cfs_post_new_comment_value']);
    }

    if(isset($settings['cfs_pnc']['cfs_post_new_comment_tag'])) {
      $output = '<'. $settings['cfs_pnc']['cfs_post_new_comment_tag'] .' class="title">'. $title .'</' . $settings['cfs_pnc']['cfs_post_new_comment_tag'] .'><div>'. $content .'</div>';
    }
    else {
         $output = '<h2 class="title">'. $title .'</h2><div>'. $content .'</div>';
    };
 };

}

else {
       // Default value
       $output = '<h2 class="title">'. $title .'</h2><div>'. $content .'</div>';
}

      return $output;
}

 

Until a module update or an "official" patch I think this is a viable solution...

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Refresh Type the characters you see in this picture. Type the characters you see in the picture; if you can't read them, submit the form and a new image will be generated. Not case sensitive.  Switch to audio verification.