This commit is contained in:
Samuel Georges 2015-10-17 08:54:40 +11:00
parent 54b4223660
commit f2e13ba3eb
1 changed files with 13 additions and 24 deletions

View File

@ -1,5 +1,6 @@
<?php namespace Backend\FormWidgets;
use Carbon\Carbon;
use Backend\Classes\FormWidgetBase;
/**
@ -46,33 +47,21 @@ class DatePicker extends FormWidgetBase
*/
public function init()
{
$this->fillDatesFromConfig();
$this->fillFromConfig(['mode']);
$this->fillFromConfig([
'mode',
'minDate',
'maxDate',
]);
$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->minDate = is_integer($this->minDate)
? Carbon::createFromTimestamp($this->minDate)
: Carbon::parse($this->minDate);
$this->{$property} = $this->getConfig($property, $this->{$property});
if (is_integer($this->{$property})) {
$this->{$property} = date('Y-m-d', $this->{$property});
}
}
$this->maxDate = is_integer($this->maxDate)
? Carbon::createFromTimestamp($this->maxDate)
: Carbon::parse($this->maxDate);
}
/**