You are here

protected function AutosaveButtonClickedTrait::isAutosaveTriggered in Autosave Form 8

Checks if the submission is triggered by autosave save.

Parameters

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

Return value

bool TRUE if the form submission is triggered by autosave, FALSE otherwise.

4 calls to AutosaveButtonClickedTrait::isAutosaveTriggered()
AutosaveFormBuilder::prepareForm in src/Form/AutosaveFormBuilder.php
Prepares a structured form array.
AutosaveFormBuilder::processForm in src/Form/AutosaveFormBuilder.php
Processes a form submission.
AutosaveFormErrorHandler::handleFormErrors in src/Form/AutosaveFormErrorHandler.php
Handles form errors after form validation.
AutosaveFormValidator::validateForm in src/Form/AutosaveFormValidator.php
Validates user-submitted form data in the $form_state.

File

src/Form/AutosaveButtonClickedTrait.php, line 19

Class

AutosaveButtonClickedTrait

Namespace

Drupal\autosave_form\Form

Code

protected function isAutosaveTriggered(FormStateInterface $form_state) {
  $triggering_element = $form_state
    ->getTriggeringElement();
  if (is_null($triggering_element)) {
    $user_input = $form_state
      ->getUserInput();
    $autosave = isset($user_input['_triggering_element_name']) && $user_input['_triggering_element_name'] == AutosaveFormInterface::AUTOSAVE_ELEMENT_NAME;
  }
  else {
    $autosave = $triggering_element && !empty($triggering_element['#autosave_form']);
  }
  return $autosave;
}