Simplify #1475
This commit is contained in:
parent
54b4223660
commit
f2e13ba3eb
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue