autosave_form_test.module in Autosave Form 8
File
tests/modules/autosave_form_test/autosave_form_test.moduleView source
<?php
use Drupal\autosave_form\Form\AutosaveFormInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_alter().
*/
function autosave_form_test_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (isset($form[AutosaveFormInterface::AUTOSAVE_ELEMENT_NAME])) {
$form[AutosaveFormInterface::AUTOSAVE_ELEMENT_NAME]['#submit'][] = 'autosave_form_test_autosave_submit';
}
if (\Drupal::state()
->get('disable_html5_validation')) {
// Disable HTML5 validation.
$form['#attributes']['novalidate'] = 'novalidate';
}
}
function autosave_form_test_autosave_submit($form, FormStateInterface $form_state) {
/** @var \Drupal\Core\State\StateInterface $state */
$state = \Drupal::state();
$count = $state
->get('autosave_submit_count', 0);
$state
->set('autosave_submit_count', ++$count);
}
Functions
Name | Description |
---|---|
autosave_form_test_autosave_submit | |
autosave_form_test_form_alter | Implements hook_form_alter(). |