You are here

SettingsForm.php in Simple Meta 8

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

File

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

namespace Drupal\simplemeta\Form;

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

/**
 * Class SettingsForm.
 *
 * @package Drupal\simplemeta\Form
 *
 * @ingroup simplemeta
 */
class SettingsForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('simplemeta.settings');
    $form['form_enable'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable Add Meta Tags Form'),
      '#description' => t('If enabled, form will appear on pages'),
      '#default_value' => $config
        ->get('form_enable'),
      '#return_value' => TRUE,
    );
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('simplemeta.settings');
    $config
      ->set('form_enable', $form_state
      ->getValue('form_enable'))
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
SettingsForm Class SettingsForm.