You are here

LiveChatSettingsForm.php in LiveChat 8

Same filename and directory in other branches
  1. 8.2 src/Form/LiveChatSettingsForm.php

File

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

namespace Drupal\livechat\Form;

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

/**
 * Configure Coffee for this site.
 */
class LiveChatSettingsForm extends ConfigFormBase {

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

  /**
   * {@inheritdoc}
   */
  protected function getEditableConfigNames() {
    return [
      LIVECHAT_CONFIGURATION_NAME,
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this
      ->config(LIVECHAT_CONFIGURATION_NAME);
    $form['path'] = [
      '#type' => 'details',
      '#title' => $this
        ->t('Visibility'),
      '#open' => TRUE,
    ];
    $form['path']['livechat_visibility'] = [
      '#type' => 'radios',
      '#title' => $this
        ->t('Show LiveChat on'),
      '#options' => array(
        LIVECHAT_VISIBILITY_NOTLISTED => $this
          ->t('All pages except those listed'),
        LIVECHAT_VISIBILITY_LISTED => $this
          ->t('Only the listed pages'),
      ),
      '#default_value' => $config
        ->get('livechat_visibility'),
    ];
    $form['path']['livechat_pages'] = [
      '#type' => 'textarea',
      '#default_value' => $config
        ->get('livechat_pages'),
      '#description' => $this
        ->t("Specify pages by using their paths. Enter one path per\n      line. The '*' character is a wildcard. Example paths are %blog for the blog\n      page and %blog-wildcard for every personal blog. %front is the\n      front page.", [
        '%blog' => 'blog',
        '%blog-wildcard' => 'blog/*',
        '%front' => '<front>',
      ]),
    ];
    $form['path']['livechat_exclude_system_paths'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Disable LiveChat on common system paths (recommended)'),
      '#description' => $this
        ->t('LiveChat will not trigger on the following paths: %paths', [
        '%paths' => str_replace("\n", ', ', LIVECHAT_VISIBILITY_SYSTEM_PATHS),
      ]),
      '#default_value' => $config
        ->get('livechat_exclude_system_paths'),
    ];
    $form['livechat_group'] = [
      '#type' => 'textfield',
      '#title' => $this
        ->t('Group Id'),
      '#description' => $this
        ->t('If you are using LiveChat on more than one website,
       enter the id of the website here'),
      '#default_value' => $config
        ->get('livechat_group'),
    ];
    $form['livechat_enabled'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Enable LiveChat'),
      '#description' => $this
        ->t('Uncheck this box to disable LiveChat.'),
      '#default_value' => $config
        ->get('livechat_enabled'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state
      ->getValues();
    $this
      ->config(LIVECHAT_CONFIGURATION_NAME)
      ->set('livechat_visibility', $values['livechat_visibility'])
      ->set('livechat_pages', $values['livechat_pages'])
      ->set('livechat_exclude_system_paths', $values['livechat_exclude_system_paths'])
      ->set('livechat_group', $values['livechat_group'])
      ->set('livechat_enabled', $values['livechat_enabled'])
      ->save();
    parent::submitForm($form, $form_state);
  }

}

Classes

Namesort descending Description
LiveChatSettingsForm Configure Coffee for this site.