Needs review
Project:
Google Custom Search Engine Advanced
Version:
6.x-1.2
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
27 Sep 2010 at 02:40 UTC
Updated:
14 Jul 2011 at 08:27 UTC
Jump to comment: Most recent file
Comments
Comment #1
jweowu commentedComment #2
jweowu commentedI found that it was quite difficult to observe the DOM and CSS changes that the autocomplete widget inserts, so here's some documentation of this. It could potentially be included in the module.
Comment #3
meba commentedI have seen several times (including myself) that we needed to drupal_add_js in preprocess page, which is obviously too late. We solved that (and there is at least one blogpost about it) by doing:
This will break your patch. Can we theme the script, wrap it in
(which is already done) and add it as inline using drupal_add_Js so it's in the registry?Comment #4
jweowu commentedFrustratingly you cannot use
drupal_add_js()to generate<script src="http://www.google.com/jsapi" type="text/javascript"></script>. Its data can either be inline javascript, or a relative path from the Drupal site's base URL. External URLs are not supported at all, which is a bit crap.The recommended workaround appears to be using
drupal_set_html_head()instead, and that should be fail-safe, but that's also really annoying if you want all the javascript output at the end of the page.This is why the patch implements both approaches, and provides an option. I've documented the issue in the code, and indicated how to deal with theme issues if you wish to use the theme option and you are also regenerating the $scripts variable.
If there's a genuine solution to this other than patching drupal_add_js(), I'd love to hear it.
The second script could be added inline with drupal_add_js(), but given this first issue, I didn't see any point in treating the two in different ways.
Comment #5
meba commentedI have used something like this in past:
Comment #6
jweowu commentedOh, nice. That's a much better hack :)
Will do.
Comment #7
jweowu commentedNew and improved.
The AJAX API loader URL looks pretty set in stone, so I didn't include that in the theme function. People may wish to add their Google API key, though, so I added a setting for that.
I also added that CSS documentation into the README file.
Comment #8
jweowu commentedComment #9
meba commentedI committed this and then realized I can't get this working. First of all, the autocomplete is inserted in search results only, not in all forms anywhere. That is intentional? Secondly, even there, no autocomplete shows - is there anything that needs to be done at google administration?
Comment #10
jweowu commentedYes, you need to enable it at the Google end as well, and then wait at least several hours before Google will start to return autocompletion suggestions.
Use the Google search interface as a test bed. Once autocompletions are appearing there, you should be getting them for the same terms from Drupal.
It was intentional inserting it into the google_cse_adv_search_view() function. I did wonder whether it might be desirable in the search block as well. It shouldn't be hard to make that change, provided that the widget plays nice when attached to multiple forms on a single page.
Ah... now that you say it, though... I guess it's not currently activated when you go to '/search/google_cse_adv' with no search keys? I think that page is still served by the original search_view(). If so, that was a genuine blunder. We currently have a weird bug where that path is timing out to a server error (not related to this module AFAIK) which I haven't gotten around to investigating, so I wouldn't have tested that page.
Although maybe the more appropriate fix there would be to add a hook_menu entry for '/search/google_cse_adv'? Writing this now, it does seem odd having that one case handled by a different function.
(n.b. I can't verify any of this right now, so apologies if I have it wrong.)
Comment #11
jweowu commentedI've updated this to resolve the issues. It now works at the form generation stage (hook_form_alter, #after_build), and can be enabled for any or all of the standard search forms (search_form, search_theme_form, search_block_form).
I've changed the autocompletion settings variable type in the process, so if you still have that value in your database from the previous patch, you'll see an error on the settings form as it tries to use the stored non-array value as an array. Just submit the form to fix that up.
Comment #12
jweowu commentedAdded an informative link to the label of the AJAX API key setting
Comment #13
jweowu commentedAdded the README changes back
Comment #14
jweowu commentedLast one, I think :) Just tweaking some text to make the warning that you need to enable this at the Google end as well a little more visible than it was before.
Comment #15
jweowu commentedTrivial change of a variable name to something more appropriate.
Comment #16
jweowu commentedHmm... I see something went amiss with my attempt to revert the README changes!
I also thought of another problem/solution: the Google AJAX API Loader may already be present by the time we go to load it (for example, if another module had used it to load up the Google Maps API), so now the javascript will only write that script tag if there is no existing
google.loaderobject.If google.loader doesn't exist, we definitely need it because we're going to use it immediately. If some other module wants to load the AJAX API Loader again after we do, then they should either be doing the same thing (checking for it first) to avoid unnecessary duplication, or else the site admin can change the module weightings so that the other code runs before ours.
I've also changed a persistent variable name from
google_cse_adv_google_api_keyto the more specificgoogle_cse_adv_ajax_api_keyComment #17
The Computer Audiophile commentedThis may sound elementary but how do I implement the 923694-9 patch into release 6.x-1.2?
Comment #18
jweowu commentedFor general information on patches, see http://drupal.org/patch
The short version is that you could use something like this from within the module's directory:
patch -p0 <google_cse_adv-923694-9_0.patchI most certainly recommend learning about patching so that you know how to deal with them in future, but I'm also attaching a pre-patched version so that you can provide some test feedback regardless.
Take note of the comments from #10: