Add classes to simplify excluding "All" from alpha pager

JohnAlbin - January 20, 2008 - 07:08
Project:Views Alpha Pager
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I had a project that didn't need the "All" tacked on to the end of the alpha pager.

Attached is a patch that adds an item to the Edit View page to make the "All" link optional.

As a side note, looking at CVS, I'm wondering why the "placement" is stored in its own database table. It seems a waste to add an additional database query to retrieve it, when it would be less database-intensive to use variable_get(). What's the rationale?

AttachmentSize
all-optional.patch2.22 KB

#1

douggreen - February 29, 2008 - 00:29
Status:needs review» needs work

This patch doesn't look very clean to me. Why all the extra #weight's?

I've had this request several times, and I've told people that they should do this in theming. However, if you can implement this as a view level setting, and store the information in the views_alpha_pager table, I'd consider it.

The extra table was created so that we don't clutter the variables table with views specific variables (each row in the variables table causes extra data to be retrieved), and the field wasn't tagged onto the views table because (a) that's considered bad form, and (b) breaks with schema api.

#2

JohnAlbin - February 29, 2008 - 01:00

The extra weights are there because that form doesn't have any weights, so there's no way to insert the use_pager_all checkbox directly before $form['page-info']['breadcrumb_no_home']. Do you know of a way to insert an element as, for example, the 6th element when the array's keys aren't number based? I couldn't figure out how to do it with any of php's array_* functions. Do you have any insights?

The easiest way to do this on the theme layer would be to display: none on the "All" links CSS class. But the "All" link doesn't have a class. If I created a patch that added a class, would you find that more acceptable than adding a field to the db?

Thanks for the module, btw!

#3

douggreen - February 29, 2008 - 11:55

"Theming" also refers to the php override functions that you can put in template.php. I've used lots of theme() calls in views_alpha_pager so that you can do just this sort of thing. For example, you can override theme_alpha_pager, as-in:

function yourtheme_alpha_pager($items, $current = '', $link = array()) {
  // add style sheet
  $modpath = drupal_get_path('module', 'views_alpha_pager');
  drupal_add_css($modpath .'/views_alpha_pager.css', 'module');

  $output = '';

  if (!empty($items)) {
    $output .= '<div class="apager"><span class="pager-list">';
    foreach ($items as $item => $item_display) {
      if ($item != '*') {
        if ("$item" == "$current") {
          $output .= '<strong class="pager-current">'. $item_display .'</strong> ';
        }
        else {
          if ($item < $current) {
            $class = 'pager-previous';
          }
          else {
            $class = 'pager-next';
          }
          $output .= theme('alpha_pager_link', $item, $item_display, array('class' => $class), $link);
        }
        $output .= ' ';
      }
    }
    $output .= '</span></div>';

    return $output;
  }
}

#4

JohnAlbin - February 29, 2008 - 13:28
Title:Add option to exclude "All" from alpha pager» Add classes to simplify excluding "All" from alpha pager
Status:needs work» needs review

I actually use phptemplate_alpha_pager() in one of my sites to add a “|” between letters (blame the client.) But manipulating that theme function to do an exclusion when "$item" == "*" is beyond most theme developers.

Here’s a patch which adds a “pager-x”-style class to each letter. And “pager-0” and “pager-all” to # and All.

AttachmentSize
pager-classes.patch 1.21 KB

#5

douggreen - March 3, 2008 - 15:03
Status:needs review» fixed

Committed, Thanks!

#6

Anonymous (not verified) - March 17, 2008 - 15:11
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.