You are here

public function EditRepeatingRuleConfirmationModalForm::submitForm in Booking and Availability Management Tools for Drupal 8

Form submission handler.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides FormInterface::submitForm

File

modules/bat_event_series/src/Form/EditRepeatingRuleConfirmationModalForm.php, line 186
Contains \Drupal\bat_event_series\Form\EditRepeatingRuleConfirmationModalForm.

Class

EditRepeatingRuleConfirmationModalForm

Namespace

Drupal\bat_event_series\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  $values = $form_state
    ->getValues();
  $event_series_type = bat_event_series_type_load($this->event_series
    ->bundle());
  $event_granularity = $event_series_type
    ->getEventGranularity();
  $events = $values['events'];
  if (!empty($events['delete_events_ids'])) {
    $this
      ->deleteEvents($events['delete_events_ids']);
  }
  if (!empty($events['add_events'])) {
    $this
      ->addEvents($events['add_events']);
  }
  $new_values = $this->tempStore
    ->get($this
    ->currentUser()
    ->id());
  $rrule = new RRule([
    'FREQ' => strtoupper($new_values['repeat_frequency']),
    'UNTIL' => $new_values['repeat_until'] . 'T235959Z',
  ]);
  if ($event_granularity == 'bat_daily') {
    $event_dates = [
      'value' => $new_values['start_date']
        ->format('Y-m-d\\T00:00:00'),
      'end_value' => $new_values['end_date']
        ->format('Y-m-d\\T00:00:00'),
    ];
  }
  else {
    $event_dates = [
      'value' => $new_values['start_date']
        ->format('Y-m-d\\TH:i:00'),
      'end_value' => $new_values['end_date']
        ->format('Y-m-d\\TH:i:00'),
    ];
  }
  $this->event_series
    ->set('event_dates', $event_dates);
  $this->event_series
    ->set('rrule', $rrule
    ->rfcString());
  $this->event_series
    ->save();
}