Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REFACTOR Locator - getTrigger #220

Merged
merged 3 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ before_script:
script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml -F php; fi
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 @@ -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
3 changes: 1 addition & 2 deletions tests/pages/LocatorControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Dynamic\Locator\Tests;

use \DOMDocument;
use Dynamic\Locator\LocationCategory;
use Dynamic\Locator\Locator;
use Dynamic\Locator\LocatorController;
Expand Down Expand Up @@ -50,7 +49,7 @@ public function testXml()
$this->assertEquals(200, $page->getStatusCode());
$this->assertEquals('application/xml', $page->getHeader('content-type'));

$dom = new DOMDocument();
$dom = new \DOMDocument();
// true if it loads, false if it doesn't
$valid = $dom->loadXML($page->getBody());
$this->assertTrue($valid);
Expand Down