Skip to content

Commit

Permalink
REFACTOR Locator - getTrigger
Browse files Browse the repository at this point in the history
Check if any GET vars exist, or if static $db ResultsOnLoad is true. If so, display results.

closes dynamic#219
  • Loading branch information
jsirish committed Jan 22, 2020
1 parent 1de9005 commit 24b6a29
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 14 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,11 @@ 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 @@ -63,13 +63,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 @@ -185,9 +178,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 24b6a29

Please sign in to comment.