Drupal 3CX Live Chat module

Laurent_FS

Free User
Joined
Jun 15, 2023
Messages
2
Reaction score
0
Hi all !
The module seems ti be "dead"...
Do you think thee will be an upgrade sonner or later ?
 
With a little help of ChatGPT (i'm not a dev) i have modified the code of the module. Seem promising on Drup. v10.3.10.
Some advice on that apreciated !
Code:
<?php

namespace Drupal\tcxlc\Plugin\Block;

use Drupal\Core\Block\BlockBase;
use Drupal\Core\Form\FormStateInterface;

/**
 * Provides a '3CX Live Chat' Block.
 *
 * @Block(
 *   id = "tcxlc_block",
 *   admin_label = @Translation("3CX Live Chat block"),
 *   category = @Translation("3CX "),
 * )
 */
class tcxlc_block extends BlockBase {

  /**
   * {@inheritdoc}
   */
  public function build() {
    $config = $this->getConfiguration();
    $snippet = isset($config['callus_snippet']) ? $config['callus_snippet'] : '';

    return [
      '#type' => 'inline_template',
      '#template' => '{{ var | raw }}',
      '#context' => [
        'var' => $snippet,
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function blockForm($form, FormStateInterface $form_state) {
    $form = parent::blockForm($form, $form_state);

    $config = $this->getConfiguration();
    $snippet = isset($config['callus_snippet']) ? $config['callus_snippet'] : '';

    $form['tcxlc_callus_header'] = [
      '#type' => 'inline_template',
      '#template' => $this->generateTemplate(),
      '#context' => [
        'var' => $snippet,
      ],
    ];

    $form['tcxlc_callus'] = [
      '#type' => 'textarea',
      '#rows' => 30,
      '#cols' => 250,
      '#attributes' => [
        'placeholder' => $this->t('Place your Live chat code snippet here'),
      ],
      '#default_value' => isset($config['callus_snippet']) ? $config['callus_snippet'] : '',
    ];

    return $form;
  }

  /**
   * Generate the HTML template for the block form header.
   */
  private function generateTemplate() {
    // Récupère le chemin absolu du fichier logo.png
    $logo_path = \Drupal::service('file_url_generator')
      ->generateAbsoluteString(\Drupal::service('extension.list.module')->getPath('tcxlc') . '/images/logo.png');

    $result = "
        <style>
            .tcxlc_script_field {
                width: 700px;
                margin-top: 15px;
            }
            .tcxlc_form {
                display: flex;
                flex-direction: column;
            }
            .tcxlc_header {
                height: 80px;
                display: flex;
                flex-direction: row;
            }
            .tcxlc_header img {
                height: 80px;
            }
            .tcxlc_label {
                text-align: center;
            }
        </style>
        <div class='tcxlc_form'>
            <div class='tcxlc_header'>
                <div>
                    <img src='" . $logo_path . "' />
                </div>
                <div>
                    <ol>
                        <li>Configure your <a href='https://www.3cx.com/docs/manual/live-chat/#h.vyesuv769zft' target='_blank'>PBX</a>.</li>
                        <li>Generate code snippet <a href='https://www.3cx.com/live-chat/code-generator/' target='_blank'>here</a>.</li>
                        <li>Paste the code and start using!</li>
                    </ol>
                </div>
            </div>
        </div>
    ";

    return $result;
  }

  /**
   * {@inheritdoc}
   */
  public function blockSubmit($form, FormStateInterface $form_state) {
    parent::blockSubmit($form, $form_state);
    $values = $form_state->getValues();
    $this->configuration['callus_snippet'] = $values['tcxlc_callus'];
  }

}
 

Forum statistics

Threads
112,147
Messages
590,959
Members
165,167
Latest member
Finatra.us