bootstrap_theme_toggler-2.0.0/src/Form/TogglerSettingsForm.php

src/Form/TogglerSettingsForm.php
<?php


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


/**
 * Global Configuration form for the Bootstrap Theme Toggler.
 */
class TogglerSettingsForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    // name used to recall this configuration form data
    return ['bootstrap_theme_toggler.settings'];
  }


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


  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    $config = $this->config('bootstrap_theme_toggler.settings');

    $form['color_mode_sass_directory'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Alternate path to find custom color mode definitions'),
      '#description' => $this->t("By default, the Theme Toggler will look for custom color mode's defined by `.scss` files with a leading underscore, inside `bootstrap_theme_toggler/scss`. To use a different folder, enter the alternate path here. This path should be relative to the site root, most often this will be `web`.
      <br><br>
      For example if you have custom color mode `_mytheme.scss` inside a folder called `scss`, inside a custom theme called `my_custom_theme`, you would set this path to be:
        <br> <b>`themes\custom\my_custom_theme\scss\`</b>  --- don't forget trailing slash '\'"),
      '#default_value' => $config->get('color_mode_sass_directory') ?? '',
    ];
    $form['add_custom_color_modes'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Add custom color modes to my non Barrio SASS Starter Kit Theme'),
      '#description' => $this->t("Because the general use case of the Theme Toggler, with SASS, is a sub-theme generated by the Bootstrap Barrio Starter Kit, by default, the Theme Toggler will only add custom color mode theme's to the drop-down if it finds a `gulpfile.js` file in theme's root folder. If using a SASS based theme that does not contain a `gulpfile.js`, check this box to force the Theme Toggler to still add custom color modes to the drop-down."),
      '#default_value' => $config->get('add_custom_color_modes') ?? false,
    ];

    return parent::buildForm($form, $form_state);
  }


  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form,
    FormStateInterface $form_state) {
    $this->config('bootstrap_theme_toggler.settings')
      ->set('use_custom_path', $form_state->getValue('use_custom_path'))
      ->set('color_mode_sass_directory', $form_state->getValue('color_mode_sass_directory'))
      ->set('add_custom_color_modes', $form_state->getValue('add_custom_color_modes'))

      ->save();
    parent::submitForm($form, $form_state);
  }


}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc