Problem/Motivation

While working with content moderation and the paragraphs module. Having some paragraphs with untranslatable fields, and collapsing the paragraphs, after the ajax event we get a duplicated Fields that apply to all languages are hidden to avoid conflicting changes over the paragraph field.

After an ajax action:

This also happens with just Drupal Core after saving a node:

The problem is that drupal_set_message() should not be used in form builders/alters as it's unpredictable when it runs.. An initial submit without an ajax action first results in the form being built again as does every form rebuild, typically done on ajax actions.

Proposed resolution

Convert the message to a render array.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#53 multiple_warning_message_3002571_update.patch5.19 KBkavbiswa
#51 interdiff.txt1.35 KBlauriii
#47 multiple_warning_message_3002571-47-interdiff.txt1000 bytesberdir
#47 multiple_warning_message_3002571-47.patch7 KBberdir
#46 multiple_warning_message_3002571-46-interdiff.txt2.87 KBberdir
#46 multiple_warning_message_3002571-46.patch7 KBberdir
#45 multiple_warning_message_3002571-45-interdiff.txt3.96 KBberdir
#45 multiple_warning_message_3002571-45.patch5.94 KBberdir
#43 multiple_warning_message_3002571-43.patch4.07 KBberdir
#39 3002571-patch_apply.jpg12.68 KBgaurav-mathur
#37 reroll_diff_33-37.txt4.62 KBstephaneq
#37 multiple_warning_message_3002571-37.patch7.29 KBstephaneq
#33 interdiff-31-33.txt1.16 KBanandhi karnan
#33 multiple_warning_message_3002571-33.patch7.67 KBanandhi karnan
#31 interdiff_29-31.txt969 bytesravi.shankar
#31 3002571-31.patch6.33 KBravi.shankar
#29 interdiff-25-27.txt3.91 KBkishor_kolekar
#29 multiple_warning_messages-3002571-27.patch6.34 KBkishor_kolekar
#26 multiple_warning_messages-3002571-26.patch2.4 KBkishor_kolekar
#25 multiple_warning_messages-3002571-25.patch2.43 KBberdir
#14 Selection_385.png38.31 KBberdir
#12 interdiff-3002571-9-12.txt534 bytesjohnchque
#12 multiple_warning_messages-3002571-12.patch2.39 KBjohnchque
#12 multiple_warning_messages-3002571-12-test-only.patch1.13 KBjohnchque
#9 interdiff-3002571-4-9.txt1.15 KBjohnchque
#9 multiple_warning_messages-3002571-9.patch2.3 KBjohnchque
#9 multiple_warning_messages-3002571-9-test-only.patch1.13 KBjohnchque
#8 Selection_381.png21.75 KBberdir
#4 interdiff-3002571-2-4.txt935 bytesjohnchque
#4 multiple_warning_messages-3002571-4.patch2.34 KBjohnchque
#4 multiple_warning_messages-3002571-4-test-only.patch1.13 KBjohnchque
#2 multiple_warning_messages-3002571-2.patch1.21 KBjohnchque
Screenshot from 2018-09-26 12-33-23.png36.79 KBjohnchque

Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB

This should fix it. Not sure how to test this without Paragraphs.

berdir’s picture

Testing that is easy, it doesn't just happen on ajax requests. It also happens if you just submit the form, then you see that message on the node page. there's propably a test looking for this message. Extend it to make sure that the message doesn't show up after submitting.

johnchque’s picture

Indeed, adding tests. :)

The last submitted patch, 4: multiple_warning_messages-3002571-4-test-only.patch, failed testing. View results

berdir’s picture

I think we have to use #theme status_messages instead of hardcoded the classes.

Basically what \Drupal\Core\Render\Element\StatusMessages::renderMessages() does. It's a bit unfortunate that we have to duplicate the label s (at least the one we actually need).

I also think that this isn't really a warning, there's nothing wrong/problematic, nothing could be done differently, so a blue info would work better but status messages can't do that. I'd suggest to change that elsewhere if we think it should be.

berdir’s picture

Status: Needs review » Needs work
berdir’s picture

Issue summary: View changes
StatusFileSize
new21.75 KB

Also added a screenshot to the summary that shows how this looks after saving which is the problem that's much easier to reproduce.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB
new2.3 KB
new1.15 KB

True, this should work better. :)

The last submitted patch, 9: multiple_warning_messages-3002571-9-test-only.patch, failed testing. View results

berdir’s picture

Status: Needs review » Needs work

What you are missing now is the #status_headings label for warning, I think we should include that too. as long as we are displaying it as a warning message.

johnchque’s picture

Status: Needs work » Needs review
StatusFileSize
new1.13 KB
new2.39 KB
new534 bytes

Indeed, adding it. :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me now.

No opinion on whether this should be added to 8.6 or not, it is IMHO a bug but not that important. And also a minor behavior change, in case someone was e.g. trying to change that specific message.

Lets see what our frontend maintainers think about this approach :)

berdir’s picture

StatusFileSize
new38.31 KB

Created #3004334: Messages about hidden untranslatable fields and pending revisions as a follow-up.

Also realized that drupal.org actually has the same bug, the security warning also repeats when you upload a file :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: multiple_warning_messages-3002571-12.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Reviewed & tested by the community

Strange, this was already RTBC. :/

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: multiple_warning_messages-3002571-12.patch, failed testing. View results

johnchque’s picture

Status: Needs work » Reviewed & tested by the community

Unrelated fail.

alexpott’s picture

Status: Reviewed & tested by the community » Needs review

Hmmm. I think we should have a more generic fix as this can happen with any message like this. Shouldn't the AJAX code that adds the messages to the screen check to see if the message is already there? This is similar to the $repeat functionality. I checked to see if #77245: Provide a common API for displaying JavaScript messages addresses this but it doesn't.

+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -595,7 +595,15 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat
-      $this->messenger->addWarning($this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]));
+      $message['warning'][] = $this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]);
+      $element['hidden_fields_warning_message'] = [
+        '#theme' => 'status_messages',
+        '#message_list' => $message,
+        '#weight' => -100,
+        '#status_headings' => [
+          'warning' => $this->t('Warning message'),
+        ]
+      ];

Doesn't this change move the message from the common status message block to it's own block. That feels a bit off.

berdir’s picture

> Shouldn't the AJAX code that adds the messages to the screen check to see if the message is already there? This is similar to the $repeat functionality. I checked to see if #77245: Provide a common API for displaying JavaScript messages addresses this but it doesn't.

It's not just ajax that is affected, it's enough to simply submit the form and then you see the message again on the node page.

I don't think this can be solved generically/automatically. If anything, we'd need a rule/guideline that form-building must not use the message API.

> Doesn't this change move the message from the common status message block to it's own block. That feels a bit off.

It does, but I don't think that is wrong. It's not a notification message that should pop up wherever the theme wants it, it belongs specifically to that form.. e.g. imagine edit forms in dialogs or so.

alexpott’s picture

  1. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -595,7 +595,15 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat
         if ($display_warning && !$form_state->isSubmitted() && !$form_state->isRebuilding()) {
    

    Do we need the !$form_state stuff now then?

  2. +++ b/core/modules/content_translation/src/ContentTranslationHandler.php
    @@ -595,7 +595,15 @@ public function entityFormSharedElements($element, FormStateInterface $form_stat
    +      $message['warning'][] = $this->t('Fields that apply to all languages are hidden to avoid conflicting changes. <a href=":url">Edit them on the original language form</a>.', [':url' => $url]);
    +      $element['hidden_fields_warning_message'] = [
    +        '#theme' => 'status_messages',
    +        '#message_list' => $message,
    +        '#weight' => -100,
    +        '#status_headings' => [
    +          'warning' => $this->t('Warning message'),
    +        ]
    +      ];
    

    Isn't one issue that if there is something that is adding a message to the page - for example the node access rebuild message then this change will break how multiple messages are normally listed together? Ie. normally all the warnings are grouped together.

berdir’s picture

That's true, but I do believe that a warning message for this is anyway the wrong pattern, which is why I created #3004334: Messages about hidden untranslatable fields and pending revisions.

A warning message indicates a problem/something that user did wrong or at least that he needs to be careful about or so. That's IMHO not the case here, everything is working exactly like it should, we just don't have any UX pattern for telling the user that and why some fields are now not visible :)

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

berdir’s picture

StatusFileSize
new2.43 KB

Reroll due to a conflict in the test, no other changes. There was a test fail on 8.9, so this is likely going to fail too.

kishor_kolekar’s picture

patch #25 Failed to Apply.
Added new patch please review.

berdir’s picture

Version: 8.9.x-dev » 9.2.x-dev
berdir’s picture

Forgot to update the version, #25 should apply on 9.2

kishor_kolekar’s picture

Thanks for the update @Berdir
as #25 Custom command failed try to solve this added new patch.
sorry forgot to update patch no.

Status: Needs review » Needs work

The last submitted patch, 29: multiple_warning_messages-3002571-27.patch, failed testing. View results

ravi.shankar’s picture

StatusFileSize
new6.33 KB
new969 bytes

Fixing failed tests of patch #29.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anandhi karnan’s picture

Status: Needs work » Needs review
StatusFileSize
new7.67 KB
new1.16 KB

Here is the fix for failed test patch of #31.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

stephaneq’s picture

This issue still occurs on Drupal 9.5.x, I rerolled the patch from #33.

gaurav-mathur’s picture

Assigned: Unassigned » gaurav-mathur
gaurav-mathur’s picture

StatusFileSize
new12.68 KB

Hi Patch #37 applied successfully on Drupal 10.1.x
The patch work properly for me.
Thanks.

gaurav-mathur’s picture

Assigned: gaurav-mathur » Unassigned
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs usability review

From what I can tell the points in #21 have not been addressed/answered. Maybe @berdir answers #21.2

Tagging for usability review for the phrase.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new4.07 KB

I discussed this a bit with @laurii at DevDays23 and he pointed me to the fact that something very similar has been done in \Drupal\ckeditor5\Plugin\Editor\CKEditor5::buildConfigurationForm() if for slightly different reasons. But I think that would have similar problems as well with the message repeating on submit and ajax operations.

I still think it makes sense to solve this bug and then think about a generic solution or not using warning messages for this at all. We discussed that the new toggletip might give us some points.

I also cleaned up the patch and removed a lot of unrelated changes and I removed the $form_state check, that should indeed not be required anymore.

Status: Needs review » Needs work

The last submitted patch, 43: multiple_warning_message_3002571-43.patch, failed testing. View results

berdir’s picture

Status: Needs work » Needs review
Issue tags: -Needs usability review
StatusFileSize
new5.94 KB
new3.96 KB

Cleaned up a the kernel test, the previous fix did work before, but only because it didn't actually test the display message part anymore. Now with the removed form state checks, the previous two cases also had the message form element, I fixed them and removed the logic for display warning completely.

No fond of those kind of tests, I don't think they're testing much and are hard to understand and maintain.

Removing the needs usability review tag. I don't think there's something to review here, that you no longer get duplicated messages or a message after saving the node doesn't needs a usability review. The issue that would need one is the follow-up that I created that wants to use a different pattern than warning messages for this.

berdir’s picture

Ok, we can actually clean up quite a bit more in that test as we no longer need those two flags at all.

berdir’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative, +Bug Smash Initiative

Ran the tests without the fix and got

ContentTranslationUntranslatableFieldsTest

Behat\Mink\Exception\ResponseTextException : The text "Fields that apply to all languages are hidden to avoid conflicting changes." appears in the text of this page, but it should not.

ContentTranslationHandlerTest passes without issue.

The fix matches the IS of transforming message to array.

Think this is good!

  • lauriii committed 29ae2445 on 11.x
    Issue #3002571 by johnchque, Berdir, kishor_kolekar, ravi.shankar,...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 29ae244 and pushed to 11.x. Thanks!

Not backporting to 10.1.x because of the small behavior change here.

lauriii’s picture

StatusFileSize
new1.35 KB

I updated the code comment on commit. Here's interdiff for that.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

kavbiswa’s picture

Patch updated for 10.2.x branch.