simplemap
simplemap copied to clipboard
Fixed an issue querying address field from non-primary site
Problem
Location queries using the map field fail on non-primary sites in multi-site Craft CMS installations. This is due to a strict JOIN condition that matches elements_sites.siteId to ownerSiteId, preventing access to map data saved on different sites.
Root Cause
In MapService::modifyElementsQuery(), the JOIN condition includes:
[[elements_sites.siteId]] = [[alias.ownerSiteId]]
This breaks location queries when:
- Map data is saved on Site A (
ownerSiteId = 1) - A query runs on Site B (
siteId = 2)
→ No results are returned since1 ≠ 2.
Solution
- Removed the strict site ID match from the
JOINcondition. - Preserved integrity by matching:
- Element ID:
[[elements.id]] = [[alias.ownerId]] - Field ID:
[[alias.fieldId]] = field->id - Excludes deleted elements: `[[elements.dateDeleted]] IS NULL`
- Element ID:
Files Changed
src/services/MapService.php: Modified theJOINcondition inmodifyElementsQuery()
Impact
This fix eliminates the need for complex workarounds in multi-site templates and makes the plugin's location query functionality work as expected across all sites in a Craft CMS multi-site setup.