You are here

public function DateRecurDefaultWidget::massageFormValues in Recurring Dates Field 8

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 DateRangeWidgetBase::massageFormValues

File

src/Plugin/Field/FieldWidget/DateRecurDefaultWidget.php, line 138

Class

DateRecurDefaultWidget
Plugin implementation of the 'date_recur_default_widget' widget.

Namespace

Drupal\date_recur\Plugin\Field\FieldWidget

Code

public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
  foreach ($values as &$item) {
    $item['infinite'] = 0;
    if (empty($item['rrule'])) {
      $item['rrule'] = '';
    }
    else {
      if (!empty($item['value']) && $item['value'] instanceof DrupalDateTime) {
        try {
          $rule = new DateRecurRRule($item['rrule'], $item['value']);
          if ($rule
            ->isInfinite()) {
            $item['infinite'] = 1;
          }
        } catch (\InvalidArgumentException $e) {

          // No-op, this is handled in validateRrule().
        }
      }
    }
    $item['timezone'] = $this
      ->getTimezone();
    if (empty($item['end_value'])) {
      $item['end_value'] = $item['value'];
    }
  }
  return parent::massageFormValues($values, $form, $form_state);
}