You are here

SettingsForm.php in Moderation Dashboard 8

Same filename and directory in other branches
  1. 2.0.x src/Form/SettingsForm.php

File

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

namespace Drupal\moderation_dashboard\Form;

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

/**
 * The settings form for Moderation Dashboard.
 */
class SettingsForm extends ConfigFormBase {

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

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'moderation_dashboard_settings_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('moderation_dashboard.settings');
    $form['redirect_on_login'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Redirect on login'),
      '#default_value' => $config
        ->get('redirect_on_login'),
      '#description' => $this
        ->t('Redirect to moderation dashboard after login.'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $this
      ->config('moderation_dashboard.settings')
      ->set('redirect_on_login', $values['redirect_on_login'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
SettingsForm The settings form for Moderation Dashboard.