You are here

protected function DateRecurModularSierraWidget::transferStateToTempstore in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::transferStateToTempstore()
  2. 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::transferStateToTempstore()

Transfers element state to tempstore ready for modal to consume.

Parameters

array $element: A single form element.

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

2 calls to DateRecurModularSierraWidget::transferStateToTempstore()
DateRecurModularSierraWidget::openOccurrencesModal in src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php
Callback to convert RRULE data from form to modal then open modal.
DateRecurModularSierraWidget::openTheModal in src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php
Callback to convert RRULE data from form to modal then open modal.

File

src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php, line 757

Class

DateRecurModularSierraWidget
Date recur sierra widget.

Namespace

Drupal\date_recur_modular\Plugin\Field\FieldWidget

Code

protected function transferStateToTempstore(array $element, FormStateInterface $form_state) : void {
  $formParents = $element['#array_parents'];
  $valueParents = $element['#parents'];

  // Transfer RULE and Start Date to temporary storage.
  $timeZone = $form_state
    ->getValue(array_merge($valueParents, [
    'time_zone',
  ]));
  try {
    $startDate = '';
    $startDate = static::buildDatesFromFields(array_merge($formParents, [
      'day_start',
    ]), array_merge($formParents, [
      'time_start',
    ]), $timeZone, $form_state);
  } catch (\Exception $e) {
  }
  $startDateStr = $startDate instanceof \DateTime ? $startDate
    ->format(static::COLLECTION_MODAL_STATE_DTSTART_FORMAT) : '';
  $path = $form_state
    ->getValue(array_merge($valueParents, [
    'field_path',
  ]));
  $rruleState = $form_state
    ->get([
    static::FORM_STATE_RRULE_KEY,
    $path,
  ]) ?? $form_state
    ->getValue(array_merge($valueParents, [
    'rrule_in_storage',
  ]));
  $collection = $this->tempStoreFactory
    ->get(static::COLLECTION_MODAL_STATE);
  $collection
    ->set(static::COLLECTION_MODAL_STATE_KEY, $rruleState);
  $collection
    ->set(static::COLLECTION_MODAL_STATE_DTSTART, $startDateStr);
  $collection
    ->set(static::COLLECTION_MODAL_STATE_PATH, $path);
  $collection
    ->set(static::COLLECTION_MODAL_DATE_FORMAT, $this
    ->getSetting('date_format_type'));
  $collection
    ->set(static::COLLECTION_MODAL_STATE_REFRESH_BUTTON, $element['buttons']['reload_recurrence_dropdown_custom']['#name']);
}