ConfigSimpleExampleSettingsForm.php

Namespace

Drupal\config_simple_example\Form

File

modules/config_simple_example/src/Form/ConfigSimpleExampleSettingsForm.php

View source
<?php

namespace Drupal\config_simple_example\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Configure example settings for this site.
 */
class ConfigSimpleExampleSettingsForm extends ConfigFormBase {
    
    /**
     * {@inheritdoc}
     */
    public function getFormId() {
        return 'config_simple_example_settings';
    }
    
    /**
     * {@inheritdoc}
     */
    protected function getEditableConfigNames() {
        return [
            'config_simple_example.settings',
        ];
    }
    
    /**
     * {@inheritdoc}
     */
    public function buildForm(array $form, FormStateInterface $form_state) {
        $config = $this->config('config_simple_example.settings');
        $form['message'] = [
            '#type' => 'textarea',
            '#title' => $this->t('Message'),
            '#default_value' => $config->get('message'),
        ];
        return parent::buildForm($form, $form_state);
    }
    
    /**
     * {@inheritdoc}
     */
    public function submitForm(array &$form, FormStateInterface $form_state) {
        // Retrieve the configuration.
        $this->config('config_simple_example.settings')
            ->set('message', $form_state->getValue('message'))
            ->save();
        parent::submitForm($form, $form_state);
    }

}

Classes

Title Deprecated Summary
ConfigSimpleExampleSettingsForm Configure example settings for this site.