When using the Geolocation field with the googlemaps widget, the map does not display when the field is attached to a field collection.

Using Drupal 7.12, Geolocation 7.x-1.1, Field collection 7.x-1.0-beta4

Comments

jojonaloha’s picture

Status: Active » Needs review
StatusFileSize
new1.01 KB

I've attached a patch that resolves the issue for me, but not sure if it is the best way to go about it.

dvega’s picture

Thank you very much, it works!

derjochenmeyer’s picture

Status: Needs review » Postponed (maintainer needs more info)

@jojonaloha: could you please explain how the patch solves the issue.
thanks! :)

jojonaloha’s picture

Status: Postponed (maintainer needs more info) » Needs review

It's been awhile, but since the Field Collection module is a fieldable entity, the array looks something like this (from memory):

$node->$field_collection_name[$parent_delta][$field_name][$delta] = array('value' => '', ... etc);

And so by just using the $instance['id'] and $delta, it is always something like 'googlemap-0', creating duplicate HTML id's and then only the first instance loads, I think. By adding the $parent_delta in there it becomes 'googlemap-0-0', 'googlemap-1-0', etc and if the field is multivalued then it would be incremented as well. The dash in between is important to avoid conflicts with something like googlemap-11-0 vs googlemap-1-10

Hope that helps.

derjochenmeyer’s picture

Thanks for the clarification. Shouldn't this code be wrapped in something like ...

if (module_exists('field_collection')) {
  ...
}
jojonaloha’s picture

I suppose it could be wrapped in a module_exists(), but since we aren't relying on any field_collection functions I don't think it's necessary.

derjochenmeyer’s picture

Status: Needs review » Fixed

However, makes sense. Thanks! Committed to 7.x-1.x-dev
http://drupalcode.org/project/geolocation.git/commit/4f0d565

derjochenmeyer’s picture

Status: Fixed » Active

Is possible to have a more generic approach. Is field collection the only module/case where we have to consider $element['#field_parents']?

jojonaloha’s picture

That's a good question. It may have been fine to just do something like (example diff):

-  $id = $instance['id'] . '-' . $delta;
+  $depth = count($element['#field_parents']) - 1;
+  $parent_delta = $element['#field_parents'][$depth];
+  $id = $instance['id'] . '-' . $parent_delta . '-' . $delta;

I haven't tested this, but it is probably better long-term to have a more generic solution, as there may be other modules that create nested fields like this.

derjochenmeyer’s picture

Issue summary: View changes
Status: Active » Closed (fixed)
rp7’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.33 KB

According to me, the fix does not cover nested field collections. Newly attached patch should fix this.

Status: Needs review » Needs work

The last submitted patch, 11: geolocation-map_in_field_collection-1548008-11.patch, failed testing.

derjochenmeyer’s picture

This patch needs a reroll.

  • derjochenmeyer committed 4f0d565 on 8.x-2.x
    Issue #1548008 by jojonaloha: Fix Google Map widget in Field Collections...
  • derjochenmeyer committed f261598 on 8.x-2.x
    Issue #1548008 by jojonaloha: Fix Google Map widget in Field Collections...
christianadamski’s picture

Component: Google Maps geolocation » Geolocation Field / Backend
Status: Needs work » Closed (won't fix)

Closing all 7.x issues. It's time.