Just a few small fixes as mentioned in:

#316779: Why need I hit enter twice?

Namely:

1) The page callback autocomplete_node_finder_block_form_results($delta) is printing its output directly rather then just returning it, so results pages aren't coming back in a fully theme'd page.

2) Supply necessary globals to theme_pager for pager output to show

3) Add JS via drupal_add_js so IE doesn't show JS errors if it's loaded too soon.

Let me know if you have any questions. :)

CommentFileSizeAuthor
autocomplete_node_finder_fixes.patch1.38 KBMoonshine

Comments

danielb’s picture

Are you sure the drupal_add_js works? I tried that and it never worked for me...

danielb’s picture

Also I would rather not use globals... what do you need them for? You should already have access to all that information.

Moonshine’s picture

The drupal_add_js is working fine here. Maybe you added it via "module" instead of "core" or a different path? not sure, but give it a try. If it doesn't work then we have some voodoo to hunt down :)

The globals are just a fact of life when using theme_pager. You'll see it uses them to pick up a couple values in the initial definitions. Normally they are just set by pager_query:

http://api.drupal.org/api/function/theme_pager/6

danielb’s picture

ah of course, without the pager query itself we have to manually set it... ok I will get onto this soon. Better get this module right before I start porting code over to my new framework, and with your interest in the code now it is a good time to do this.

danielb’s picture

I was wondering why you did the globals differently to how pager_query does it?
What do you think of this?

<?php

/**
 * Build a basic results page.
 */

function theme_autocomplete_node_finder_results_page($delta, $nids, $form_state) {
  global $pager_page_array, $pager_total, $pager_total_items;
  $limit = variable_get('autocomplete_node_finder_'.$delta.'_pager', 0);

  if (!empty($nids) && is_numeric($limit) && $limit > 0) {
    $total = count($nids);
    $nids = array_chunk($nids, $limit, TRUE);
    $page = isset($_GET['page']) ? $_GET['page'] : 0;
    $nids = $nids[$page];
    $quantity = ceil($total/$limit);

    // set globals for theme_pager
    $pager_total_items[$delta] = $total;
    $pager_total[$delta] = $quantity;
    $pager_page_array[$delta] = $page;
  }

  $output = '';

  if (empty($nids)) {
    $output .= t('There are no results to display.');
  }
  else {
    foreach ($nids as $nid) {
      $result = node_load($nid);
      $output .= node_view($result, TRUE);
    }
  }

  if (is_numeric($limit) && $limit > 0) {
    $output .= theme('pager', null, $limit, $delta, array(), $quantity);
  }

  return $output;

}

?>
Moonshine’s picture

That should be fine... I just literally included the two globals that theme_pager makes use of. Adding pager_total_items certainly won't hurt, it just isn't used by the theme call. But for sake of completeness...

danielb’s picture

Cheers, the latest release has these changes.

danielb’s picture

Status: Needs review » Fixed

Alright mate thanks for that, I'll mark as fix to coincide with the new release. If you have another feature/fix to talk about, we can start a new issue.

Status: Fixed » Closed (fixed)

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