Skip to content

Commit

Permalink
Merge pull request #652 from City-of-Helsinki/UHF-9274-telia-ace
Browse files Browse the repository at this point in the history
UHF-9274: Basic implementation of Telia ACE widget.
  • Loading branch information
juho-lehmonen authored Nov 29, 2023
2 parents 3b45ca7 + da0d96b commit 6b8c6d7
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
3 changes: 3 additions & 0 deletions assets/css/telia_ace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.region--attachments .humany-rendered {
visibility: visible;
}
8 changes: 8 additions & 0 deletions config/schema/helfi_platform_config.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ block.settings.chat_leijuke:
chat_title:
type: text
label: 'Chat title'

block.settings.telia_ace_widget:
type: block_settings
label: 'Block config translation for Telia ACE widget'
mapping:
chat_id:
type: text
label: 'Chat widget ID'
9 changes: 9 additions & 0 deletions helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,12 @@ user_consent_functions:
assets/js/user_consent_functions.js: {}
dependencies:
- core/drupal

telia_ace_widget:
version: 1.0.x
header: true
css:
theme:
assets/css/telia_ace.css: {}
dependencies:
- helfi_platform_config/user_consent_functions
2 changes: 2 additions & 0 deletions helfi_platform_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ function helfi_platform_config_config_ignore_settings_alter(array &$settings) {
'block.block.genesyschat',
'block.block.genesyschat_*',
'block.block.smarttichatbot',
'block.block.teliaacewidget*',
'block.block.hdbt_subtheme_teliaacewidget*',
];

foreach ($add_ignore as $config) {
Expand Down
89 changes: 89 additions & 0 deletions src/Plugin/Block/TeliaAceWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Drupal\helfi_platform_config\Plugin\Block;

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

/**
* Provides a Telia ACE chat widget block.
*
* @Block(
* id = "telia_ace_widget",
* admin_label = @Translation("Telia ACE Widget"),
* )
*/
class TeliaAceWidget extends BlockBase {

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

$form['script_url'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Script URL'),
'#description' => $this->t('URL to the chat JS library without the domain, for example: /wds/instances/J5XKjqJt/ACEWebSDK.min.js'),
'#default_value' => $config['script_url'] ?? '/wds/instances/J5XKjqJt/ACEWebSDK.min.js',
];

$form['chat_id'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Chat Widget ID'),
'#description' => $this->t('ID for the chat instance. Example format: //acewebsdk/example-chat-fin'),
'#default_value' => $config['chat_id'] ?? '//acewebsdk/',
];

return $form;
}

/**
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $formState) {
$this->configuration['script_url'] = $formState->getValue('script_url');
$this->configuration['chat_id'] = $formState->getValue('chat_id');
}

/**
* {@inheritdoc}
*/
public function build() {

$library = ['helfi_platform_config/telia_ace_widget'];

$build = [];

$config = $this->getConfiguration();
$base_url = 'https://wds.ace.teliacompany.com';
$script_url = $base_url . $config['script_url'];
$chat_id = $config['chat_id'];

$build['ibm_chat_app'] = [
'#title' => $this->t('Telia ACE Widget'),
'#markup' => '<a class="hidden" href="' . $chat_id . '"></a>',
'#attached' => [
'library' => $library,
'html_head' => [
[
[
'#tag' => 'script',
'#attributes' => [
'async' => TRUE,
'type' => 'text/javascript',
'src' => $script_url,
],
], 'telia_ace_script',
],
],
],
];

return $build;
}

}

0 comments on commit 6b8c6d7

Please sign in to comment.