Commit 10afa115 authored by Sahana  N's avatar Sahana N Committed by mark-casias
Browse files

Issue #3064011 by Sahana _N: Should be a setting or permissions to disable for logged in users

parent 72f1ec30
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -31,8 +31,16 @@ function livechat_page_attachments_alter(array &$page) {
  ];

  $page['#attached']['drupalSettings']['livechat'] = $js_settings;
  $variables['value'] = \Drupal::config('hidelivechat.settings')->get('hide_live_chat');
  $current_user = \Drupal::currentUser();
  $roles = $current_user->getRoles();
  if ($roles[0] == 'authenticated' &&  $variables['value'] == 1) {
    unset($page['#attached']['library']['livechat/livechat']);
  }
  else {
    $page['#attached']['library'][] = 'livechat/livechat';
  }
}

/**
 * Helper function to check whether LiveChat is active.
@@ -53,7 +61,10 @@ function _livechat_active($path) {
function livechat_theme($existing, $type, $theme, $path) {
  return [
    'livechat_settings' => [
      'variables' => [],
      'variables' => [
        'hide_live_chat_settings_form' => NULL,
      ],
      'render element' => 'form',
    ],
  ];
}
+3 −0
Original line number Diff line number Diff line
@@ -58,8 +58,11 @@ class LivechatController extends ControllerBase {

    $host = $this->request->getSchemeAndHttpHost();

    $form = \Drupal::formBuilder()->getForm('Drupal\livechat\Form\HideLiveChatSettingsForm');

    $render = [
      '#theme' => 'livechat_settings',
      '#hide_live_chat_settings_form' => $form,
    ];

    $render['#attached'] = [
+57 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\livechat\Form;

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

/**
 * HideLiveChatSettingsForm.
 */
class HideLiveChatSettingsForm extends ConfigFormBase {

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

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $config = $this->config('hidelivechat.settings');
    $form['hide_live_chat'] = [
      '#type' => 'checkbox',
      '#title' => t('Hide Livechat window for logged in users '),
      '#default_value' => $config->get('hide_live_chat'),
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $values = $form_state->getValue('hide_live_chat');
    $value = $this->config('hidelivechat.settings')
      ->set('hide_live_chat', $values)
      ->save();
    parent::submitForm($form, $form_state);
  }

}
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@
          </select>
        </div>
      </div>

    {{ hide_live_chat_settings_form }}
      <p>Need help? Check out our <a href="https://www.livechatinc.com/kb/drupal-add-livechat-website/?utm_source=drupal.org&utm_medium=integration&utm_campaign=drupal8integration" target="_blank">LiveChat for Drupal 8 integration tutorial</a>.</p>
      <p class="reset-settings">Something went wrong? <a class="reset-settings" href="#" id="reset_settings">Click here</a> to reset settings!</p>
    </div>