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_modal / src / Form / MeltModalForm.php
Size: Mime:
<?php

namespace Drupal\melt_modal\Form;

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

/**
 * Class modalForm.
 */
class MeltModalForm extends ConfigFormBase {

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

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

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

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

    $form['external_link_settings'] = [
      '#type' => 'details',
      '#title' => $this->t('External Link Modal Settings'),
      '#description' => $this->t('Settings for external link modal'),
      // Controls the HTML5 'open' attribute. Defaults to FALSE.
      '#open' => TRUE,
    ];

    $form['external_link_settings']['extlink_enable'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Enable'),
      '#description' => $this->t('Enable if you want all 3rd party links to trigger a global modal.'),
      '#default_value' => $config->get('extlink_enable'),
    ];

    $form['external_link_settings']['extlink_modal_selector'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Modal ID'),
      '#description' => $this->t('CSS selector for modal. Defaults to <b>#external-link-modal</b>'),
      '#maxlength' => 64,
      '#size' => 64,
      '#default_value' => $config->get('extlink_modal_selector'),
    ];

    $form['external_link_settings']['extlink_continue_selector'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Modal Continue ID'),
      '#description' => $this->t('CSS selector for the continue link. Defaults to <b>.external-link-modal--continue</b>'),
      '#maxlength' => 64,
      '#size' => 64,
      '#default_value' => $config->get('extlink_continue_selector'),
    ];

    $form['external_link_settings']['extlink_whitelist'] = [
      '#type' => 'textarea',
      '#title' => $this->t('Whitelist Domains'),
      '#description' => $this->t('Domains to ignore. Enter 1 domain per line.'),
      '#default_value' => $config->get('extlink_whitelist'),
    ];

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

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

    $this->config('melt_modal.modal')
      ->set('extlink_modal_selector', $form_state->getValue('extlink_modal_selector'))
      ->set('extlink_continue_selector', $form_state->getValue('extlink_continue_selector'))
      ->set('extlink_whitelist', $form_state->getValue('extlink_whitelist'))
      ->set('extlink_enable', $form_state->getValue('extlink_enable'))
      ->save();
  }

}