| 1 | <?php |
||
| 22 | final class DatetimeFieldType implements FieldTypeInterface |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var DataExtractorInterface |
||
| 26 | */ |
||
| 27 | private $dataExtractor; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param DataExtractorInterface $dataExtractor |
||
| 31 | */ |
||
| 32 | public function __construct(DataExtractorInterface $dataExtractor) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * {@inheritdoc} |
||
| 39 | */ |
||
| 40 | public function render(Field $field, $data, array $options) |
||
| 41 | { |
||
| 42 | $value = $this->dataExtractor->get($field, $data); |
||
| 43 | if (null === $value) { |
||
| 44 | return null; |
||
| 45 | } |
||
| 46 | |||
| 47 | Assert::isInstanceOf($value, \DateTime::class); |
||
| 48 | |||
| 49 | return $value->format($options['format']); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * {@inheritdoc} |
||
| 54 | */ |
||
| 55 | public function configureOptions(OptionsResolver $resolver) |
||
| 56 | { |
||
| 57 | $resolver->setDefaults([ |
||
| 58 | 'format' => 'Y:m:d H:i:s' |
||
| 59 | ]); |
||
| 60 | $resolver->setAllowedTypes([ |
||
|
|
|||
| 61 | 'format' => 'string' |
||
| 62 | ]); |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | public function getName() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * {@inheritdoc} |
||
| 75 | */ |
||
| 76 | public function getBlockPrefix() |
||
| 80 | } |
||
| 81 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: