gridstack-8.x-2.5/modules/gridstack_ui/src/Form/GridStackSettingsForm.php

modules/gridstack_ui/src/Form/GridStackSettingsForm.php
<?php

namespace Drupal\gridstack_ui\Form;

use Drupal\Core\Url;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\gridstack\GridStackDefault;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Defines the GridStack admin settings form.
 */
class GridStackSettingsForm extends ConfigFormBase {

  /**
   * The library discovery service.
   *
   * @var \Drupal\Core\Asset\LibraryDiscoveryInterface
   */
  protected $libraryDiscovery;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    $instance = parent::create($container);
    $instance->libraryDiscovery = $container->get('library.discovery');
    return $instance;
  }

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

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

  /**
   * Implements \Drupal\Core\Form\FormInterface::buildForm().
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('gridstack.settings');

    $form['debug'] = [
      '#type'          => 'checkbox',
      '#title'         => $this->t('Debug'),
      '#description'   => $this->t('Only enable for debugging purposes. Disable at production. Currently only showing INDEX numbering for each box to know/ adjust stamp placements. Or grey outline.'),
      '#default_value' => $config->get('debug'),
    ];

    $form['dev'] = [
      '#type'          => 'checkbox',
      '#title'         => $this->t('Use non-minified GridStack library'),
      '#description'   => $this->t('Only enable for debugging purposes at <b>GridStack UI admin pages</b>. This will replace the minified version with <code>gridstack.js</code> and <code>gridstack.jQueryUI.js</code>.'),
      '#default_value' => $config->get('dev'),
    ];

    $form['framework'] = [
      '#type'          => 'select',
      '#title'         => $this->t('Grid framework'),
      '#options'       => [
        'bootstrap3' => 'Bootstrap 3',
        'bootstrap'  => 'Bootstrap 4',
        'foundation' => 'Foundation 5',
      ],
      '#empty_option' => '- None -',
      '#description'   => $this->t("By default GridStack supports dynamic magazine layouts -- js-driven. Choose a grid framework to also support static grids -- css-driven.<br>This will be used as a replacement for GridStack JS whenever provided/ overriden <strong>per optionset</strong>. This means no GridStack JS/ CSS assets are loaded for the active optionset. Your Bootstrap/ Foundation grid framework will take over. GridStack acts more like a layout builder for those static grids. Yet still usable as original dynamic magazine layouts as well, <strong>per optionset</strong>. <br>GridStack doesn't load the Bootstrap/Foundation library for you. Have a theme, or module, which does it."),
      '#default_value' => $config->get('framework'),
    ];

    // See https://getbootstrap.com/docs/4.0/migration/
    // See https://get.foundation/sites/docs
    $form['fw_classes'] = [
      '#type'          => 'textarea',
      '#title'         => $this->t('Framework CSS classes'),
      '#description'   => $this->t('Specify non-grid aka. cosmetic valid CSS classes with pipe and space delimiters, one line per group, e.g.: <br><code>background|bg-primary bg-primary--light bg-danger</code><br><code>callout|callout--primary callout--warning</code><br>where the left hand before the pipe is the group name and the right the names of classes delimited by a space. This option will be available at Layout Builder configuration page when a GridStack layout is selected under option <b>Preset classes</b>. Check them out, avoid dups, avoid grid classes like <code>col-</code> since these are managed by GridStack UI. The current existing groups: <br>Bootstrap/ Foundation: <code>text_align text_color text_transform utility visibility</code> <br>BS 3-4: <code>background</code> <br>BS 3: <code>hidden visible</code> <br>Check out Bootstrap/ Foundation versions. These classes are applied to grid containers (<code>.box</code> for native CSS Grid or js-driven layouts, or <code>.box__content</code> for Bootstrap/Foundation grids to avoid overlapping backgrounds). Not applied to anything like IMG, TABLE, etc. Not all CSS classes are applicable.'),
      '#default_value' => $config->get('fw_classes'),
    ];

    $form['excludes'] = [
      '#type'          => 'textarea',
      '#title'         => $this->t('Exclude optionsets'),
      '#description'   => $this->t('Specify optionset IDs to exclude from Layout Builder layout options with a comma delimiter, all in one line, e.g.: <br><code>tagore, paz, foundation</code>. Default to <code>default</code>. Be sure to clear caches.'),
      '#default_value' => $config->get('excludes'),
    ];

    $form['library'] = [
      '#type'          => 'textfield',
      '#title'         => $this->t('Grid library'),
      '#description'   => $this->t('Specify CSS grid library to load at admin pages such as for core layout builder pages, e.g.: <code>bootstrap_library/bootstrap, my_theme/bootstrap</code>, etc. Use comma for multiple libraries.'),
      '#default_value' => $config->get('library'),
    ];

    $form['optimized'] = [
      '#type'          => 'checkbox',
      '#title'         => $this->t('Optimize CSS grid classes'),
      '#description'   => $this->t('<b>Experimental!</b> Check to optimize CSS classes by removing duplicate grid rules, mobile first. E.g.:<br><code>col col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12</code> becomes <code>col col-12</code> <br><code>col col-12 col-sm-6 col-md-6 col-lg-4 col-xl-4</code> becomes <code>col col-12 col-sm-6 col-lg-4</code> <br>Uncheck if any issue.'),
      '#default_value' => $config->get('optimized'),
    ];

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

  /**
   * Implements \Drupal\Core\Form\FormInterface::submitForm().
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $config = $this->configFactory->getEditable('gridstack.settings');
    foreach (array_keys(GridStackDefault::uiSettings()) as $key) {
      $config->set($key, $form_state->getValue($key));
    }
    $config->save();

    // Invalidate the library discovery cache to update new assets.
    $this->libraryDiscovery->clearCachedDefinitions();
    $this->configFactory->clearStaticCache();

    // If anything fails, notice to clear the cache.
    $this->messenger()->addMessage($this->t('Be sure to <a href=":clear_cache">clear the cache</a> <strong>ONLY IF</strong> trouble to see the updated libraries.', [':clear_cache' => Url::fromRoute('system.performance_settings')->toString()]));

    parent::submitForm($form, $form_state);
  }

}

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

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