Skip to content

Commit

Permalink
REFACTOR Locator - getTrigger (#220)
Browse files Browse the repository at this point in the history
* REFACTOR Locator - getTrigger

Check if any GET vars exist, or if static $db ResultsOnLoad is true. If so, display results.

closes #219

* travis tweak

* phpcs
  • Loading branch information
jsirish authored Jun 1, 2022
1 parent 4e09b0a commit f8f63a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/pages/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Dynamic\SilverStripeGeocoder\AddressDataExtension;
use SilverStripe\Core\Manifest\ModuleResourceLoader;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter;
use SilverStripe\Forms\HeaderField;
Expand Down Expand Up @@ -46,6 +47,7 @@ class Locator extends \Page
*/
private static $db = array(
'Unit' => 'Enum("m,km","m")',
'ResultsOnLoad' => 'Boolean',
);

/**
Expand All @@ -55,6 +57,13 @@ class Locator extends \Page
'Categories' => LocationCategory::class,
);

/**
* @var array
*/
private static $defaults = [
'ResultsOnLoad' => 0,
];

/**
* @var string
*/
Expand All @@ -75,6 +84,10 @@ public function getCMSFields()
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')),
CheckboxField::create('ResultsOnLoad', 'Show results on page load')
->setDescription('For larger collections of locations, it is
recommended to only show a limited amount of results after a location
search.')
));

// Filter categories
Expand Down
11 changes: 1 addition & 10 deletions src/pages/LocatorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ class LocatorController extends \PageController
*/
private static $list_container = 'loc-list';

/**
* GET variable which, if isset, will trigger storeLocator init and return XML
*
* @var string
*/
private static $query_trigger = 'action_doFilterLocations';

/**
* @var DataList|ArrayList
*/
Expand Down Expand Up @@ -186,9 +179,7 @@ public function getTrigger(HTTPRequest $request = null)
if ($request === null) {
$request = $this->getRequest();
}
$trigger = $request->getVar(Config::inst()->get(LocatorController::class, 'query_trigger'));

return isset($trigger);
return !empty($this->getRequest()->getVars()) || $this->data()->ResultsOnLoad;
}

/**
Expand Down

0 comments on commit f8f63a2

Please sign in to comment.