This module looks great but as a relative Drupal newbie I'm a bit confused about where these 3 chunks of code go. At first I thought they could be put in template.php but it throws up an error:

warning: Missing argument 1 for theme_apachesolr_ajax_yui(), called in /home/finalcut/public_html/sites/all/themes/finalcutters/template.php on line 212 and defined in /home/finalcut/public_html/sites/all/modules/apachesolr_ajax/apachesolr_ajax.module on line 189.

thanks

Martin

Comments

jpmckinney’s picture

I made a mistake in the documentation. Try the following in your template.php:

function mytheme_preprocess_page(&$vars, $hook) {
  $vars['apachesolr_ajax'] = theme('apachesolr_ajax_yui');
}

The first and last hooks (whose function names start with mymodule) should be defined in a custom module. See the first two parts of the module developer's guide: http://drupal.org/node/206753 Remember to substitute your custom module's name for "mymodule".

jpmckinney’s picture

Status: Active » Closed (fixed)

Two weeks without reply. I assume it's fixed.

Anonymous’s picture

Sorry I've been busy with other stuff. Will try again later in the week.

Anonymous’s picture

That did fix it thanks. Because our results page has some other js stuff going on, there seems to be a conflict happening. Haven't got time to investigate so am putting this on the backburner for now.

thanks

Martin

jason ruyle’s picture

I'm actually getting this error as well, it happens when I got to my search page:

http://www.mydomainname.com/search
or
http://www.mydomainname.com/search/apachesolr_search

And I do not have a search term or keyword. Once I do an actual search, the error is gone.

jpmckinney’s picture

Status: Closed (fixed) » Active

Could you post the contents of the apachesolr_ajax hooks you've implemented?

jason ruyle’s picture

Below is the code. We get these errors for both anonymous and logged in users. I saw this because we do use YUI library and their panes layout, but this is only used for authenticated users, so isn't so relevant.

searchajax.module

<?php
/**
* Implementation of hook_settings().
*/
function searchajax_apachesolr_ajax_settings() {
  global $theme;

  $settings = array(
    'content' => '#content-area',
    'spinner' => '/sites/all/modules/custom/searchajax/images/spinner.gif',
    'regions' => array(
      'left' => '#sidebar-left-inner',
      'right' => '#sidebar-right-inner',
      'header' => '#header',
      'footer' => '#footer',
      'branding' => '#branding',
      'current_search' => '#current-search',
      'adv_search' => '#adv-search',
      'admin_right' => '#static-wrapper',
      'lightbox' => '#lightbox-pane',
      'search_mini' => '#search-mini',
      'content_top' => '#content-top'
    )
  );

  $modules = apachesolr_ajax_modules();
  foreach ($modules as $module) {
    if (module_exists($module)) {
      if ($list = module_invoke($module, 'block', 'list')) {
        foreach (array_keys($list) as $delta) {
          $settings['blocks'][$module .'_'. $delta] = '#block-'. $module .'-'. $delta;
        }
      }
    }
  }

  return $settings;
}

preprocess.inc (template.php)

function OURTHEME_preprocess_page(&$vars, $hook) {
  global $theme;

  // Support for ajax search
  $vars['apachesolr_ajax'] = theme('apachesolr_ajax_yui');
......

page-search.tpl.php
between head tags

<?php if (module_exists('apachesolr_ajax')): ?>
<script src="http://yui.yahooapis.com/2.8.0r4/build/yahoo/yahoo-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.0r4/build/event/event-min.js"></script>
<script src="http://yui.yahooapis.com/2.8.0r4/build/history/history-min.js"></script>
<?php endif; ?>
<body id="yui-gen0" class="<?php print $body_classes; ?>">
<?php
if (module_exists('apachesolr_ajax')):
  print $apachesolr_ajax;
endif;
?>
<div id="wrapper" style="overwrite:auto;">

I should note that not all the regions are on the page-search for anonymous users. But don't know if that's related.

Also I should say that not every page does:
print $apachesolr_ajax;

But we get the errors on all pages. Even if we redirect users to the search page from another search box.

homoludens’s picture

mine solution maybe is not the best, but this thing is working:
i changed function theme_apachesolr_ajax_yui

function theme_apachesolr_ajax_yui($src) {
  return '<iframe id="yui-history-iframe" src="'.$src .'"></iframe><input id="yui-history-field" type="hidden">';
}

to look like this:

function theme_apachesolr_ajax_yui() {
  return '<iframe id="yui-history-iframe" src="'.'/sites/default/files/logo.png' .'"></iframe><input id="yui-history-field" type="hidden">';
}

and added following css file apachesolr_ajax.css:

#yui-history-iframe  {
height:1px;
left:0;
position:absolute;
top:0;
visibility:hidden;
width:1px;
}

.

i, also, had problem with getting preprocess functions to add js files, so i created:

function apachesolr_ajax_init(){
  drupal_add_js('sites/all/modules/apachesolr/apachesolr.js');
  drupal_add_js('sites/all/modules/apachesolr_ajax/apachesolr_ajax.js');
  drupal_add_css('sites/all/modules/apachesolr_ajax/apachesolr_ajax.css');
  foreach (array('http://yui.yahooapis.com/2.8.0r4/build/yahoo/yahoo-min.js', 'http://yui.yahooapis.com/2.8.0r4/build/event/event-min.js', 'http://yui.yahooapis.com/2.8.0r4/build/history/history-min.js') as $script) {
    if (strpos('<script src="'. $script .'"></script>', drupal_get_html_head()) === FALSE) {
      drupal_set_html_head('<script src="'. $script .'"></script>');
    }
  }
}

in apachesolr_ajax.module

it is working in firefox, didn't test other browsers.

jpmckinney’s picture

Sorry for the late reply. Please download apachesolr_ajax 1.4 and read the updates to the documentation. If the new code doesn't work, let me know in this thread.

@homoludens:

I fixed the bug in theme_apachesolr_ajax_yui. If no argument is supplied, it defaults $src to "robots.txt".

I forgot to mention the CSS rule. I've added it to the documentation at http://drupal.org/project/apachesolr_ajax

I've added a troubleshooting section describing a solution to the problem of the preprocess functions not adding the JS files. Here it is again:

If this module's JS files are not added to your page, you may have to modify the mytheme_preprocess_page function described above:

function mytheme_preprocess_page(&$vars, $hook) {
  $vars['apachesolr_ajax'] = theme('apachesolr_ajax_yui');
  $vars['head'] = drupal_get_html_head();
  $vars['scripts'] = drupal_get_js();
}

In some cases, template_preprocess_page in theme.inc is run before apachesolr_ajax_preprocess_page, and so the JavaScripts files are not added. This is the fix.

jpmckinney’s picture

Component: Code » Documentation
Status: Active » Closed (duplicate)

As these bugs were mostly due to poor documentation, I'm merging with #704582: Enhance Module Documentation.