Hello at all,

I am using a local installation of Drupal version 7.23 with MAMP.

When I am clicking on the preview button to show the preview of a comment, I got the following error:

Notice: Undefined index: format in comment_preview() (line 2071 of /Applications/MAMP/htdocs/.../drupal-7.23-DE/modules/comment/comment.module)

For the comment body in text processing I selected plain text. Is filtered text selected, all works fine and they are no errors display.
I also tried to change the display format into plain text. But that has no effect.

The drupal installation is new (from today) and there is up to now only the CKEditor installed.

These are the steps to get the error.

  • Go to an content type like article and click on edit to enable comments
  • Go to comment fields and click edit to set plain text for text processing
  • Go to comment display and choose plain text at format
  • Choose an article and write an comment
  • Click preview

This issue seems not to be new. I found that old entry from 2010 at https://drupal.org/node/813052 Only the error line is an other.

Can somebody help?
Thanks a lot
Greetings

Comments

balajidharma’s picture

Status: Active » Needs review
StatusFileSize
new685 bytes

This was my fix for it. Upload a solution patch.

Anonymous’s picture

Thank you. :)

I guess the patch works fine.

Now I am not sure about the issue status. Shall I set the status to "reviewed & tested by the community"? I am asking because you an I are the only two people who saying that the patch is working fine...

balajidharma’s picture

Version: 7.23 » 7.x-dev
Status: Needs review » Reviewed & tested by the community

I changed the status to RTBC

David_Rothstein’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs work

This should not be using the "plain_text" format, but rather something like check_plain(). See code in comment_submit() which was added in #813052: Undefined index: format in comment_preview line 2065 and line 2183. Also, the indentation should be fixed (see https://drupal.org/coding-standards#indenting).

I did a quick test of Drupal 8 and I think this bug no longer exists there, so leaving at Drupal 7 for now.

David_Rothstein’s picture

Oh actually, check_plain() is called elsewhere. The issue here is perhaps that $comment->format has no reason to be set at all? See the long discussion in #813052: Undefined index: format in comment_preview line 2065 and line 2183, but somehow that issue got marked fixed without this issue ever being addressed...

David_Rothstein’s picture

pascaz10’s picture

The error is in the function comment_preview.
There is no test about existence of the format key.
Just replace:
$comment->format = $comment_body[0]['format'];
by
if(isset($comment_body[0]['format'])){$comment->format = $comment_body[0]['format'];}

aaronaverill’s picture

9 months for a one line code change.... unreal. un-freaking-real.

aaronaverill’s picture

Status: Needs work » Needs review
johnv’s picture

Status: Needs review » Closed (duplicate)
johnv’s picture

reis quarteu’s picture

Patch #1 works fine for me. Thank you very much! :)

azend’s picture

I've got this issue as well. Was this patch merged into a new version of the module or is it still best to apply the patch here?

johnv’s picture

You should use the patch in the issue in #10

Anonymous’s picture

For those of us who prefer not to patch a core module and are using plain text for comments, consider using a text format specifically for comments. By allowing a minimum amount of HTML (say, making text bold and/or italic) you will be able to view previews without getting the notice / warning.

I gather this bug was fixed a while ago - but somehow the previews weren't patched.

lscook’s picture

In reference to comment #15. I created a Comment text format allowing minimum HTML and configured it for authenticated and admin users. I then assigned ckeditor to the Comment text format in the Wysiwyg profile. In the content type comment fields I set the text processing to filtered text. After doing that I went back into the Comment text format and disabled authenticated user access so that authenticated users would only have access to plain text format. After doing this the comment preview error disappeared. All roles except authenticated users have options for comment text formats. Authenticated users can only comment using the plain text format. Anonymous users have no access to comments. This solved my issue of users receiving an error when previewing comments. The comment preview error may be due to a configuration error.

hip’s picture

Me too. The issue still alive with latest Drupal 7 version.
(Not installing Drupal 8 yet for there's lack of some modules I need)