From 20704bca676ae0fbab2c328023b11a47815684e8 Mon Sep 17 00:00:00 2001 From: Patrick Ward Date: Tue, 29 Sep 2015 19:02:42 -0400 Subject: [PATCH] Allow minDate/maxDate to be entered in date format for DatePicker. Fixes #909. --- modules/backend/formwidgets/DatePicker.php | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/backend/formwidgets/DatePicker.php b/modules/backend/formwidgets/DatePicker.php index 390be8a2f..e1ce658f7 100644 --- a/modules/backend/formwidgets/DatePicker.php +++ b/modules/backend/formwidgets/DatePicker.php @@ -46,15 +46,35 @@ class DatePicker extends FormWidgetBase */ public function init() { - $this->fillFromConfig([ - 'mode', - 'minDate', - 'maxDate', - ]); - + $this->fillDatesFromConfig(); + $this->fillFromConfig(['mode']); $this->mode = strtolower($this->mode); } + /** + * Transfers minDate and maxDate config values stored inside the + * $config property directly on to the root object properties. + * + * This method checks for Yaml parsed dates that have been converted + * into integer timestamps via the Symfony Yaml parser and converts them + * back into strings for use with the datepicker. + * + * @param array $properties + * @return void + */ + protected function fillDatesFromConfig() + { + foreach(['minDate', 'maxDate'] as $property) { + + $this->{$property} = $this->getConfig($property, $this->{$property}); + + if (is_integer($this->{$property})) { + $this->{$property} = date('Y-m-d', $this->{$property}); + } + + } + } + /** * {@inheritDoc} */