Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
drupal/melt_glossify / src / Form / MeltGlossifyForm.php
Size: Mime:
<?php

namespace Drupal\melt_glossify\Form;

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

/**
 * Class glossifyForm.
 */
class MeltGlossifyForm extends ConfigFormBase {

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('config.factory')
    );
  }

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

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

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

    $form['tippy_settings'] = [
      '#type' => 'details',
      '#title' => $this->t('Tippy.js settings'),
      '#description' => $this->t('Settings for Tippyjs'),
      // Controls the HTML5 'open' attribute. Defaults to FALSE.
      '#open' => TRUE,
    ];

    $form['tippy_settings']['tippyjs_yaml'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Tippy.js Options'),
      '#description' => $this->t('Use YAML syntax for the options object passed to <b>tippyjs(options)</b> function. See <a href="https://atomiks.github.io/tippyjs/all-options/" target="_blank">Tippy.js options</a>.'),
      '#default_value' => $config->get('tippyjs.yaml'),
      '#attributes' => ['data-yaml-editor' => 'true'],
    ];

    $form['tippy_settings']['tippyjs_color'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Tooltip color'),
      '#description' => $this->t('CSS color property to color the background and arrow of the tooltip. Defaults to what Tippy.js provides.'),
      '#default_value' => $config->get('tippyjs.color'),
    ];

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

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form, $form_state);

    $this->config('melt_glossify.settings')
      ->set('tippyjs.yaml', $form_state->getValue('tippyjs_yaml'))
      ->set('tippyjs.color', $form_state->getValue('tippyjs_color'))
      ->save();
  }

}