Skip to content

Commit

Permalink
Improve flexibility of scope type properties
Browse files Browse the repository at this point in the history
Improves the flexibility of scope type properties by removing conditional logic specific to the date and daterange scope types and laying the groundwork for scopes to define their own custom properties that can be loaded from the scope configuration defined by the developer.
  • Loading branch information
LukeTowers authored Aug 5, 2017
1 parent d733431 commit 962aa32
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions modules/backend/widgets/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,17 +463,33 @@ public function addScopes(array $scopes)
}

/*
* Ensure dates options are set
* Ensure scope type options are set
*/
if (!isset($config['minDate'])) {
$scopeObj->minDate = '2000-01-01';
$scopeObj->maxDate = '2099-12-31';
$scopeProperties = [];
switch ($scopeObj->type) {
case 'date':
case 'daterange':
$scopeProperties = [
'minDate' => '2000-01-01',
'maxDate' => '2099-12-31',
'yearRange' => 10,
];

break;
}

foreach ($scopeProperties as $property => $value) {
if (isset($config[$property])) {
$value = $config[$property];
}

$scopeObj->{$property} = $value;
}

$this->allScopes[$name] = $scopeObj;
}
}

/**
* Programatically remove a scope, used for extensibility.
* @param string $scopeName Scope name
Expand Down

0 comments on commit 962aa32

Please sign in to comment.