wetboew_webform_example-1.0.x-dev/src/Form/SettingsForm.php
src/Form/SettingsForm.php
<?php namespace Drupal\wetboew_webform_example\Form; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; /** * Configure WetBoew Webform Example settings for this site. */ class SettingsForm extends ConfigFormBase { /** * {@inheritdoc} */ public function getFormId() { return 'wetboew_webform_example_settings'; } /** * {@inheritdoc} */ protected function getEditableConfigNames() { return ['wetboew_webform_example.settings']; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['example'] = [ '#type' => 'textfield', '#title' => $this->t('Example setting'), '#default_value' => $this->config('wetboew_webform_example.settings')->get('example'), ]; return parent::buildForm($form, $form_state); } /** * {@inheritdoc} */ public function validateForm(array &$form, FormStateInterface $form_state) { if (is_numeric($form_state->getValue('example'))) { $form_state->setErrorByName('example', $this->t('The value is not supposed to be a number, please make it alpha numeric or alpha string.')); } parent::validateForm($form, $form_state); } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->config('wetboew_webform_example.settings') ->set('example', $form_state->getValue('example')) ->save(); parent::submitForm($form, $form_state); } }