function FormTestStorageForm::elementValidateValueCached

Same name and namespace in other branches
  1. 8.9.x core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php \Drupal\form_test\Form\FormTestStorageForm::elementValidateValueCached()
  2. 10 core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php \Drupal\form_test\Form\FormTestStorageForm::elementValidateValueCached()
  3. 11.x core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php \Drupal\form_test\Form\FormTestStorageForm::elementValidateValueCached()

Form element validation handler for 'value' element.

Tests updating of cached form storage during validation.

File

core/modules/system/tests/modules/form_test/src/Form/FormTestStorageForm.php, line 118

Class

FormTestStorageForm
A multistep form for testing the form storage.

Namespace

Drupal\form_test\Form

Code

public function elementValidateValueCached($element, FormStateInterface $form_state) {
    // If caching is enabled and we receive a certain value, change the storage.
    // This presumes that another submitted form value triggers a validation error
    // elsewhere in the form. Form API should still update the cached form storage
    // though.
    if ($this->getRequest()
        ->get('cache') && $form_state->getValue('value') == 'change_title') {
        $form_state->set([
            'thing',
            'changed',
        ], TRUE);
    }
}

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