protected function ScheduledPublishWidget::prepareFormState in Scheduled Publish 8.3
Prepares the form state for the current widget.
1 call to ScheduledPublishWidget::prepareFormState()
- ScheduledPublishWidget::formElement in src/
Plugin/ Field/ FieldWidget/ ScheduledPublishWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ ScheduledPublishWidget.php, line 148
Class
- ScheduledPublishWidget
- Plugin implementation of the 'scheduled_publish_widget' widget.
Namespace
Drupal\scheduled_publish\Plugin\Field\FieldWidgetCode
protected function prepareFormState(FormStateInterface $form_state, FieldItemListInterface $items, $field_name) {
$entries = $form_state
->get([
'scheduled_publish',
$field_name,
]);
if (!isset($entries)) {
$entries = [];
// Store the $items in the form state for further manipulation.
foreach ($items as $delta => $item) {
$date = $item->date;
$date
->setTimezone(new \DateTimeZone(date_default_timezone_get()));
$date_display = $date
->format('d.m.Y - H:i');
$date
->setTimezone(new \DateTimezone(ScheduledPublish::STORAGE_TIMEZONE));
$entries[$delta] = [
'date' => $date
->format(ScheduledPublish::DATETIME_STORAGE_FORMAT),
'date_display' => $date_display,
'state' => $item->moderation_state,
'state_display' => NULL,
'state_options' => [],
'delta' => $delta,
'form' => NULL,
];
}
$form_state
->set([
'scheduled_publish',
$field_name,
], $entries);
$this
->handleEntries($form_state, $field_name);
}
}