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
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | comment_preview_error_for_plain_text-2077901-8.patch | 639 bytes | aaronaverill |
| #1 | comment_preview_error_for_plain_text-2077901-1.patch | 685 bytes | balajidharma |
Comments
Comment #1
balajidharmaThis was my fix for it. Upload a solution patch.
Comment #2
Anonymous (not verified) commentedThank 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...
Comment #3
balajidharmaI changed the status to RTBC
Comment #4
David_Rothstein commentedThis 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.
Comment #5
David_Rothstein commentedOh 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...
Comment #6
David_Rothstein commentedAlso marked a couple issues as duplicate of this one (even though they are older, this one has a patch):
#1214854: Notice: Undefined index: format in comment preview () (line 2043 of/mysite.com/public_html/modules/comment/comment.module
#1543170: Undefined index: format in comment_preview()
Comment #7
pascaz10 commentedThe 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'];}
Comment #8
aaronaverill commented9 months for a one line code change.... unreal. un-freaking-real.
Comment #9
aaronaverill commentedComment #10
johnvThis is handled in the D7-patch of #1038652: Notices in comment_submit() and comment_admin_overview() when body field does not exist or is not required (comment #95 or later)
Comment #11
johnvAdding the issue from #10.
Comment #12
reis quarteu commentedPatch #1 works fine for me. Thank you very much! :)
Comment #13
azend commentedI'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?
Comment #14
johnvYou should use the patch in the issue in #10
Comment #15
Anonymous (not verified) commentedFor 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.
Comment #16
lscook commentedIn 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.
Comment #17
hip commentedMe too. The issue still alive with latest Drupal 7 version.
(Not installing Drupal 8 yet for there's lack of some modules I need)