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.
This issue is to create a new “Views Responsive Grid” format in Drupal 10 core.
Background
We've fixed this in Olivero, and the 10.x solution is fantastic. It injects the number of columns into the markup via inline CSS variables, and also sets a minimum width for the grid cells.
The browser will automatically readjust the column count taking into account the inputted number of columns (which it treats as a maximum value) and the minimum width of the grid cell.
- Codepen demo: https://codepen.io/mherchel/pen/xxXXbog
- Drupal 10.0.x demo: https://3151553-views-grid-responsive--brwh3eo7yvlialqjeyuhkcemop8up7gn....
- CSS in Olivero: https://git.drupalcode.org/project/drupal/-/blob/10.0.x/core/themes/oliv...
Views UI Settings
Responsive horizontal style in action (in Stark theme)
Responsive vertical style in action (in Stark theme)
Testing instructions
- Apply patch (or pull branch) and clear cache
- Create or modify a View that uses the new “Responsive Grid” format (available in the “Format” section of the Views UI
- Go into the settings for this format, and adjust the various options. There are four:
- Maximum number of columns: This is where the grid “wants” to be, if the grid container has space enough so that the grid cells are not under the “Minimum grid cell width” setting.
- Minimum grid cell width: As the grid container is resized, the grid cells with grow shrink to maintain the maximum number of columns. However, once the grid cells reach the “Minimum grid cell width” value, the number of columns will be reduced to maintain this minimum width.
- Grid gutter spacing: This is the space that will be between the grid cells (in pixels). This maps to the CSS
gap
property. - Alignment: these two options are exactly the same as the old “Grid” format. If set to “Horizontal” the Views rows will be ordered left to right (or RTL if needed) and appear in horizontal rows. If set to “Vertical” the grid items will be formatted using CSS columns and be ordered from top to bottom and then left to right (or RTL).
- View the grid page and resize the browser and play around and verify all the settings. Verify it works as expected.
- Test in multiple browsers such as Chromium, Safari, Firefox.
Comment | File | Size | Author |
---|
Issue fork drupal-3151553
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3151553-make-core-views changes, plain diff MR !1585
Comments
Comment #2
mandclu CreditAttribution: mandclu at Northern Commerce commentedI agree, we basically never use the grid view style in core because of its limitations. Something responsive would be a huge improvement.
Comment #5
xjmComment #6
xjmTagging for Views maintainer feedback on whether we can deprecate the row and column classes feature outright, which would be a simpler step than adding the responsive grid display feature (useful in its own right, but more work).
Comment #7
tstoecklerLinking a related issue here. Not sure, it might be a duplicate of this but the issue summary here mentions Olivero whereas that issue is a problem in all core themes (if I remember correctly). But it seems resolving this would resolve that as well, so maybe closing that would be fine?
Comment #9
mherchelWe just committed #3255180: Olivero: Refactor Views Grid Style CSS to take advantage of not having to support IE in Olivero. I'd love to work on this to get this into 10.0.0 Views core.
Adding related issues:
Comment #10
mherchelComment #11
LendudeIn my opinion you are much better off adding a new display. Doing the BC dance with the old one will be much more work and updates tend to end up being fragile.
And this being Views, I'm certain somebody has cooked up something weird with the settings we think are useless and should be removed.
Comment #12
mherchelThanks for the clarification!
Comment #14
mandclu CreditAttribution: mandclu as a volunteer and at Acquia commentedWith all tests passing, including a new unit test for the plugin added, moving this to Needs Review.
Comment #15
Gauravvvv CreditAttribution: Gauravvvv at Srijan | A Material+ Company for Drupal India Association commentedI tested on live preview, both grid view horizontal and grid view vertical. Added the screen-recording for reference. views grid styles are responsive.
Can be move to RTBC.
Comment #16
mherchelUpdating summary
Comment #17
mherchelThanks for the review @Gauravmahlawat, but before RTBC we'll probably need subsystem maintainer review.
Comment #18
mglamanI forgot to reply here, myself, but I gave it a look over and thumbs up from me. This is exciting!
Comment #19
lauriiiGave the MR quick peek and it looks awesome! I hope that we get this in soon 🎉
Comment #20
mherchelUpdated Tugboat link to https://3151553-views-grid-responsive-smap87qfp2e6gy4lp8twqyulyaobwpib.t...
Comment #21
mherchelUpdating tugboat preview to https://3151553-views-grid-responsive--brwh3eo7yvlialqjeyuhkcemop8up7gn....
Comment #22
catchI think this is a bit more than normal.
Should we also look into deprecating the non-responsive grid eventually, or are there still use-cases for that?
Comment #23
mherchelI can't see any use cases for the current grid system anymore. I think it should be deprecated.
Comment #24
andypostI bet there's use-cases and deprecating the format users need to know how to replace it
Comment #25
catchI'm removing 'needs subsystem maintainer review' since @lendude has commented on here.
To actually mark the existing grid deprecated, we'll need #3039240: Create a way to declare a plugin as deprecated which is not in yet.
I'm going to tag this for product manager review - are we OK to add a new plugin without deprecating the old one?
Comment #26
Gábor HojtsyI think its ok to add a new one without depreacting the old one, since the features are not 1-1. In case of the existing core grid, the columns setup stays the same regardless of viewport. I would not suggest anyone to use the non-responsive grid and I would not add that feature to core these days, but it is already there. It is important to gently deprecate it with proper tooling and I don't think this needs that deprecated to be added.
Comment #27
catch#26 makes sense to me - we can open a follow-up to discuss deprecating the old grid layout once this has landed.
Comment #28
mherchelComment #29
mherchelBrought back up to date with 10.0.x
Comment #30
mherchelUpdated Tugboat demo https://3151553-views-grid-responsive--d14gzzrh9d6eirksfgjd68l77nnqbycg....
Comment #31
LendudeIt looks amazing on tugboat.
I'd like to see the test coverage expanded here, we are only testing with 1 set of values and it would be nice to run some different sets. Also the defaults aren't being tested currently.
I would suggest rewriting the test to use a @dataProvider so it becomes easier to test different data sets (one of which could be empty to test the defaults).
Comment #32
mherchelThanks for the reviews! We'll address these shortly :)
Comment #33
darvanenChecked out the CSS, my only hesitation is the negative margin to bring the bounding box in line with the end of the bottom row for the vertical grid because it will likely surprise newer themers.... but then I realised the other option was fielding hundreds of "how do I remove this gap?" questions which is way harder to understand than why a gap is bigger than you intended after setting a margin.... so in short: no further comment on the CSS
Comment #34
mandclu CreditAttribution: mandclu as a volunteer and at Acquia commentedResponding to some earlier feedback:
There's no value in including it because it's only used twice? I'm not sure I follow the logic there. Also, the test associated with this property does validate that the expected class is being applied. That speaks to this comment:
And to respond to the comment by @Lendude in #31:
I'm not against trying to improve what we have here, but I think it's worth pointing out that what is here already is equivalent to what has already been implemented (and accepted into core) for the existing grid view. Could we accept what's here and open a child issue for the expanded test coverage?
Comment #35
danflanagan8Here's what I mean. The new test clearly began as a copy/paste
StyleGridTest.php.
That test ran assertGrid for many more configurations:Some of the assertions only need to be done once per alignment. That's why
StyleGridTest.php.
has$alignmentsTested
: to prevent running redundant assertions.For the new test, there's only one horizontal configuration and one vertical configuration:
So there aren't going to be redundant assertions and we don't need
$alignmentsTested
.But we can't simply remove the declaration of
$alignmentsTested
. We also have to modifysuch that any logic related to
$alignmentsTested
is removed.Alternatively, we could add more cases to
testGrid()
and then$alignmentsTested
would be useful.Comment #36
mandclu CreditAttribution: mandclu as a volunteer and at Acquia commented@danflanagan8 you are spot on that the new test is adapted from the StyleGridTest.php. Unfortunately, writing unit tests isn't one of my strengths, so being able to leverage existing code is a big help. Can you recommend one or more tests elsewhere in core that I could use as examples to write the additional tests / cases needed to provided sufficient coverage here?
Comment #37
danflanagan8After communicating with @mandclu in Slack, I decided to take off my Reviewer Hat and put on my Test Writing Hat. I have pushed some updates that address my concerns with the tests as well as the comments from @lendude in #31.
I also did a rebase where I had to resolve a conflict in Stable9LibrariesOverrideTest. I think I got it right, but the git history looks kind of funky for the rebase. Hopefully I didn't mess anything up. I really struggle with the MR workflow.
Anyone want to review? :)
Comment #38
mherchelThanks for the work on this @danflanagan8!
For some reason, Gitlab said this had a merge error. I merged 10.0.x into it to bring it up to date (Git did not show me any merge conflicts)
Comment #39
danflanagan8Thank you, @mherchel
I must have done something wrong with the rebase I attempted. I'm very thankful you were able to fix it.
Hopefully we can get this across the finish line! As far as I know, the only outstanding task was to enhance the test coverage, which I have addressed. I will be happy to make additional changes to the test coverage if they are requested.
Comment #40
mherchelRemoved the pointless comments and responded to the thought on testing the CSS layout.
Comment #41
mherchelCreated followup #3301797: Create ability to verify CSS layouts in tests
Comment #42
mherchelAnother followup created to deprecate the old "Grid" style: #3301811: [PP-1] Deprecate Views "Grid" style (Now that "Responsive Grid" is being added to core)
Comment #43
LendudeRemoving the 'Needs change record' since that was from a time when we were still thinking about deprecating the old grid here. That has been moved to the follow up so removing the tag here.
Nice to see the discussion on the possible test coverage, interesting to see what happens there.
I don't see anything else to nitpick, so moving to RTBC
Comment #44
catchfwiw I've been running this patch on a site for 3-4 months with no problems (except keeping up with re-rolls). Not doing anything extreme with it, but it's working very well.
Comment #46
lauriiiCommitted 6aed2e9 and pushed to 10.1.x. Thanks!
Leaving open for a backport to 10.0.x once the freeze is over. I don't think this can be backported to 9.x given that this is fundamentally not compatible with IE 11.
Comment #49
lauriiiCherry-picked to 10.0.x.
Comment #50
ressa CreditAttribution: ressa at Ardea commentedThank you so much @mherchel, @mandclu, @danflanagan8, @catch, @Lendude, @lauriii and @Gábor for making this great improvement. It looks amazing. Especially the vertical style with the images automatically resizing and realigning looks almost magical :-)