-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathDateIntervalField.php
More file actions
53 lines (46 loc) · 1.67 KB
/
Copy pathDateIntervalField.php
File metadata and controls
53 lines (46 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace EasyCorp\Bundle\EasyAdminBundle\Field;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use Symfony\Component\Form\Extension\Core\Type\DateIntervalType;
use Symfony\Contracts\Translation\TranslatableInterface;
/**
* @author Pascal CESCON <pascal.cescon@gmail.com>
*/
final class DateIntervalField implements FieldInterface
{
use FieldTrait;
public const OPTION_FORMAT = 'format';
public static function new(string $propertyName, TranslatableInterface|string|bool|null $label = null): self
{
return (new self())
->setProperty($propertyName)
->setLabel($label)
->setTemplateName('crud/field/date_interval')
->setFormType(DateIntervalType::class)
->setFormTypeOptions([
'widget' => 'single_text',
'input' => 'dateinterval',
'with_years' => true,
'with_months' => true,
'with_weeks' => false,
'with_days' => true,
'with_hours' => true,
'with_minutes' => true,
'with_seconds' => true,
])
->addCssClass('field-date-interval')
->setDefaultColumns('col-md-6 col-xxl-5')
->setCustomOption(self::OPTION_FORMAT, null);
}
/**
* Set a custom format string passed to DateInterval::format().
*
* When set, this overrides the localized rendering and the value is
* displayed using the raw DateInterval::format() output.
*/
public function setFormat(?string $format): self
{
$this->setCustomOption(self::OPTION_FORMAT, $format);
return $this;
}
}