public function ModerationStateWidget::extractFormValues in Lightning Scheduler 8
Extracts field values from submitted form values.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values. This parameter is altered by reference to receive the incoming form values.
array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Overrides WidgetBase::extractFormValues
File
- src/
Plugin/ Field/ FieldWidget/ ModerationStateWidget.php, line 146
Class
- ModerationStateWidget
- Scheduler extension of Content Moderation's widget.
Namespace
Drupal\lightning_scheduler\Plugin\Field\FieldWidgetCode
public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) {
parent::extractFormValues($items, $form, $form_state);
$transitions = $form_state
->getValue('transition_storage');
$entity = $items
->getEntity();
$uuid = $entity
->uuid();
// Do not use empty() here, because it's possible that the user is trying to
// clear all scheduled transitions, which means $transitions[$uuid] will
// be an empty array.
if (!isset($transitions[$uuid])) {
return;
}
$states = array_map(function (array $transition) {
assert(!empty($transition['state']) && is_string($transition['state']));
return [
'value' => $transition['state'],
];
}, $transitions[$uuid]);
$dates = array_map(function (array $transition) {
return [
'value' => gmdate(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $transition['when']),
];
}, $transitions[$uuid]);
assert(count($states) === count($dates));
$entity
->set('scheduled_transition_state', $states)
->set('scheduled_transition_date', $dates);
}