| 1 | <?php |
||
| 12 | class Date extends Field |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Date format. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $format; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Render and format a Datetime. |
||
| 23 | * |
||
| 24 | * @param $value |
||
| 25 | * |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | 1 | public function render($value) |
|
| 29 | { |
||
| 30 | 1 | if ($value instanceof DateTime) { |
|
| 31 | 1 | $value = $value->format($this->format); |
|
| 32 | } |
||
| 33 | |||
| 34 | 1 | return $value; |
|
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param OptionsResolver $resolver |
||
| 39 | */ |
||
| 40 | 1 | public function configureOptions(OptionsResolver $resolver) |
|
| 41 | { |
||
| 42 | 1 | $resolver->setDefaults([ |
|
| 43 | 'format' => $this |
||
| 44 | 1 | ->applicationConfiguration |
|
| 45 | 1 | ->getParameter('date_format'), |
|
| 46 | ]); |
||
| 47 | 1 | } |
|
| 48 | |||
| 49 | /** |
||
| 50 | * @param array $options |
||
| 51 | */ |
||
| 52 | 1 | public function setOptions(array $options) |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @return string |
||
| 59 | */ |
||
| 60 | public function getType() |
||
| 64 | } |
||
| 65 |