tawk_to.module in tawk.to Live Chat (Drupal 8) 8        
                          
                  
                        
  
  
  
  
File
  tawk_to/tawk_to.module
  
    View source  
  <?php
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\tawk_to\core\TawktoGenerator;
function tawk_to_help($route_name, RouteMatchInterface $route_match) {
  if ($route_name !== 'tawk_to.help') {
    return;
  }
  $links = [
    ':homepage' => 'https://tawk.to',
    ':dashboard' => 'https://dashboard.tawk.to',
    ':project_page' => 'https://www.drupal.org/sandbox/tawk/2205433',
    ':mail_link' => 'support@tawk.to',
  ];
  $output = '';
  $output .= '<h3>' . t('About tawk.to') . '</h3>';
  $output .= '<p>' . t('tawk.to Drupal module allows you to easily choose which one of your tawk.to widgets you
    want to use on your drupal page. To create account please visit <a href=":project">https://tawk.to</a>.<br />
    To answer chat go to <a href="dashboard">https://dashboard.tawk.to</a>.<br />
    * For a full description of the module, visit the project page:<br />
    <a href=":project_page">https://www.drupal.org/sandbox/tawk/2205433</a><br /><br />
    * To submit bug reports and feature suggestions, or to track changes please email support@tawk.to
    ', $links) . '</p>';
  return $output;
}
function tawk_to_page_bottom(array &$page_bottom) {
  
  $route = \Drupal::routeMatch()
    ->getRouteObject();
  $is_admin_route = \Drupal::service('router.admin_context')
    ->isAdminRoute($route);
  $has_node_operation_option = $route
    ->getOption('_node_operation_route');
  $is_admin = $is_admin_route || $has_node_operation_option;
  if (!$is_admin) {
    $generator = new TawktoGenerator();
    
    $vars = $generator
      ->getWidgetVars();
    extract($vars);
    if ($options && !is_null($options)) {
      global $base_url;
      
      $options = json_decode($options);
      
      $currentUrl = $base_url . $_SERVER["REQUEST_URI"];
      if (false == $options->always_display) {
        $showPages = json_decode($options->show_oncustom);
        $show = false;
        foreach ($showPages as $slug) {
          if (empty(trim($slug))) {
            continue;
          }
          
          if ($currentUrl == $slug) {
            $show = true;
            break;
          }
        }
        
        if ("taxonomy_term" == strtolower(\Drupal::request()->attributes
          ->get('view_id'))) {
          if (false != $options->show_oncategory) {
            $show = true;
          }
        }
        
        if (\Drupal::service('path.matcher')
          ->isFrontPage()) {
          if (false != $options->show_onfrontpage) {
            $show = true;
          }
        }
        
        if (!$show) {
          return;
        }
      }
      else {
        $hide_pages = json_decode($options->hide_oncustom);
        $show = true;
        
        $currentUrl = (string) $currentUrl;
        foreach ($hide_pages as $slug) {
          if (empty(trim($slug))) {
            continue;
          }
          $slug = (string) htmlspecialchars($slug);
          
          if ($currentUrl == $slug) {
            $show = false;
            break;
          }
        }
        if (!$show) {
          return;
        }
      }
    }
    $page_bottom['tawk_to'] = array(
      '#type' => 'inline_template',
      '#template' => $generator
        ->widget(),
    );
  }
}