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.
With a view setup to use the grid format one of the format settings is "Fill up single line".
Currently this setting does not work with horizontal alignment, but that is a different issue: #1744478: Grid format disregards "number of columns" option for a single line of results
However this issue is to deal with fixing the same functionality with vertical alignment.
This is the change needed, hopefully someone can roll a patch.
/**
* Display a view as a grid style.
*/
function template_preprocess_views_view_grid(&$vars) {
...
- for ($i = 0; $i < count($rows[0]); $i++) {
+ for ($i = 0; $i < $columns; $i++) {
...
}
Comment | File | Size | Author |
---|---|---|---|
#22 | views-n1773798-22.patch | 696 bytes | DamienMcKenna |
| |||
#22 | views-n1773798-22.interdiff.txt | 757 bytes | DamienMcKenna |
Comments
Comment #1
MustangGB CreditAttribution: MustangGB commentedComment #2
danwonac CreditAttribution: danwonac commentedI had the same issue and followed the same basic premise. To only do this when 'fill single line' is checked, I instead added a new loop (no need for handling $rows[1+] since it only occurs when there is only one row). this is at approximately row 737 of theme.inc for version 7.x-3.6. I too have yet to figure out patches:
Comment #3
danwonac CreditAttribution: danwonac commentedAttempt at a patch...
Comment #4
imclean CreditAttribution: imclean commentedThanks danwonac. This replaces tabs with 2 spaces.
Comment #5
kari.nies CreditAttribution: kari.nies commentedThe above patch did not work for me.
The problem appears to be this line:
if (!empty($handler->options['fill_single_line']) && count($rows)) {
It should read.
if (!empty($handler->options['fill_single_line']) && $row_count==count($rows))
I've attached a new patch.
Comment #7
NaX CreditAttribution: NaX commentedThe last patch worked for me. Heres a re-rolled patch.
Comment #8
gianfrasoft CreditAttribution: gianfrasoft commented#7 seems to be perfect.
Why don't you put in the next views version?
Comment #9
DaPooch CreditAttribution: DaPooch commented#7 almost got me where I need to be but it doesn't appear to apply the row class to the rows it adds which I need for styling purposes. Any ideas? In looking through the code it appears that the row/column classes don't get applied till further down in the function and that they require a row_index to be set, just need to figure out if its possible to add these indexes to the filler rows that the patch in #7 generates.
Comment #10
DaPooch CreditAttribution: DaPooch commentedGot it. Slight mod to #7 to allow column classes to be applied to the fill columns as well:
Sadly I'm not sure how to create a patch so if anyone wants to review and roll a patch I'm sure it would be appreciated.
Comment #11
clfer CreditAttribution: clfer at Smile commentedHi
I needed this patch so here is my attempt taking into account last comment about column classes.
It add the same class as it normally would if there was content plus a new one ".col-fill"
New patch attached
Comment #12
MustangGB CreditAttribution: MustangGB commentedkari.nies, NaX, gianfrasoft, alanpuccinelli, clfer: This issue is only concerned with the functionality when using vertical alignment, the code you are touching is when horizontal alignment is used, for this see the other thread mentioned #1744478: Grid format disregards "number of columns" option for a single line of results.
Here is an update that addresses danwonac's concern of only being applied when the box is ticked:
Comment #13
MustangGB CreditAttribution: MustangGB commentedComment #14
MustangGB CreditAttribution: MustangGB commentedAnd a patch.
Comment #15
DamienMcKennaBumping to the next release.
Comment #16
DamienMcKennaTaking this off the plan for the next release, will consider it later.
Comment #17
Chris Matthews CreditAttribution: Chris Matthews as a volunteer commentedThe 2 year old patch in #14 to theme.inc applied cleanly to the latest views 7.x-3.x-dev
Comment #18
MustangGB CreditAttribution: MustangGB commentedNot sure why this was dropped from consideration previously, so retrying.
Obviously I can't really mark as RTBC, so if there is another reason please let me know.
Comment #19
DamienMcKennaI think it was because of the lack of reviews.
Could someone please add a comment to the for() loop explaining the logic? Thanks.
Comment #20
DamienMcKennaComment #21
DamienMcKennaComment #22
DamienMcKennaSimplified the code a little.
Comment #24
DamienMcKennaCommitted. Thanks all.