You are here

SalvattoreAdminSettingsForm.php in Salvattore (CSS driven Masonry) 8

File

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

/**
 * @file
 * Contains \Drupal\salvattore\Form\SalvattoreAdminSettingsForm.
 */
namespace Drupal\salvattore\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
class SalvattoreAdminSettingsForm extends ConfigFormBase {

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this
      ->config('salvattore.settings');
    foreach (Element::children($form) as $variable) {
      $config
        ->set($variable, $form_state
        ->getValue($form[$variable]['#parents']));
    }
    $config
      ->save();
    if (method_exists($this, '_submitForm')) {
      $this
        ->_submitForm($form, $form_state);
    }
    parent::submitForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'salvattore.settings',
    ];
  }
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
    $form = [];
    $form['salvattore_use_min_js'] = [
      '#title' => t('Javascript file to use'),
      '#description' => t('Please choose whether you want the minified or the full version of the JS file.'),
      '#type' => 'radios',
      '#options' => [
        '1' => 'Minified',
        '0' => 'Full (debug)',
      ],
      '#default_value' => \Drupal::config('salvattore.settings')
        ->get('salvattore_use_min_js'),
    ];
    $form['salvattore_load_default_css'] = [
      '#title' => t('Load default CSS'),
      '#description' => t('Salvattore is easily configurable via CSS and you should write your own in your theme.<br>If some reason you want to use the default then enable this setting.'),
      '#type' => 'checkbox',
      '#default_value' => \Drupal::config('salvattore.settings')
        ->get('salvattore_load_default_css'),
    ];
    return parent::buildForm($form, $form_state);
  }

}

Classes