Description
Addressfield autocomplete provides a hook into google maps autocomplete API. It implements a new widget which utilises the existing addressfield module functionality.
It is useful for people who do not wish to utilise PAF or want an easy method for users to input addresses.
Git Repo
git clone --branch 7.x-1.x http://git.drupal.org/sandbox/adammitchell/2126989.git addressfield_autocomplete
Sandbox
https://drupal.org/sandbox/adammitchell/2126989
About the author
I have been working with Drupal on some relatively large sites now for several years. I feel that it is time that I returned some of the nice features we have built back to the community.
I have seem some users requesting this piece of functionality; so I thought I could fill a small gap in the market, whilst utilising an existing module.
Sponsors
Thank you to The Drum for kindly sponsoring this module.
Reviews of other projects
https://www.drupal.org/node/2291697#comment-8910641
https://www.drupal.org/node/2292285#comment-8913777
https://www.drupal.org/node/2290783#comment-8914147
| Comment | File | Size | Author |
|---|---|---|---|
| #47 | pareview_results.txt | 2.98 KB | mpdonadio |
| #12 | addressfield-js.jpg | 608.98 KB | caspervoogt |
Comments
Comment #1
PA robot commentedThere are some errors reported by automated review tools, did you already check them? See http://pareview.sh/pareview/httpgitdrupalorgsandboxadammitchell2126989git
We are currently quite busy with all the project applications and we prefer projects with a review bonus. Please help reviewing and put yourself on the high priority list, then we will take a look at your project right away :-)
Also, you should get your friends, colleagues or other community members involved to review this application. Let them go through the review checklist and post a comment that sets this issue to "needs work" (they found some problems with the project) or "reviewed & tested by the community" (they found no major flaws).
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #2
miroslavbanov commentedYour git clone link cannot be accessed by others. You should use http protocol for git clone command -
git clone http://git.drupal.org/sandbox/adammitchell/2126989.git
You shouldn't use master branch but 7.x-1.x instead. See:
https://drupal.org/empty-git-master
Comment #3
adammitchell commentedThank you for your reponses, I have updated this issue and the module to reflect your comments.
Comment #4
adammitchell commentedComment #5
adammitchell commentedComment #6
joshi.rohit100Hi Adam,
You should have a install file to remove the declared variables.
Also, it is good to add dependency in your info file if you are extending / using a contributed module.
Comment #7
joshi.rohit100Comment #8
adammitchell commentedHi Josh,
Thank you for taking the time to review the module and thanks for your suggestions, I have now implemented them.
Comment #9
caspervoogt commentedI am getting JS errors;
Uncaught ReferenceError: o is not definedand:
Uncaught ReferenceError: fd is not definedI had set up a Google Maps API V3 key at https://code.google.com/apis/console/?noredirect because the link on your sandbox page (https://developers.google.com/maps/signup) can be confusing - might be worth updating. I created a new key, but maybe I didn't do it right? Step by step instructions would be handy because Google has been changing the API console a lot.
Comment #10
adammitchell commentedHi Casper,
I have changed the sandbox project page to reflect your comments. I found a better tutorial on setting up a google maps v3 api key here https://developers.google.com/maps/documentation/javascript/tutorial#api....
Please could you let me know what browser and version you are using so I can test.
Many thanks for reviewing.
Comment #11
caspervoogt commentedOK, so I followed the tutorial and am using the correct key but am still getting JS errors. I am using Chrome and jQuery 1.7. I tested with and without compressing JS (in Performance settings) and also tried jQuery 1.5 and 1.8 without effect. Attaching screenshot in a moment.
Comment #12
caspervoogt commentedComment #13
adammitchell commentedHi Casper,
Thank you for getting back so quickly. I can't seem to replicate these issues on the basic install that I have. I noticed in the console that you may have other google maps api modules turned on. Could you please let me know which modules these are. I will then try and see if I can fix the conflicts.
Cheers,
Adam
Comment #14
caspervoogt commentedIt's the Gmap module. I disabled it and now your module works beautifully. I do need my Gmap module, and I suspect others may too, but you can just add that as a bug that needs to be fixed. So long as people know about it I think that's fine.
Comment #15
adammitchell commentedThank you for pointing this out to me Casper, I will note this as a conflict issue in my project and try and fix it for you this weekend. I will let you know once it has been updated.
Comment #16
kscheirerEnter one manuallyshould be run through t(), as with all user-facing text.Looks like a very useful module, setting to needs work for the number of issues.
----
Top Shelf Modules - Crafted, Curated, Contributed.
Comment #17
caspervoogt commentedgoing to agree with kscheirer here. The style issues aren't a huge deal though. And the Gmap conflict shouldn't hold it up ... just note it on the module page until you have a fix for it.
Comment #18
adammitchell commentedHi Karl and Casper,
Thank you very much for your comments, I have changed everything that you have both suggested.
I have decided to make GMap a dependency (as it is a widely used module) and in the newest version I am utilising the google maps js file that it loads onto the page. This means that there should be no more conflicts with this module.
If you have any further improvements I would be grateful to hear them.
Adam
Comment #19
caspervoogt commentedVery good to hear. This is working. I still get some JS errors but they don't affect the functionality:
So.... RBTC but maybe check on the JS issues (Chrome)
Comment #20
adammitchell commentedI can't seem to replicate this js error. I have tried it on multiple OS' and 3 different platforms. I am wondering if it might be another conflict?
Comment #21
perennial.sky commentedplease remove console.log from js file , and there is some line which exceed 80 character , use drupal coding standard.
Comment #22
perennial.sky commentedComment #23
adammitchell commentedHi akashjain132,
Thank you for your suggestions, I think you may have downloaded a previous version as there is no longer console.log's in the js file. However I have updated some of the longer lines of code and separated them out to make them easier to read.
Comment #24
mac_weber commentedThis is an interesting module I want to contribute myself.
There are some minor things to be fixed, which I'm sending a patch:
if ($widget['type'] == 'addressfield_standard') {because you have only 1 widget. Moreover, after the if you return$form, which may be undefined. I've fixed it removing the conditional.function addressfield_autocomplete_field_attach_submit()there is$items = field_get_items(...). This may lead to a bug at the next line - foreach - becausefield_get_items()may return FALSE. I've fixed it adding a conditional before theforeach().The patch may be found at your issue queue: https://drupal.org/node/2156297
The attached patch can be applied using git apply patchname.patch. This will keep the correct author information.
Comment #25
mac_weber commentedComment #26
adammitchell commentedHi Mac_Weber,
Many thanks for taking an interest in the module, I will have a look at the patch and make the other necessary updates you suggested.
Comment #27
adammitchell commentedHi Mac_Weber,
Many thanks for reviewing the module and providing the patch, this has been applied to the project. I have also updated the js file to be more in keeping with Drupal's coding standards.
Regards,
Adam
Comment #28
mac_weber commentedHello Adam,
there are still some minor mistakes:
http://pareview.sh/pareview/httpgitdrupalorgsandboxadammitchell2126989git
I think you want to delete the line with the link to instructions to get the google API key: http://drupalcode.org/sandbox/adammitchell/2126989.git/blob/51292c5488d3...
- Make sure you have the same user configuration across your machines. I see in the module repository you sometimes using the username Adam Mitchell, other times you are using adammitchell.
- For each commit fix only one issue. It will be better for later understanding what is going on in the code history. I see a commit you fixed 2 different issues.
- Use the command
git apply. This will preserve the patch's author information. Contributors love getting credit ;) As you can see here you are listed both as committer and author of the patch I've sent. Read more at: Advanced patch contributor guideI have many suggestions for this module and I'd like to talk more about it with you. Let me know if you are available anytime for a chat on IRC.
One of my suggestions is to not use this complex JS. You can instead use a very small JS to integrate with this: http://ubilabs.github.io/geocomplete/
This project looks good to become a full project. Marking it as RTBC.
Comment #29
adammitchell commentedHi Mac_Weber,
Thank you for setting this to RTBC, I have made some major updates to the module based upon some of your suggestions. It would be good to get some feedback on it.
Cheers,
Adam
Comment #30
adammitchell commentedGoing to change this back to needs review as I have added some major updates.
Comment #31
rachel_norfolkHi,
The field now has the wrong help text - it has some html tags in it...
"Please enter the address the <strong>event takes place at</strong>. We will use this to add a pin to the map of events."
Comment #32
adammitchell commentedHi Rachel,
Many thanks for taking the time to review this module. I have fixed the issue of html tags appearing in the field description.
If there are any other issues you are having let me know and I will get them sorted.
Thanks,
Adam
Comment #33
heddnAutomated review:
addressfield_autocomplete.js
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AFFECTING 1 LINE(S)
--------------------------------------------------------------------------------
142 | ERROR | Whitespace found at end of line
.js file:
for statement doesn't loop at line 61
for(var country in settings.available_countries) break;'gmapSettings.controltype == 'None' ? true : false' can be simplified to 'gmapSettings.controltype == 'None'' at line 48
disableDefaultUI : gmapSettings.controltype == 'None' ? true : false,In general, there is inconsistent whitespace usage in the js. In some places there are spaces around the conditional if and else clauses. In other cases, this isn't true. Please put a space around the conditional statements, similar to how you would do in PHP.
See the section on Behaviors at https://drupal.org/node/171213. No need to pass Drupal and jQuery into the closure. Drupal is available from the global namespace.
.module file:
I don't see where you end up using the drupal_static pattern, even though it gets called in line 165.
Consider using Drupal's theme functionality, either a tpl or a theme function for the map markup (around line 280)
Comment #34
adammitchell commentedHi heddn,
Thank you for taking your time to review the module and for your suggestions.
I have added a theme function and tidied up the js file as you advised.
Here are some of the explainations as to why some things were coded the way they were:
The static variable is used so that when you have multiple address fields inside the same form we do not add the js for those fields twice.
The javascript loop is used to get the first element of an object. I could change the data structures when adding them to the Drupal js settings, this would allow me to remove the loop.
Thanks again,
Adam
Comment #35
heddn#attached and drupal_add_js both should handle this situation already.
javascript control statements should still use {} (line 66). And each else, else if should be on their own new line.
See https://drupal.org/node/172169.
Comment #36
adammitchell commentedHi heddn,
Thank you for getting back so quickly and the further suggestions. I have completed the further formatting of the js file.
With regards to the use of the static variable if it is not done this way and we have multiple addressfield autocomplete fields inside the same form, you will only ever get the last field setting inside the drupal settings object. It seems that because we use the same key for each of the fields (line 194 of the module file) the setting gets overwritten even if the data inside is different.
Thanks,
Adam
Comment #37
heddnAhh, that makes much more sense now. Thanks for being patient with my feedback. RTBCing.
Comment #38
adammitchell commentedNo problem, thank you very much for the RTBC.
I am sorry that I didn't explain it very well the first time. It would have been much simpler to explain in person.
Comment #39
mpdonadioJust a random comment about https://drupal.org/node/2127007#comment-8750019
Explicitly passing the Drupal object into the closure isn't needed, but it is an established practice. Pretty sure most people call it global import (I think Ben Cherry coined the term). With the way the JS scope chain works, the runtime will start to work its ways up the scope until it hits global, searching for the identifier. By passing it the closure, you create a binding, and since objects are passed by reference, the JS runtime will find the global object quicker. Passing in jQuery does the same thing, but with the normal Drupal pattern, the binding you create is called $. Whether it speeds up simple Drupal behaviors is debatable, but I like that style.
Comment #40
heddnre: #2127007-39: [D7] Addressfield Autocomplete
Good information. I learn something new every day.
Comment #41
PA robot commentedProject 1: https://www.drupal.org/node/2291667
Project 2: https://www.drupal.org/node/2127007
As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).
If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.
I'm a robot and this is an automated message from Project Applications Scraper.
Comment #42
adammitchell commentedComment #43
adammitchell commentedComment #44
adammitchell commentedMarking as major as it has been a month without feedback.
Comment #45
mpdonadioThew review bonus will get this finished quicker. This will likely be my next full review.
Comment #46
mpdonadioAutomated Review
Review of the 7.x-1.x branch:
This automated report was generated with PAReview.sh, your friendly project application review script. You can also use the online version to check your project. You have to get a review bonus to get a review from me.
The CSS/JS look like false positives. The rest is minor.
Manual Review
It would be nice if the link to get Geocomplete was in the status report, and if there was a drush command to download and install it.
Add a complete path to a library file in the email, eg sites/all/libraries/geocomplete/jquery.geocomplete.js to help people double check
how to install this. It will cut down on issue when people mess it up.
Why the dependency on libraries >= 1? Why not >= 2 or no version all together?
Your JS should use the context and settings objects that are passed in via the behavior.
It looks like you have an untranslated string in addressfield_autocomplete_field_widget_info(), 'Enter one manually'. Do a pass to see if you missed others.
addressfield_autocomplete_field_widget_form() has an empty clearfix div as a prefix. Since clearfix is supposed to get rid of the need
for empty clearing divs, should that wrap it instead?
Did you test out the field in groups, etc? It looks like the code will support this, but I didn't explicitly test this.
It would be handy if this could also populate a geofield in parallel to the address.
You may want a hook_help().
Tracing out any user facing text with this is a little tough, but everything looks OK, and I did a few XSS injection tests.
Not seeing any blocking issues. The code is well written, and will be a good addition to the module space. I will be using this in the future.
Comment #47
mpdonadioForgot the attachment..
Thanks for your contribution, adammitchell!
I updated your account so you can promote this to a full project and also create new projects as either a sandbox or a "full" project.
Here are some recommended readings to help with excellent maintainership:
You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and stay involved!
Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.
Thanks to the dedicated reviewer(s) as well.
Comment #48
adammitchell commentedHi Matthew,
Thank you for taking the time to review the module and for the approval. Your suggested improvements are invaluable and I will be doing these before promoting it.
Thanks again to all of the other reviewers, your comments and helpful tips having been extremely useful.
Cheers,
Adam