TimestampDateWidget
A date picker, without a time, for timestamp and created fields.
The field still stores a full timestamp, so the time of day comes from the widget's settings: either a fixed time, or the time of submission for a new item. An existing item keeps the time of day it already has unless a fixed time is configured, because a date with no time is parsed as that day at the current time, so every save would otherwise move it.
- Full name:
\Drupal\helper\Plugin\Field\FieldWidget\TimestampDateWidget - Parent class:
TimestampDatetimeWidget
Constants
| Constant | Visibility | Type | Value |
|---|---|---|---|
TIME_FORMAT |
public | 'H:i:s' |
Methods
defaultSettings
{@inheritdoc}
public static defaultSettings(): array
- This method is static.
settingsForm
{@inheritdoc}
public settingsForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
validateTime
Form element validation handler for the fixed time setting.
public static validateTime(array& $element, \Drupal\Core\Form\FormStateInterface $form_state): void
Stores the time with seconds, and requires one when it is used.
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$element |
array | |
| The time element. | ||
$form_state |
\Drupal\Core\Form\FormStateInterface | |
| The form state. |
settingsSummary
{@inheritdoc}
public settingsSummary(): array
formatTime
Formats a stored fixed time for display.
protected static formatTime(string $time): string
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$time |
string | |
| The stored time, in H:i:s format. |
Return Value:
The time in H:i format, or in H:i:s format when it has seconds. A time that is not valid, for example from imported configuration, is returned as it is rather than throwing an exception.
formElement
{@inheritdoc}
public formElement(\Drupal\Core\Field\FieldItemListInterface $items, mixed $delta, array $element, array& $form, \Drupal\Core\Form\FormStateInterface $form_state): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$items |
\Drupal\Core\Field\FieldItemListInterface | |
$delta |
mixed | |
$element |
array | |
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
massageFormValues
{@inheritdoc}
public massageFormValues(array $values, array $form, \Drupal\Core\Form\FormStateInterface $form_state): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$values |
array | |
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |