Passed
Push — enhancement/more-config-option... ( 58b9a6 )
by Matthew
09:31
created
src/Page/LocatorController.php 1 patch
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -21,388 +21,388 @@
 block discarded – undo
21 21
  */
22 22
 class LocatorController extends \PageController
23 23
 {
24
-    /**
25
-     * @var array
26
-     */
27
-    private static $allowed_actions = [
28
-        'xml',
29
-        'json',
30
-    ];
31
-
32
-    /**
33
-     * @var array
34
-     */
35
-    private static $base_filter = [];
36
-
37
-    /**
38
-     * @var array
39
-     */
40
-    private static $base_exclude = [
41
-        'Lat' => 0,
42
-        'Lng' => 0,
43
-    ];
44
-
45
-    /**
46
-     * @var array
47
-     */
48
-    private static $base_filter_any = [];
49
-
50
-    /**
51
-     * @var bool
52
-     */
53
-    private static $bootstrapify = true;
54
-
55
-    /**
56
-     * ID of map container
57
-     *
58
-     * @var string
59
-     */
60
-    private static $map_container = 'map';
61
-
62
-    /**
63
-     * class of location list container
64
-     *
65
-     * @var string
66
-     */
67
-    private static $list_container = 'loc-list';
68
-
69
-    /**
70
-     * GET variable which, if isset, will trigger storeLocator init and return XML
71
-     *
72
-     * @var string
73
-     */
74
-    private static $query_trigger = 'action_doFilterLocations';
75
-
76
-    /**
77
-     * The zoom level of the map
78
-     * @var int
79
-     */
80
-    private static $zoom = 12;
81
-
82
-    /**
83
-     * The minimum zoom level the map can have
84
-     * @var int
85
-     */
86
-    private static $min_zoom = 6;
87
-
88
-    /**
89
-     * The maximum zoom level the map can have
90
-     * @var int
91
-     */
92
-    private static $max_zoom = 18;
93
-
94
-    /**
95
-     * If double clicking the map should not zoom
96
-     * @var bool
97
-     */
98
-    private static $disable_double_click_zoom = true;
99
-
100
-    /**
101
-     * If the map should disable zoom by scrollwheel
102
-     * @var bool
103
-     */
104
-    private static $scrollwheel = false;
105
-
106
-    /**
107
-     * If the map should show naviagtion controls
108
-     * @var bool
109
-     */
110
-    private static $navigation_control = false;
111
-
112
-    /**
113
-     * @var bool
114
-     */
115
-    private static $draggable = false;
116
-
117
-    /**
118
-     * @var DataList|ArrayList
119
-     */
120
-    protected $locations;
121
-
122
-    /**
123
-     * Set Requirements based on input from CMS
124
-     */
125
-    public function init()
126
-    {
127
-        parent::init();
128
-
129
-        // prevent init of map if no query
130
-        $request = Controller::curr()->getRequest();
131
-        if (!$this->getTrigger($request)) {
132
-            return;
133
-        }
134
-
135
-        $locations = $this->getLocations();
136
-
137
-        // prevent init of map if there are no locations
138
-        if (!$locations) {
139
-            return;
140
-        }
141
-
142
-        // google maps api key
143
-        $key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
144
-        Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
145
-
146
-        $mapSettings = [
147
-            'fullMapStart' => true,
148
-            'maxDistance' => true,
149
-            'storeLimit' => -1,
150
-            'originMarker' => true,
151
-            'slideMap' => false,
152
-            'distanceAlert' => -1,
153
-            'featuredLocations' => false,
154
-            'defaultLat' => 0,
155
-            'defaultLng' => 0,
156
-            'mapSettings' => [
157
-                'zoom' => Config::inst()->get(LocatorController::class, 'zoom'),
158
-                'minZoom' => Config::inst()->get(LocatorController::class, 'min_zoom'),
159
-                'maxZoom' => Config::inst()->get(LocatorController::class, 'max_zoom'),
160
-                'mapTypeId' => 'google.maps.MapTypeId.ROADMAP',
161
-                'disableDoubleClickZoom' => Config::inst()->get(LocatorController::class, 'disable_double_click_zoom'),
162
-                'scrollwheel' => Config::inst()->get(LocatorController::class, 'scrollwheel'),
163
-                'navigationControl' => Config::inst()->get(LocatorController::class, 'navigation_control'),
164
-                'draggable' => Config::inst()->get(LocatorController::class, 'draggable'),
165
-            ],
166
-        ];
167
-
168
-        $mapSettings['listTemplatePath'] = $this->getListTemplate();
169
-        $mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate();
170
-        $mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm';
171
-        $mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container');
172
-        $mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container');
173
-
174
-        if ($locations->filter('Featured', true)->count() > 0) {
175
-            $mapSettings['featuredLocations'] = true;
176
-        }
177
-
178
-        // map config based on user input in Settings tab
179
-        $limit = Config::inst()->get(LocatorController::class, 'limit');
180
-        if (0 < $limit) {
181
-            $mapSettings['storeLimit'] = $limit;
182
-        }
183
-
184
-        if ($coords = $this->getAddressSearchCoords()) {
185
-            $mapSettings['defaultLat'] = $coords->getField("Lat");
186
-            $mapSettings['defaultLat'] = $coords->getField("Lng");
187
-        }
188
-
189
-        // pass GET variables to xml action
190
-        $vars = $this->request->getVars();
191
-        unset($vars['url']);
192
-        $url = '';
193
-        if (count($vars)) {
194
-            $url .= '?' . http_build_query($vars);
195
-        }
196
-        $mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url);
197
-
198
-        if ($stylePath = $this->getMapStyleJSONPath()) {
199
-            if ($style = file_get_contents($stylePath)) {
200
-                $mapSettings['mapSettings']['styles'] = json_decode($style);
201
-            }
202
-        }
203
-
204
-        if ($imagePath = $this->getMarkerIcon()) {
205
-            $mapSettings['markerImg'] = $imagePath;
206
-        }
207
-
208
-        $this->extend('modifyMapSettings', $mapSettings);
209
-
210
-        $encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES);
211
-        // mapTypeId is a javascript object
212
-        $encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded);
213
-
214
-        $this->extend('modifyMapSettingsEncoded', $encoded);
215
-        // init map
216
-        Requirements::customScript("
24
+	/**
25
+	 * @var array
26
+	 */
27
+	private static $allowed_actions = [
28
+		'xml',
29
+		'json',
30
+	];
31
+
32
+	/**
33
+	 * @var array
34
+	 */
35
+	private static $base_filter = [];
36
+
37
+	/**
38
+	 * @var array
39
+	 */
40
+	private static $base_exclude = [
41
+		'Lat' => 0,
42
+		'Lng' => 0,
43
+	];
44
+
45
+	/**
46
+	 * @var array
47
+	 */
48
+	private static $base_filter_any = [];
49
+
50
+	/**
51
+	 * @var bool
52
+	 */
53
+	private static $bootstrapify = true;
54
+
55
+	/**
56
+	 * ID of map container
57
+	 *
58
+	 * @var string
59
+	 */
60
+	private static $map_container = 'map';
61
+
62
+	/**
63
+	 * class of location list container
64
+	 *
65
+	 * @var string
66
+	 */
67
+	private static $list_container = 'loc-list';
68
+
69
+	/**
70
+	 * GET variable which, if isset, will trigger storeLocator init and return XML
71
+	 *
72
+	 * @var string
73
+	 */
74
+	private static $query_trigger = 'action_doFilterLocations';
75
+
76
+	/**
77
+	 * The zoom level of the map
78
+	 * @var int
79
+	 */
80
+	private static $zoom = 12;
81
+
82
+	/**
83
+	 * The minimum zoom level the map can have
84
+	 * @var int
85
+	 */
86
+	private static $min_zoom = 6;
87
+
88
+	/**
89
+	 * The maximum zoom level the map can have
90
+	 * @var int
91
+	 */
92
+	private static $max_zoom = 18;
93
+
94
+	/**
95
+	 * If double clicking the map should not zoom
96
+	 * @var bool
97
+	 */
98
+	private static $disable_double_click_zoom = true;
99
+
100
+	/**
101
+	 * If the map should disable zoom by scrollwheel
102
+	 * @var bool
103
+	 */
104
+	private static $scrollwheel = false;
105
+
106
+	/**
107
+	 * If the map should show naviagtion controls
108
+	 * @var bool
109
+	 */
110
+	private static $navigation_control = false;
111
+
112
+	/**
113
+	 * @var bool
114
+	 */
115
+	private static $draggable = false;
116
+
117
+	/**
118
+	 * @var DataList|ArrayList
119
+	 */
120
+	protected $locations;
121
+
122
+	/**
123
+	 * Set Requirements based on input from CMS
124
+	 */
125
+	public function init()
126
+	{
127
+		parent::init();
128
+
129
+		// prevent init of map if no query
130
+		$request = Controller::curr()->getRequest();
131
+		if (!$this->getTrigger($request)) {
132
+			return;
133
+		}
134
+
135
+		$locations = $this->getLocations();
136
+
137
+		// prevent init of map if there are no locations
138
+		if (!$locations) {
139
+			return;
140
+		}
141
+
142
+		// google maps api key
143
+		$key = Config::inst()->get(GoogleGeocoder::class, 'map_api_key');
144
+		Requirements::javascript('https://maps.google.com/maps/api/js?key=' . $key);
145
+
146
+		$mapSettings = [
147
+			'fullMapStart' => true,
148
+			'maxDistance' => true,
149
+			'storeLimit' => -1,
150
+			'originMarker' => true,
151
+			'slideMap' => false,
152
+			'distanceAlert' => -1,
153
+			'featuredLocations' => false,
154
+			'defaultLat' => 0,
155
+			'defaultLng' => 0,
156
+			'mapSettings' => [
157
+				'zoom' => Config::inst()->get(LocatorController::class, 'zoom'),
158
+				'minZoom' => Config::inst()->get(LocatorController::class, 'min_zoom'),
159
+				'maxZoom' => Config::inst()->get(LocatorController::class, 'max_zoom'),
160
+				'mapTypeId' => 'google.maps.MapTypeId.ROADMAP',
161
+				'disableDoubleClickZoom' => Config::inst()->get(LocatorController::class, 'disable_double_click_zoom'),
162
+				'scrollwheel' => Config::inst()->get(LocatorController::class, 'scrollwheel'),
163
+				'navigationControl' => Config::inst()->get(LocatorController::class, 'navigation_control'),
164
+				'draggable' => Config::inst()->get(LocatorController::class, 'draggable'),
165
+			],
166
+		];
167
+
168
+		$mapSettings['listTemplatePath'] = $this->getListTemplate();
169
+		$mapSettings['infowindowTemplatePath'] = $this->getInfoWindowTemplate();
170
+		$mapSettings['lengthUnit'] = $this->data()->Unit == 'km' ? 'km' : 'm';
171
+		$mapSettings['mapID'] = Config::inst()->get(LocatorController::class, 'map_container');
172
+		$mapSettings['locationList'] = Config::inst()->get(LocatorController::class, 'list_container');
173
+
174
+		if ($locations->filter('Featured', true)->count() > 0) {
175
+			$mapSettings['featuredLocations'] = true;
176
+		}
177
+
178
+		// map config based on user input in Settings tab
179
+		$limit = Config::inst()->get(LocatorController::class, 'limit');
180
+		if (0 < $limit) {
181
+			$mapSettings['storeLimit'] = $limit;
182
+		}
183
+
184
+		if ($coords = $this->getAddressSearchCoords()) {
185
+			$mapSettings['defaultLat'] = $coords->getField("Lat");
186
+			$mapSettings['defaultLat'] = $coords->getField("Lng");
187
+		}
188
+
189
+		// pass GET variables to xml action
190
+		$vars = $this->request->getVars();
191
+		unset($vars['url']);
192
+		$url = '';
193
+		if (count($vars)) {
194
+			$url .= '?' . http_build_query($vars);
195
+		}
196
+		$mapSettings['dataLocation'] = Controller::join_links($this->Link(), 'xml.xml', $url);
197
+
198
+		if ($stylePath = $this->getMapStyleJSONPath()) {
199
+			if ($style = file_get_contents($stylePath)) {
200
+				$mapSettings['mapSettings']['styles'] = json_decode($style);
201
+			}
202
+		}
203
+
204
+		if ($imagePath = $this->getMarkerIcon()) {
205
+			$mapSettings['markerImg'] = $imagePath;
206
+		}
207
+
208
+		$this->extend('modifyMapSettings', $mapSettings);
209
+
210
+		$encoded = json_encode($mapSettings, JSON_UNESCAPED_SLASHES);
211
+		// mapTypeId is a javascript object
212
+		$encoded = preg_replace('/("mapTypeId"\s*:\s*)"(.+?)"/i', '$1$2', $encoded);
213
+
214
+		$this->extend('modifyMapSettingsEncoded', $encoded);
215
+		// init map
216
+		Requirements::customScript("
217 217
                 $(function(){
218 218
                     $('#map-container').storeLocator({$encoded});
219 219
                 });
220 220
             ", 'jquery-locator');
221
-    }
222
-
223
-    /**
224
-     * @param HTTPRequest $request
225
-     *
226
-     * @return bool
227
-     */
228
-    public function getTrigger(HTTPRequest $request = null)
229
-    {
230
-        if ($request === null) {
231
-            $request = $this->getRequest();
232
-        }
233
-        $trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
234
-
235
-        return isset($trigger);
236
-    }
237
-
238
-    /**
239
-     * @return ArrayList|DataList
240
-     */
241
-    public function getLocations()
242
-    {
243
-        if (!$this->locations) {
244
-            $this->setLocations($this->request);
245
-        }
246
-
247
-        return $this->locations;
248
-    }
249
-
250
-    /**
251
-     * @param HTTPRequest|null $request
252
-     *
253
-     * @return $this
254
-     */
255
-    public function setLocations(HTTPRequest $request = null)
256
-    {
257
-
258
-        if ($request === null) {
259
-            $request = $this->request;
260
-        }
261
-        $filter = $this->config()->get('base_filter');
262
-
263
-        $categoryVar = $this->data()->config()->get('category_var');
264
-        if ($request->getVar($categoryVar)) {
265
-            $filter['Categories.ID'] = $request->getVar($categoryVar);
266
-        } else {
267
-            if ($this->getPageCategories()->exists()) {
268
-                foreach ($this->getPageCategories() as $category) {
269
-                    $filter['Categories.ID'][] = $category->ID;
270
-                }
271
-            }
272
-        }
273
-
274
-        $this->extend('updateLocatorFilter', $filter, $request);
275
-
276
-        $filterAny = $this->config()->get('base_filter_any');
277
-        $this->extend('updateLocatorFilterAny', $filterAny, $request);
278
-
279
-        $exclude = $this->config()->get('base_exclude');
280
-        $this->extend('updateLocatorExclude', $exclude, $request);
281
-
282
-        $class = $this->data()->ClassName;
283
-        $locations = $class::get_locations($filter, $filterAny, $exclude);
284
-        $locations = DataToArrayListHelper::to_array_list($locations);
285
-
286
-        //allow for adjusting list post possible distance calculation
287
-        $this->extend('updateLocationList', $locations);
288
-
289
-        if ($locations->canSortBy('Distance')) {
290
-            $locations = $locations->sort('Distance');
291
-        }
292
-
293
-        if ($this->getShowRadius()) {
294
-            $radiusVar = $this->data()->config()->get('radius_var');
295
-
296
-            if ($radius = (int)$request->getVar($radiusVar)) {
297
-                $locations = $locations->filterByCallback(function ($location) use (&$radius) {
298
-                    return $location->Distance <= $radius;
299
-                });
300
-            }
301
-        }
302
-
303
-        //allow for returning list to be set as
304
-        $this->extend('updateListType', $locations);
305
-
306
-        $limit = $this->getLimit();
307
-        if ($limit > 0) {
308
-            $locations = $locations->limit($limit);
309
-        }
310
-
311
-        $this->locations = $locations;
312
-
313
-        return $this;
314
-    }
315
-
316
-    /**
317
-     * @return ArrayData|boolean
318
-     */
319
-    public function getAddressSearchCoords()
320
-    {
321
-        $addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
322
-        if (!$this->request->getVar($addressVar)) {
323
-            return false;
324
-        }
325
-        if (class_exists(GoogleGeocoder::class)) {
326
-            $geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
327
-            $response = $geocoder->getResult();
328
-            $lat = $response->getLatitude();
329
-            $lng = $response->getLongitude();
330
-
331
-            return new ArrayData([
332
-                "Lat" => $lat,
333
-                "Lng" => $lng,
334
-            ]);
335
-        }
336
-    }
337
-
338
-    /**
339
-     * @param HTTPRequest $request
340
-     *
341
-     * @return \SilverStripe\View\ViewableData_Customised
342
-     */
343
-    public function index(HTTPRequest $request)
344
-    {
345
-        if ($this->getTrigger($request)) {
346
-            $locations = $this->getLocations();
347
-        } else {
348
-            $locations = ArrayList::create();
349
-        }
350
-
351
-        return $this->customise([
352
-            'Locations' => $locations,
353
-        ]);
354
-    }
355
-
356
-    /**
357
-     * Renders locations in xml format
358
-     *
359
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
360
-     */
361
-    public function xml()
362
-    {
363
-        $this->getResponse()->addHeader("Content-Type", "application/xml");
364
-        $data = new ArrayData([
365
-            "Locations" => $this->getLocations(),
366
-            "AddressCoords" => $this->getAddressSearchCoords(),
367
-        ]);
368
-
369
-        return $data->renderWith('Dynamic/Locator/Data/XML');
370
-    }
371
-
372
-    /**
373
-     * Renders locations in json format
374
-     *
375
-     * @return \SilverStripe\ORM\FieldType\DBHTMLText
376
-     */
377
-    public function json()
378
-    {
379
-        $this->getResponse()->addHeader("Content-Type", "application/json");
380
-        $data = new ArrayData([
381
-            "Locations" => $this->getLocations(),
382
-            "AddressCoords" => $this->getAddressSearchCoords(),
383
-        ]);
384
-
385
-        return $data->renderWith('Dynamic/Locator/Data/JSON');
386
-    }
387
-
388
-    /**
389
-     * LocationSearch form.
390
-     *
391
-     * Search form for locations, updates map and results list via AJAX
392
-     *
393
-     * @return \SilverStripe\Forms\Form
394
-     */
395
-    public function LocationSearch()
396
-    {
397
-
398
-        $form = LocatorForm::create($this, 'LocationSearch');
399
-
400
-        $this->extend('updateLocationSearch', $form);
401
-
402
-        return $form
403
-            ->setFormMethod('GET')
404
-            ->setFormAction($this->Link())
405
-            ->disableSecurityToken()
406
-            ->loadDataFrom($this->request->getVars());
407
-    }
221
+	}
222
+
223
+	/**
224
+	 * @param HTTPRequest $request
225
+	 *
226
+	 * @return bool
227
+	 */
228
+	public function getTrigger(HTTPRequest $request = null)
229
+	{
230
+		if ($request === null) {
231
+			$request = $this->getRequest();
232
+		}
233
+		$trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));
234
+
235
+		return isset($trigger);
236
+	}
237
+
238
+	/**
239
+	 * @return ArrayList|DataList
240
+	 */
241
+	public function getLocations()
242
+	{
243
+		if (!$this->locations) {
244
+			$this->setLocations($this->request);
245
+		}
246
+
247
+		return $this->locations;
248
+	}
249
+
250
+	/**
251
+	 * @param HTTPRequest|null $request
252
+	 *
253
+	 * @return $this
254
+	 */
255
+	public function setLocations(HTTPRequest $request = null)
256
+	{
257
+
258
+		if ($request === null) {
259
+			$request = $this->request;
260
+		}
261
+		$filter = $this->config()->get('base_filter');
262
+
263
+		$categoryVar = $this->data()->config()->get('category_var');
264
+		if ($request->getVar($categoryVar)) {
265
+			$filter['Categories.ID'] = $request->getVar($categoryVar);
266
+		} else {
267
+			if ($this->getPageCategories()->exists()) {
268
+				foreach ($this->getPageCategories() as $category) {
269
+					$filter['Categories.ID'][] = $category->ID;
270
+				}
271
+			}
272
+		}
273
+
274
+		$this->extend('updateLocatorFilter', $filter, $request);
275
+
276
+		$filterAny = $this->config()->get('base_filter_any');
277
+		$this->extend('updateLocatorFilterAny', $filterAny, $request);
278
+
279
+		$exclude = $this->config()->get('base_exclude');
280
+		$this->extend('updateLocatorExclude', $exclude, $request);
281
+
282
+		$class = $this->data()->ClassName;
283
+		$locations = $class::get_locations($filter, $filterAny, $exclude);
284
+		$locations = DataToArrayListHelper::to_array_list($locations);
285
+
286
+		//allow for adjusting list post possible distance calculation
287
+		$this->extend('updateLocationList', $locations);
288
+
289
+		if ($locations->canSortBy('Distance')) {
290
+			$locations = $locations->sort('Distance');
291
+		}
292
+
293
+		if ($this->getShowRadius()) {
294
+			$radiusVar = $this->data()->config()->get('radius_var');
295
+
296
+			if ($radius = (int)$request->getVar($radiusVar)) {
297
+				$locations = $locations->filterByCallback(function ($location) use (&$radius) {
298
+					return $location->Distance <= $radius;
299
+				});
300
+			}
301
+		}
302
+
303
+		//allow for returning list to be set as
304
+		$this->extend('updateListType', $locations);
305
+
306
+		$limit = $this->getLimit();
307
+		if ($limit > 0) {
308
+			$locations = $locations->limit($limit);
309
+		}
310
+
311
+		$this->locations = $locations;
312
+
313
+		return $this;
314
+	}
315
+
316
+	/**
317
+	 * @return ArrayData|boolean
318
+	 */
319
+	public function getAddressSearchCoords()
320
+	{
321
+		$addressVar = Config::inst()->get(DistanceDataExtension::class, 'address_var');
322
+		if (!$this->request->getVar($addressVar)) {
323
+			return false;
324
+		}
325
+		if (class_exists(GoogleGeocoder::class)) {
326
+			$geocoder = new GoogleGeocoder($this->request->getVar($addressVar));
327
+			$response = $geocoder->getResult();
328
+			$lat = $response->getLatitude();
329
+			$lng = $response->getLongitude();
330
+
331
+			return new ArrayData([
332
+				"Lat" => $lat,
333
+				"Lng" => $lng,
334
+			]);
335
+		}
336
+	}
337
+
338
+	/**
339
+	 * @param HTTPRequest $request
340
+	 *
341
+	 * @return \SilverStripe\View\ViewableData_Customised
342
+	 */
343
+	public function index(HTTPRequest $request)
344
+	{
345
+		if ($this->getTrigger($request)) {
346
+			$locations = $this->getLocations();
347
+		} else {
348
+			$locations = ArrayList::create();
349
+		}
350
+
351
+		return $this->customise([
352
+			'Locations' => $locations,
353
+		]);
354
+	}
355
+
356
+	/**
357
+	 * Renders locations in xml format
358
+	 *
359
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
360
+	 */
361
+	public function xml()
362
+	{
363
+		$this->getResponse()->addHeader("Content-Type", "application/xml");
364
+		$data = new ArrayData([
365
+			"Locations" => $this->getLocations(),
366
+			"AddressCoords" => $this->getAddressSearchCoords(),
367
+		]);
368
+
369
+		return $data->renderWith('Dynamic/Locator/Data/XML');
370
+	}
371
+
372
+	/**
373
+	 * Renders locations in json format
374
+	 *
375
+	 * @return \SilverStripe\ORM\FieldType\DBHTMLText
376
+	 */
377
+	public function json()
378
+	{
379
+		$this->getResponse()->addHeader("Content-Type", "application/json");
380
+		$data = new ArrayData([
381
+			"Locations" => $this->getLocations(),
382
+			"AddressCoords" => $this->getAddressSearchCoords(),
383
+		]);
384
+
385
+		return $data->renderWith('Dynamic/Locator/Data/JSON');
386
+	}
387
+
388
+	/**
389
+	 * LocationSearch form.
390
+	 *
391
+	 * Search form for locations, updates map and results list via AJAX
392
+	 *
393
+	 * @return \SilverStripe\Forms\Form
394
+	 */
395
+	public function LocationSearch()
396
+	{
397
+
398
+		$form = LocatorForm::create($this, 'LocationSearch');
399
+
400
+		$this->extend('updateLocationSearch', $form);
401
+
402
+		return $form
403
+			->setFormMethod('GET')
404
+			->setFormAction($this->Link())
405
+			->disableSecurityToken()
406
+			->loadDataFrom($this->request->getVars());
407
+	}
408 408
 }
Please login to merge, or discard this patch.