You are here

Settings.php in jQuery World Calendars API 3.x

Contains \Drupal\jquery_calendar\Form\JqueryCalendarSettings.

File

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

/**
 * @file
 * Contains \Drupal\jquery_calendar\Form\JqueryCalendarSettings.
 */
namespace Drupal\jquery_calendar\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\Element;
use Drupal\Core\Render\Markup;
use Drupal\Core\Url;
use Drupal\jquery_calendar\Error\MissingRequirements;
class Settings extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      'jquery_calendar.settings',
    ];
  }
  public function buildForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state) {
    try {
      jquery_calendar_requirements_check(null);
    } catch (MissingRequirements $e) {
      \Drupal::messenger()
        ->addMessage(Markup::create($e
        ->getMessage() . ' ' . $this
        ->t('Checkout the <a href="@link">status reports</a>.', [
        '@link' => Url::fromRoute('system.status')
          ->toString(),
      ])), \Drupal::messenger()::TYPE_ERROR);
      return [];
    }

    // Library compression level.
    $form['compression_level'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Library default compression level'),
      '#description' => $this
        ->t('Choose default library files compression level. This will be used as a fallback in case that the API implementer does not provide a level.'),
      '#default_value' => \Drupal::config('jquery_calendar.settings')
        ->get('compression_level'),
      '#options' => [
        'min' => $this
          ->t('Minified'),
        'normal' => $this
          ->t('No Compression'),
      ],
    ];

    // Calendars default theme.
    $form['datepicker_theme'] = [
      '#type' => 'select',
      '#title' => $this
        ->t('Datepicker default theme'),
      '#description' => $this
        ->t('Choose which datepicker theme you want to use. This will override datepicker theme settings set by other modules. You can add your own customized theme by placing it into the <code><u>@dir</u></code> directory respecting this filename format: <strong><em>theme-name</em>.calendars.picker.css</strong>', [
        '@dir' => 'sites/all/libraries/jquery.calendars',
      ]),
      '#default_value' => \Drupal::config('jquery_calendar.settings')
        ->get('datepicker_theme'),
      '#options' => jquery_calendar_datepicker_themes(),
    ];
    return parent::buildForm($form, $form_state);
  }

}

Classes

Namesort descending Description
Settings