These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler; |
||
6 | |||
7 | use DateTime; |
||
8 | use eZ\Publish\API\Repository\Values\Content\Content; |
||
9 | use eZ\Publish\API\Repository\Values\ContentType\FieldDefinition; |
||
10 | use eZ\Publish\Core\FieldType\DateAndTime as DTValue; |
||
11 | use eZ\Publish\SPI\FieldType\Value; |
||
12 | use Netgen\Bundle\EzFormsBundle\Form\FieldTypeHandler; |
||
13 | use Symfony\Component\Form\Extension\Core\Type\DateTimeType; |
||
14 | use Symfony\Component\Form\FormBuilderInterface; |
||
15 | use Symfony\Component\Validator\Constraints as Assert; |
||
16 | |||
17 | class DateAndTime extends FieldTypeHandler |
||
18 | { |
||
19 | public function convertFieldValueToForm(Value $value, ?FieldDefinition $fieldDefinition = null): DateTime |
||
20 | { |
||
21 | return $value->value; |
||
0 ignored issues
–
show
|
|||
22 | } |
||
23 | |||
24 | public function convertFieldValueFromForm($data): DTValue\Value |
||
25 | { |
||
26 | return new DTValue\Value($data); |
||
27 | } |
||
28 | |||
29 | protected function buildFieldForm( |
||
30 | FormBuilderInterface $formBuilder, |
||
31 | FieldDefinition $fieldDefinition, |
||
32 | string $languageCode, |
||
33 | ?Content $content = null |
||
34 | ): void { |
||
35 | $options = $this->getDefaultFieldOptions($fieldDefinition, $languageCode, $content); |
||
36 | |||
37 | $useSeconds = $fieldDefinition->getFieldSettings()['useSeconds']; |
||
38 | $options['input'] = 'datetime'; |
||
39 | $options['date_widget'] = 'choice'; |
||
40 | $options['time_widget'] = 'choice'; |
||
41 | $options['with_seconds'] = $useSeconds; |
||
42 | $options['constraints'][] = new Assert\DateTime(); |
||
43 | |||
44 | $formBuilder->add($fieldDefinition->identifier, DateTimeType::class, $options); |
||
45 | } |
||
46 | } |
||
47 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: