public function DateRecurModularSierraWidget::massageFormValues in Recurring Date Field Modular Widgets 3.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::massageFormValues()
- 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::massageFormValues()
Massages the form values into the format expected for field values.
Parameters
array $values: The submitted form values produced by the widget.
- If the widget does not manage multiple values itself, the array holds the values generated by the multiple copies of the $element generated by the formElement() method, keyed by delta.
- If the widget manages multiple values, the array holds the values of the form element generated by the formElement() method.
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.
Return value
array An array of field values, keyed by delta.
Overrides DateRecurModularWidgetBase::massageFormValues
File
- src/
Plugin/ Field/ FieldWidget/ DateRecurModularSierraWidget.php, line 677
Class
- DateRecurModularSierraWidget
- Date recur sierra widget.
Namespace
Drupal\date_recur_modular\Plugin\Field\FieldWidgetCode
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
$dateStorageFormat = $this->fieldDefinition
->getSetting('datetime_type') == DateRecurItem::DATETIME_TYPE_DATE ? DateRecurItem::DATE_STORAGE_FORMAT : DateRecurItem::DATETIME_STORAGE_FORMAT;
$dateStorageTimeZone = new \DateTimezone(DateRecurItem::STORAGE_TIMEZONE);
$returnValues = [];
foreach ($values as $delta => $value) {
$returnValues[$delta] = [];
$item = [];
if (!empty($value['start'])) {
$item['value'] = (clone $value['start'])
->setTimezone($dateStorageTimeZone)
->format($dateStorageFormat);
}
if (!empty($value['end'])) {
$item['end_value'] = (clone $value['end'])
->setTimezone($dateStorageTimeZone)
->format($dateStorageFormat);
}
// If no start or end date then skip.
if (count($item) === 0) {
continue;
}
assert(strlen($value['time_zone']) > 0);
$item['timezone'] = $value['time_zone'];
if (!empty($value['rrule'])) {
$item['rrule'] = $value['rrule'];
}
$returnValues[$delta] = $item;
}
return $returnValues;
}