how to reproduce it:
- disable comment title
- create a comment with the text "abc def"
- preview the comment
- previewed subject is "abc def" (as it should)
- edit the comment body to read "123 def"
- re-preview the comment
- previewed subject still is "abc def" (should be "123 def")
cause:
- comment_form_build_preview doesn't takes into account that having #access=FALSE preserves the #default_value of the first preview in subsequent previews
- previously in D6 the subject field didn't existed when disabled, therefore comment_form_add_preview always had an empty subject and previewed subject was regenerated every time
suggestion:
- if #access==FALSE drop the $form_state['values']['subject'] when building the preview
function comment_form_build_preview($form, &$form_state) {
if (!$form['subject']['#access']) {
$form_state['values']['subject'] = ''; // <<-- it shouldn't be preserved between subsequent previews
}
$comment = comment_form_submit_build_comment($form, $form_state);
$form_state['comment_preview'] = comment_preview($comment);
}
relevance:
- this bug propagates to every module providing default values, therefore, previewing what will become the actual subject wouldn't be possible at all
Comments
Comment #1
arhak commentedBTW, this was introduced by #524652: Overhaul comment form and preview
and there states:
then it might be similar bugs whenever there is a preview with elements having #access=FALSE and generated defaults
is there any other place doing such thing?
Comment #2
arhak commentedtagging
(no patch provided, but a quick review would say if the proposed fix worth it)
Comment #3
arhak commentedactually no, I did some tests, and actually the way it is preserves #default_value passed through $form_state['values'] (as intended)
but, core's default behavior does breaks
not big deal, just re-preview doesn't displays an accurate title
if comment body is completely rewritten the user might find awkward to keep viewing an unrelated subject on re-preview (it might be a WTF, when user decides to discard the comment and post a new one to get rid of that sticky wrong preview)
Comment #4
asimmonds commentedStill a issue in HEAD