Hi!

This patch enhances table as well as grid views by some styles I have missed so far and referring to #364637: Let table rows emit custom classes.

The first row of a view gets the class views-row-first, the last one accordingly views-row-last. There is one exception: If there is only one single row, its classes are not both views-row-first and views-row-last, but views-row-single instead.

In addition to $row_classes there is also an array $col_classes with similar class names (views-col-first, views-col-last, views-col-single, views-col-odd, views-col-even).

Furthermore, I have moved php code from the grid template to the grid preprocess function and renamed row-first/row-last as views-row-first/views-row-last.

I left the implode function in the template file, though I'd personally prefer not to use it there, since it opposes the paradigm that a designer should understand the whole template source. Otherwise, I see the advantage of manipulating an array of classes within further preprocess functions over working with a string. Unfortunately, I cannot offer a better solution, so it would be great, if anyone had a better idea.

Comments

drupalexio’s picture

StatusFileSize
new4.4 KB
dawehner’s picture

Status: Needs review » Needs work

I like to move logic from the template into preprocess, but sadly there are some minor things

+    foreach ($vars['rows'][0] as $fields => $field) {

I don't like $fields as variable here, its $field_id, or something similar.


+    if (count($vars['rows'][0]) == 1) {
+      reset($vars['rows'][0]);
+      $vars['col_classes'][key($vars['rows'][0])][] = 'views-col-single';
+    }
+    else {
+      reset($vars['rows'][0]);
+      $vars['col_classes'][key($vars['rows'][0])][] = 'views-col-first';
+      end($vars['rows'][0]);
+      $vars['col_classes'][key($vars['rows'][0])][] = 'views-col-last';
+    }

It would be better for people if you have inline comments where you describe what reset key and end does here.

drupalexio’s picture

Status: Needs work » Needs review
StatusFileSize
new6.22 KB

In terms of the variable name $fields I completely agree with you and have renamed it as $field_id. I did the same within views-view-table.tpl.php.

In addition, I have also added the wanted inline comments.

Finally, I have added some missing lines in the comment head of the templates.

kars-t’s picture

Status: Needs review » Reviewed & tested by the community

This is a great and use full patch. Please commit it!

dawehner’s picture

Status: Reviewed & tested by the community » Needs review

Related issue: http://drupal.org/node/682888

Can you please have a look where the implode should be done? in template file or preprocess

<tr class="<?php print implode(' ', $row_classes[$count]); ?>">

Sorry for this.

kars-t’s picture

As you did show me on IRC the only option to avoid this in D6 would be to do some special hook_theme implementation like this ZEN theme is doing. So I'd still say go for it. I will try to catch earl on IRC to talk about this. Hope I find some time. Otherwise maybe he stumbles about this issue and likes it ;)

dawehner’s picture

Sorry but

patch -p0 < views-grid-and-table-v2.patch
patching file theme/theme.inc
Hunk #2 succeeded at 449 (offset 1 line).
patching file theme/views-view-grid.tpl.php
Hunk #1 succeeded at 2 with fuzz 1.
Hunk #2 FAILED at 20.
1 out of 2 hunks FAILED -- saving rejects to file theme/views-view-grid.tpl.php.rej
patching file theme/views-view-table.tpl.php
dawehner’s picture

Status: Needs review » Needs work

Update status

esmerel’s picture

Status: Needs work » Closed (won't fix)

No updated to patch in over 3 months.