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++) {
  ...
}
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MustangGB’s picture

Title: For the grid format "Fill up single line" should work when using vertical alignment » For the grid format "Fill up single line" does not work when using vertical alignment for a single row
danwonac’s picture

I 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:

if (!empty($handler->options['fill_single_line'])) {
	for ($i = 0; $i < $columns; $i++) {
		if (!isset($rows[0][$i])) {
			$rows[0][$i] = '';
		}
	}
}
danwonac’s picture

Attempt at a patch...

imclean’s picture

Status: Needs work » Needs review
FileSize
547 bytes

Thanks danwonac. This replaces tabs with 2 spaces.

kari.nies’s picture

The 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.

Status: Needs review » Needs work

The last submitted patch, views-fill-single-line1773798-5.patch, failed testing.

NaX’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
557 bytes

The last patch worked for me. Heres a re-rolled patch.

gianfrasoft’s picture

#7 seems to be perfect.

Why don't you put in the next views version?

DaPooch’s picture

#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.

DaPooch’s picture

Got it. Slight mod to #7 to allow column classes to be applied to the fill columns as well:

    if ($row) {
      // Fill up the last line only if it's configured, but this is default.
      if (!empty($handler->options['fill_single_line'])) {
        for ($i = 0; $i < ($columns - $col_count); $i++) {
          $row[] = '';
          $row_indexes[$row_count][$col_count+$i] = 'fill_'.$row_count.'_'.($col_count+$i);
        }
      }
      $rows[] = $row;
    }

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.

clfer’s picture

Hi
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

MustangGB’s picture

kari.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:

/**
 * 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 < (!empty($handler->options['fill_single_line']) ? $columns : count($rows[0])); $i++) {
  ...
}
MustangGB’s picture

MustangGB’s picture

And a patch.

DamienMcKenna’s picture

DamienMcKenna’s picture

Taking this off the plan for the next release, will consider it later.

Chris Matthews’s picture

The 2 year old patch in #14 to theme.inc applied cleanly to the latest views 7.x-3.x-dev

MustangGB’s picture

Not 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.

DamienMcKenna’s picture

Status: Needs review » Needs work

I think it was because of the lack of reviews.

Could someone please add a comment to the for() loop explaining the logic? Thanks.

DamienMcKenna’s picture

DamienMcKenna’s picture

DamienMcKenna’s picture

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks all.

Status: Fixed » Closed (fixed)

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