You are here

BUEditorSettingsForm.php in BUEditor 8

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

File

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

namespace Drupal\bueditor\Form;

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

/**
 * BUEditor settings form.
 */
class BUEditorSettingsForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config('bueditor.settings');
    $form['devmode'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable development mode'),
      '#default_value' => $config
        ->get('devmode'),
      '#description' => $this
        ->t('In development mode minified libraries are replaced by source libraries to make debugging easier.'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('bueditor.settings');

    // Invalidate library cache if devmode has changed.
    $devmode = $form_state
      ->getValue('devmode');
    if ($config
      ->get('devmode') != $devmode) {
      \Drupal::cache('discovery')
        ->invalidate('library_info');
    }

    // Save config
    $config
      ->set('devmode', $devmode)
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
BUEditorSettingsForm BUEditor settings form.