You are here

public function FieldsSettingsForm::multiStepSubmit in Diff 8

Form submission handler for multi-step buttons.

Parameters

array $form: The form array.

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

File

src/Form/FieldsSettingsForm.php, line 319

Class

FieldsSettingsForm
Configure fields with their diff builder plugin settings.

Namespace

Drupal\diff\Form

Code

public function multiStepSubmit(array $form, FormStateInterface $form_state) {
  $trigger = $form_state
    ->getTriggeringElement();
  $op = $trigger['#op'];
  switch ($op) {
    case 'edit':

      // Store the field whose settings are currently being edited.
      $field_key = $trigger['#field_key'];
      $form_state
        ->set('plugin_settings_edit', $field_key);
      break;
    case 'update':

      // Store the saved settings, and set the field back to 'non edit' mode.
      $field_key = $trigger['#field_key'];
      if ($plugin_settings = $form_state
        ->getValue([
        'fields',
        $field_key,
        'settings_edit_form',
        'settings',
      ])) {
        $form_state
          ->set([
          'plugin_settings',
          $field_key,
          'settings',
        ], $plugin_settings);
      }
      $form_state
        ->set('plugin_settings_edit', NULL);
      break;
    case 'cancel':

      // Set the field back to 'non edit' mode.
      $form_state
        ->set('plugin_settings_edit', NULL);
      break;
  }
  $form_state
    ->setRebuild();
}