Here's an area handler that I've had to use on two projects now (D6 and D7). Would be useful in Views core?

May need some cleanup.

Comments

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new2.58 KB

And the file. Which is just an area handler. Needs a hook_views_data bit, below.

  $data['global']['search_header'] = array(
    'title' => t('Search header'),
    'help' => t('Prints search information.'),
    'area' => array(
      'handler' => 'custom_handler_area_search_header',
    ),
  );
agentrickard’s picture

StatusFileSize
new32.67 KB

Sample usage.

dawehner’s picture

Status: Needs review » Needs work

A lit

  function query() {
    // do nothing -- to override the parent query.

The default handler already does nothing.

    $options['content'] = array(
      'default' => t('Displaying @start - @end of @total'));
    return $options;

This should be 'translatable'

    $variables = array(
      'items' => array(
        '@start -- the initial record number in the set',
        '@end -- the last record number in the set',
        '@total -- the total records in the set',
        '@name -- the human-readable name of the view',
        '@per_page -- the number of items per page',
        '@current_page -- the current page number',
        '@page_count -- the total page count',

Wouldn't it be possible to use the views tokens system here?

    $current_page = (int) $this->view->get_current_page() + 1;
    $per_page = (int) $this->view->get_items_per_page();
    $count = count($this->view->result);
    $total = $this->view->total_rows;
    $name = check_plain($this->view->human_name);
    $page_count = (int) ceil($total / $per_page);
    if ($per_page === 0) {
      $start = 1;
      $end = $total;
    }
    else {
      $total_count = $current_page * $per_page;
      if ($total_count > $total) {
        $total_count = $total;
      }
      $start = ($current_page - 1) * $per_page + 1;
      $end = $total_count;

I'm wondering whether we could somehow reuse/share the stuff from the field count handler. It's quite an amount of code

Powered by Dreditor.

dawehner’s picture

Version: 7.x-3.x-dev » 6.x-3.x-dev
Status: Needs work » Patch (to be ported)

In general i really like this feature, as it can drop the amount of ugly template-code you need a lot.
Committed a version with some renaming and improvements.

tnightingale’s picture

StatusFileSize
new502 bytes

This is an excellent feature!
Currently it doesn't export correctly as it doesn't add its options definition to the array returned from the call to parent::option_definition().
Here's a patch.

dawehner’s picture

Ohhhhhhh thanks! Committed to 7.x-3.x

windmaomao’s picture

I saw this feature is turned on in Drupal 7.x - 3.x . Really really nice, i really like it. Thanks a million.

tamasco’s picture

I am using drupal 6 with views 2. How can I use this code in my case? I am sure the above feature is not yet implemented in views 2.

mustanggb’s picture

Issue summary: View changes
Status: Patch (to be ported) » Closed (won't fix)