1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
4
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
5
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
6
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
7
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
8
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace MpaCustomDoctrineHydrator\Form\Element; |
12
|
|
|
|
13
|
|
|
use Zend\Filter\StringTrim; |
14
|
|
|
use Zend\Form\Element\Date as ZendDate; |
15
|
|
|
use Zend\InputFilter\InputProviderInterface; |
16
|
|
|
|
17
|
|
|
class Date extends ZendDate implements InputProviderInterface |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Override the type="date" because we can't |
21
|
|
|
* set a placeholder on html5 date input |
22
|
|
|
*/ |
23
|
|
|
protected $attributes = ['type' => 'text']; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Accepted options for DateTime: |
27
|
|
|
* - format: A \DateTime compatible string |
28
|
|
|
* |
29
|
|
|
* @param array|\Traversable $options |
30
|
|
|
* @return \DateTime |
31
|
|
|
*/ |
32
|
3 |
|
public function setOptions($options) |
33
|
|
|
{ |
34
|
3 |
|
parent::setOptions($options); |
35
|
|
|
|
36
|
3 |
|
if (isset($this->options['date_format'])) { |
37
|
1 |
|
$this->setFormat($this->options['date_format']); |
38
|
|
|
} |
39
|
|
|
|
40
|
3 |
|
return $this; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Provide default input rules for this element |
45
|
|
|
* Attaches default validators for the Date input. |
46
|
|
|
* |
47
|
|
|
* @return array |
48
|
|
|
*/ |
49
|
5 |
|
public function getInputSpecification() |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
5 |
|
'name' => $this->getName(), |
53
|
|
|
'required' => true, |
54
|
|
|
'filters' => [ |
55
|
|
|
['name' => StringTrim::class], |
56
|
|
|
[ |
57
|
5 |
|
'name' => 'MpaCustomDoctrineHydrator\Filter\DateToDateTime', |
58
|
|
|
'options' => [ |
59
|
5 |
|
'date_format' => $this->getFormat(), |
60
|
|
|
] |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
'validators' => [ |
64
|
5 |
|
$this->getDateValidator() |
65
|
|
|
], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|