public function ModerationStateWidget::extractFormValues in Lightning Workflow 8.2
Same name and namespace in other branches
- 8.3 modules/lightning_scheduler/src/Plugin/Field/FieldWidget/ModerationStateWidget.php \Drupal\lightning_scheduler\Plugin\Field\FieldWidget\ModerationStateWidget::extractFormValues()
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
- modules/
lightning_scheduler/ src/ Plugin/ Field/ FieldWidget/ ModerationStateWidget.php, line 210
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) {
$date_time = new DrupalDateTime($transition['when'], 'UTC');
return [
'value' => $date_time
->format(DateTimeItemInterface::DATETIME_STORAGE_FORMAT),
];
}, $transitions[$uuid]);
assert(count($states) === count($dates));
$entity
->set('scheduled_transition_state', $states)
->set('scheduled_transition_date', $dates);
}