From 962aa32a60421a7a950465db2b7a0471d0045553 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Sat, 5 Aug 2017 12:38:20 -0600 Subject: [PATCH] Improve flexibility of scope type properties 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. --- modules/backend/widgets/Filter.php | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/backend/widgets/Filter.php b/modules/backend/widgets/Filter.php index 1d66cd651..8d5f712c4 100644 --- a/modules/backend/widgets/Filter.php +++ b/modules/backend/widgets/Filter.php @@ -463,17 +463,33 @@ class Filter extends WidgetBase } /* - * 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