function ViewUI::standardSubmit

Same name in other branches
  1. 8.9.x core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\ViewUI::standardSubmit()
  2. 10 core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\ViewUI::standardSubmit()
  3. 11.x core/modules/views_ui/src/ViewUI.php \Drupal\views_ui\ViewUI::standardSubmit()

Basic submit handler applicable to all 'standard' forms.

This submit handler determines whether the user wants the submitted changes to apply to the default display or to the current display, and dispatches control appropriately.

File

core/modules/views_ui/src/ViewUI.php, line 222

Class

ViewUI
Stores UI related temporary settings.

Namespace

Drupal\views_ui

Code

public function standardSubmit($form, FormStateInterface $form_state) {
    // Determine whether the values the user entered are intended to apply to
    // the current display or the default display.
    [
        $was_defaulted,
        $is_defaulted,
        $revert,
    ] = $this->getOverrideValues($form, $form_state);
    // Based on the user's choice in the display dropdown, determine which display
    // these changes apply to.
    $display_id = $form_state->get('display_id');
    if ($revert) {
        // If it's revert just change the override and return.
        $display =& $this->getExecutable()->displayHandlers
            ->get($display_id);
        $display->optionsOverride($form, $form_state);
        // Don't execute the normal submit handling but still store the changed view into cache.
        $this->cacheSet();
        return;
    }
    elseif ($was_defaulted === $is_defaulted) {
        // We're not changing which display these form values apply to.
        // Run the regular submit handler for this form.
    }
    elseif ($was_defaulted && !$is_defaulted) {
        // We were using the default display's values, but we're now overriding
        // the default display and saving values specific to this display.
        $display =& $this->getExecutable()->displayHandlers
            ->get($display_id);
        // optionsOverride toggles the override of this section.
        $display->optionsOverride($form, $form_state);
        $display->submitOptionsForm($form, $form_state);
    }
    elseif (!$was_defaulted && $is_defaulted) {
        // We used to have an override for this display, but the user now wants
        // to go back to the default display.
        // Overwrite the default display with the current form values, and make
        // the current display use the new default values.
        $display =& $this->getExecutable()->displayHandlers
            ->get($display_id);
        // optionsOverride toggles the override of this section.
        $display->optionsOverride($form, $form_state);
        $display->submitOptionsForm($form, $form_state);
    }
    $submit_handler = [
        $form_state->getFormObject(),
        'submitForm',
    ];
    call_user_func_array($submit_handler, [
        &$form,
        $form_state,
    ]);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.