dynamic / silverstripe-locator

SilverStripe Locator Module. Show locations on a map. Search by geoposition.
http://www.dynamicagency.com/labs/silverstripe-locator-module/
BSD 3-Clause "New" or "Revised" License
21 stars 7 forks source link

BUG - Missing fields on custom locations cause json errors #221

Open mak001 opened 4 years ago

mak001 commented 4 years ago

Describe the bug When using a custom object as a location if Featured is not a field on the object the json endpoint generates invalid json.

To Reproduce Steps to reproduce the behavior:

  1. Create a custom location object without a Featured field
  2. Set locator to use new class as location
  3. run a dev/build?flush=all
  4. visit the locator page and add the json action

Expected behavior Valid json is generated

This is what is generated currently without a Featured field of getter

{
   "locations":[
      {
         "ID":1,
         "Title":"#1",
         "Featured":,
         "Website":"",
         "Phone":"",
         "Fax":"",
         "Email":"",
         "Address":"",
         "Address2":"",
         "City":"Sheboygan",
         "State":"WI",
         "PostalCode":"53081",
         "Country":"us",
         "Distance":-1,
         "Lat":43.7013054,
         "Lng":-87.7271123
      }
   ]
}

Possible solutions Make data templates try to find location object specific templates. Possibly add fall back support to a basic template with bare minimum field requirements.

The fix should also be implemented to the XML feed to keep everything consistent.