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

arhak’s picture

BTW, this was introduced by #524652: Overhaul comment form and preview
and there states:

This patch moves comment preview to use the exact same workflow than node previews

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?

arhak’s picture

Status: Active » Needs review
Issue tags: +Quick fix, +Regression

tagging

(no patch provided, but a quick review would say if the proposed fix worth it)

arhak’s picture

Priority: Normal » Minor
Status: Needs review » Active
Issue tags: -Quick fix

this bug propagates to every module providing default values

actually 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)

asimmonds’s picture

Version: 7.0-alpha1 » 7.x-dev

Still a issue in HEAD

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.