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

Comments

PA robot’s picture

Status: Needs review » Needs work

There 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.

miroslavbanov’s picture

Your 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

adammitchell’s picture

Issue summary: View changes

Thank you for your reponses, I have updated this issue and the module to reflect your comments.

adammitchell’s picture

Issue summary: View changes
adammitchell’s picture

Status: Needs work » Needs review
joshi.rohit100’s picture

Hi 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.

joshi.rohit100’s picture

Status: Needs review » Needs work
adammitchell’s picture

Status: Needs work » Needs review

Hi Josh,

Thank you for taking the time to review the module and thanks for your suggestions, I have now implemented them.

caspervoogt’s picture

I am getting JS errors;

Uncaught ReferenceError: o is not defined
and:
Uncaught ReferenceError: fd is not defined

I 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.

adammitchell’s picture

Hi 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.

caspervoogt’s picture

OK, 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.

caspervoogt’s picture

StatusFileSize
new608.98 KB
adammitchell’s picture

Hi 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

caspervoogt’s picture

It'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.

adammitchell’s picture

Thank 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.

kscheirer’s picture

Status: Needs review » Needs work
Master Branch
It appears you are working in the "master" branch in git. You should really be working in a version specific branch. The most direct documentation on this is Moving from a master branch to a version branch. For additional resources please see the documentation about release naming conventions and creating a branch in git.

Looks like a very useful module, setting to needs work for the number of issues.

----
Top Shelf Modules - Crafted, Curated, Contributed.

caspervoogt’s picture

going 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.

adammitchell’s picture

Issue summary: View changes
Status: Needs work » Needs review

Hi 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

caspervoogt’s picture

Very good to hear. This is working. I still get some JS errors but they don't affect the functionality:

Uncaught ReferenceError: o is not defined

So.... RBTC but maybe check on the JS issues (Chrome)

adammitchell’s picture

I 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?

perennial.sky’s picture

please remove console.log from js file , and there is some line which exceed 80 character , use drupal coding standard.

perennial.sky’s picture

Status: Needs review » Needs work
adammitchell’s picture

Status: Needs work » Needs review

Hi 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.

mac_weber’s picture

This is an interesting module I want to contribute myself.

There are some minor things to be fixed, which I'm sending a patch:

  • Do not add .css on the .info file: if you add .css in the .info it will be added on every page. The correct way is via the form array (the way you are doing in code) or drupal_add_js(). Read: https://drupal.org/node/542202#stylesheets
  • Minor fixes on some comments.
  • There is no need for using 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.
  • In function addressfield_autocomplete_field_attach_submit() there is $items = field_get_items(...). This may lead to a bug at the next line - foreach - because field_get_items() may return FALSE. I've fixed it adding a conditional before the foreach().
  • There are many coding standard mistakes at the JS file, for example not using lowerCamelCase for variable names. I've fixed only 2 of these variables.
  • A couple trailing spaces somewhere. Fixed.

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.

mac_weber’s picture

Status: Needs review » Needs work
adammitchell’s picture

Hi 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.

adammitchell’s picture

Status: Needs work » Needs review

Hi 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

mac_weber’s picture

Status: Needs review » Reviewed & tested by the community

Hello Adam,

there are still some minor mistakes:

  • git
  • - 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 guide

I 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.

adammitchell’s picture

Hi 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

adammitchell’s picture

Status: Reviewed & tested by the community » Needs review

Going to change this back to needs review as I have added some major updates.

rachel_norfolk’s picture

Status: Needs review » Needs work

Hi,

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."

adammitchell’s picture

Status: Needs work » Needs review

Hi 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

heddn’s picture

Status: Needs review » Needs work

Automated 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.

(function ($) {
Drupal.behaviors.myModule = {
  attach: function (context, settings) {
    // Do something
  }
};
}(jQuery));

.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)

adammitchell’s picture

Status: Needs work » Needs review

Hi 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

heddn’s picture

Status: Needs review » Needs work

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.

#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.

adammitchell’s picture

Status: Needs work » Needs review

Hi 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

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Ahh, that makes much more sense now. Thanks for being patient with my feedback. RTBCing.

adammitchell’s picture

No 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.

mpdonadio’s picture

Just 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.

heddn’s picture

re: #2127007-39: [D7] Addressfield Autocomplete
Good information. I learn something new every day.

PA robot’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 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.

adammitchell’s picture

Status: Closed (duplicate) » Reviewed & tested by the community
adammitchell’s picture

Issue summary: View changes
Issue tags: +PAreview: review bonus
adammitchell’s picture

Priority: Normal » Major

Marking as major as it has been a month without feedback.

mpdonadio’s picture

Thew review bonus will get this finished quicker. This will likely be my next full review.

mpdonadio’s picture

Automated Review

Review of the 7.x-1.x branch:

  • Coder Sniffer has found some issues with your code (please check the Drupal coding standards). See attachment.
  • DrupalPractice has found some issues with your code, but could be false positives, and may be duplicate results from Coder Sniffer. See attachment.

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

Individual user account
Yes: Follows the guidelines for individual user accounts.
No multiple applications
Theere is another application for a different module, but @adammitchell closed it as a dup.
No duplication
Yes, this was a feature request in Addressfield, but it was closed as Won't Fix: https://www.drupal.org/node/1604866
Master Branch
Yes: Follows the guidelines for master branch.
Licensing
Yes: Follows the licensing requirements
3rd party code
Yes: Follows the guidelines for 3rd party code.
README.txt
Yes: Follows the guidelines for in-project documentation and the README.txt Template.
Code long/complex enough for review
Yes: Follows the guidelines for project length and complexity.
Secure code
Yes. If "no", list security issues identified.
Coding style & Drupal API usage

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.

mpdonadio’s picture

Assigned: adammitchell » Unassigned
Status: Reviewed & tested by the community » Fixed
StatusFileSize
new2.98 KB

Forgot 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.

adammitchell’s picture

Hi 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

Status: Fixed » Closed (fixed)

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