Completed
Push — 0.3-dev ( 291149...449c2f )
by Arnaud
14:26
created

Date::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace LAG\AdminBundle\Field\Field;
4
5
use LAG\AdminBundle\Field\Field;
6
use DateTime;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Date field.
11
 */
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
    public function render($value)
29
    {
30
        if ($value instanceof DateTime) {
31
            $value = $value->format($this->format);
32
        }
33
34
        return $value;
35
    }
36
37
    public function configureOptions(OptionsResolver $resolver)
38
    {
39
        $resolver->setDefaults([
40
            'format' => $this->configuration->getDateFormat(),
41
        ]);
42
    }
43
44
    public function setOptions(array $options)
45
    {
46
        $this->format = $options['format'];
47
    }
48
49
    public function getType()
50
    {
51
        return 'date';
52
    }
53
}
54