When generating zebra classes please also provide first and last classes to the item elements. This will enable site builder to properly style, for example, a row of guttered images, where the first or last item has to have different side margin than others. As this seems to be a relatively easy addition, please try to make it into 1.x branch

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

moniuch’s picture

As I'm not git-savvy enough, please accept my traditional "patch" that works for me. Hope you will not mind applying it to your code.

ds/modules/ds_extras/ds_extras.module

Inside the foreach loop at line 460 I changed the first IF labeled // Field item wrapper.

    if (isset($config['fi'])) {
      $classes = array();
      
      // Determine first-last classes
      reset($variables['items']);
      if($delta === key($variables['items'])) {
        $classes[] = 'first';
      }
      end($variables['items']);
      if($delta === key($variables['items'])) {
        $classes[] = 'last';
      }
      
      // Determine zebra classes
      $classes[] = ($delta % 2 ? 'odd' : 'even');

      $classes_str = implode(' ', $classes);
      if (!empty($config['fi-cl'])) {
        $classes_str .= ' ' . $config['fi-cl'];
      }
      
      $output .= '<' . $fi_wrapper . ' class="' . $classes_str . '">';
    }
moniuch’s picture

Spleshka’s picture

Status: Active » Needs work

Patch is OK but I have one notice:

+++ b/modules/ds_extras/ds_extras.module
@@ -471,11 +471,27 @@ function theme_ds_field_expert($variables) {
+      $classes = array();
+      ¶
+      // Determine first-last classes
+      reset($variables['items']);
+      if($delta === key($variables['items'])) {
+        $classes[] = 'first';
+      }
+      end($variables['items']);
+      if($delta === key($variables['items'])) {
+        $classes[] = 'last';
+      }
+      ¶
+      // Determine zebra classes
+      $classes[] = ($delta % 2 ? 'odd' : 'even');
+
+      $classes_str = implode(' ', $classes);
       if (!empty($config['fi-cl'])) {
-        $classes .= ' ' . $config['fi-cl'];
+        $classes_str .= ' ' . $config['fi-cl'];
       }
-      $output .= '<' . $fi_wrapper . ' class="' . $classes . '">';
+      ¶

Please, remove extra spaces from the patch. And please set issue status to Needs Review when providing a patch.

moniuch’s picture

Status: Needs work » Needs review
FileSize
1.17 KB

Thanks, Spleshka, slowly making my progress :)

Spleshka’s picture

Status: Needs review » Needs work

According to Drupal coding standards - at the end of comment should be dot :) I'm not sure if it is required for this patch, but if you have free minute - please fix this.

moniuch’s picture

Status: Needs work » Needs review
FileSize
1.05 KB

As desired :)

swentel’s picture

Version: 7.x-1.5 » 7.x-2.x-dev

Needs to go into second branch first - with configuration option (if that's not in yet, not sure). I'm a bit afraid I can't add this by default in the first branch as it might possibly break existing css configurations. To overcome this in the first branch you can create your own field template function though with the hook_ds_field_theme_functions_info() hook.

moniuch’s picture

In 1.5 I haven't seen any configuration option for zebra classes, so I did not worry about making first/last classes configurable. Also, I thought it would be more intuitive that first-last classes go into the same place as zebra. Hence the patch.

I've been using this patch with no CSS problems. It's just additional classes that should don't break anything.

You changed the version of the issue, but I created the patch against 1.5 and I'm not likely to test 2.x-dev as I'm using only release versions for my productions sites. Therefore, if you are not going to use that patch, simply disregard and close that issue. No offense.
Thanks for the hook info though, might come in handy some day.

jmix’s picture

HI ! i'm using 7.x-2.0 and just understood this patch was for 1x...
Is there a simple way to have first / last class with DS ?
Thanks !

lonehorseend’s picture

Issue summary: View changes
FileSize
4.14 KB

Here's a patch against the latest version of 7.2.x. It has the admin functionality so you can select or deselect on a field item basis. Remember to clear your cache before using.

aspilicious’s picture

I'm considering this... Will ask frontend input at work.

bceyssens’s picture

Status: Needs review » Fixed

Thanks for the patch lonehorseend
This has been committed

Status: Fixed » Closed (fixed)

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