You are here

CourseSettingsForm.php in Course 3.x

Namespace

Drupal\course\Form

File

src/Form/CourseSettingsForm.php
View source
<?php

namespace Drupal\course\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
class CourseSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() : array {
    return [
      'course.settings',
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() : string {
    return 'course_settings_overview';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('course.settings');
    $form['testing'] = [
      '#type' => 'textarea',
      '#title' => $this
        ->t('Welcome message'),
      '#description' => $this
        ->t('Welcome message display to users when they login'),
      '#default_value' => $config
        ->get('testing'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this
      ->config('course.settings')
      ->setData($form_state
      ->getValues())
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
CourseSettingsForm