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.
Problem/Motivation
On node pages there is a node type class of the form page-node-type-[node-type] however this class is not present on node preview pages, leading to preview pages not having the same styles as normal node view pages.
Proposed resolution
Add the node type class to the node preview pages also.
Comments
Comment #2
rooby CreditAttribution: rooby commentedHere is a patch to add the class.
Comment #4
BerdirGood catch, see also #2834316: Node preview shows and defaults to "Default" instead of "Full" view mode for more preview theming/template fun.
Should be easy to add an assertion in an existing node preview test.
Comment #6
LoMo CreditAttribution: LoMo as a volunteer commentedI've added an assertion to the PagePreviewTest. It correctly finds the new node type class added on the preview body element.
The patch containing only tests should FAIL (correctly). The "complete" patch should pass and includes the original fix for the issue as well as the new tests. Hope we can get this moved along to RTBC, ASAP. ;-)
Comment #7
LoMo CreditAttribution: LoMo as a volunteer commentedBefore the nitpicking police show up and point out that my comment was missing a period at the end... ;-)
(Fix according to Drupal standards. Ignore patches uploaded in #6, though functionally the same.)
Comment #10
LoMo CreditAttribution: LoMo as a volunteer commentedRe #8 and #9, this is what we hoped to see... the tests fail if the patch is not applied. With the fix and tests together (drupal-node_type_preview_class-2736391-7-complete.patch), tests pass. Since the difference between the #6 complete and #7 complete is trivial (missing period added to end inline comment, per Drupal coding standards), we have seen the new test pass twice with the patch.
Comment #13
Anas_maw CreditAttribution: Anas_maw as a volunteer commentedThe patch in 7 worked for me perfectly, this should be set to RTCB
Thank you.
Comment #14
lauriiiThank you for your work on the issue! This change will cause small change for the
node_type
variable in the html template, but I think it is reasonable to assume that the preview page and the node page are rendered with same parameters. Let's create a small change record stating that thenode_type
variable is now set also on the preview pages.Comment #15
lauriiiComment #16
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedI'll work on the change record.
Comment #17
leolandotan CreditAttribution: leolandotan as a volunteer and at Promet Source commentedI have created the change record in Add node type to node preview page body class.
Hope everything is in order.
Thanks!
Comment #18
lauriiiThanks for creating the change record. Looks good!
Comment #19
catchCommitted 2f9be00 and pushed to 8.6.x. Thanks!