Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Part 1 :
Go to the bottom of front page and click on “contact”
Fill the “subject” and “message” fields and click on preview
Check the result: you should see the preview of your message under the message input area. It's the expected behavior.
Part 2 :
Go to /admin/structure/contact
Select “manage form display” for the selected contact form (“Website feedback”)
Sort fields by avoiding weight negative values
Save, restart the part 1 and see the result : contact message preview appears random form position.
We can't simply set some static weight to the container preview, as it can be different for other fields according to “manage form display” Contact page settings. My suggestion is to make preview position configurable like any other Contact page field. Then we will have weight defined by default as well as a new weight for container preview if something will be changed in the display settings. Patch attached.
Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.
Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.
Yeah, it is at the bottom by default, so a default weight of 40 means there is a pretty good chance that it is still at the bottom by default when applying this patch.
I also don't think this needs an update function. Entity displays update themself automatically with extra and base field definitions, Manually verified that this works fine, it just needs a cache clear. We could add an empty update function to enforce that happens, but IMHO, that's overkill for an addition like this, there are probably other update functions and nothing is broken (not more than without the patch, that is) until you do clear the cache.
Patch unfortunately had a trivial conflict due to an array() => [] change, re-uploading, hope it's still OK if I RTBC.. attaching an actual diff of the two patches to show that I changed nothing, it's just the context that changed.
Comments
Comment #1
andypostComment #2
andypostComment #3
andypostProblem is \Drupal\contact\MessageForm::form() - preview have no weight assigned
Comment #4
fil00dl CreditAttribution: fil00dl at Skilld commentedHere is the test scenario to trigger the bug :
Part 1 :
Go to the bottom of front page and click on “contact”
Fill the “subject” and “message” fields and click on preview
Check the result: you should see the preview of your message under the message input area. It's the expected behavior.
Part 2 :
Go to /admin/structure/contact
Select “manage form display” for the selected contact form (“Website feedback”)
Sort fields by avoiding weight negative values
Save, restart the part 1 and see the result : contact message preview appears random form position.
Comment #5
OleksiyWe can't simply set some static weight to the container preview, as it can be different for other fields according to “manage form display” Contact page settings. My suggestion is to make preview position configurable like any other Contact page field. Then we will have weight defined by default as well as a new weight for container preview if something will be changed in the display settings. Patch attached.
Comment #6
andypostAlso we need test to make sure that preview is always on top (like min element weight -1)
I won't work, because fields could be reordered in UI but preview should be always above
Comment #7
andypostfor tests
Comment #9
larowlanadding a test
Comment #10
larowlanComment #12
andypostThanx, looks great, just a question of BC... do we need update hook?
Comment #13
alexpott#6 @andypost says that the field should always be on top... but the fix suggests that we allow re-ordering.
And yes I think we should have an update.
Comment #14
alexpottAlso #6 seems to contradict #4 - I think #4 is right - the preview should be at the bottom of the form by default.
Comment #16
BerdirYeah, it is at the bottom by default, so a default weight of 40 means there is a pretty good chance that it is still at the bottom by default when applying this patch.
I also don't think this needs an update function. Entity displays update themself automatically with extra and base field definitions, Manually verified that this works fine, it just needs a cache clear. We could add an empty update function to enforce that happens, but IMHO, that's overkill for an addition like this, there are probably other update functions and nothing is broken (not more than without the patch, that is) until you do clear the cache.
Patch unfortunately had a trivial conflict due to an array() => [] change, re-uploading, hope it's still OK if I RTBC.. attaching an actual diff of the two patches to show that I changed nothing, it's just the context that changed.
Comment #18
andypostrandom fail
Comment #20
BerdirMore random fails.
Comment #21
alexpottComment #22
alexpottCommitted and pushed 57fdb94 to 8.3.x and 05c29b2 to 8.2.x. Thanks!